Skip to content
This repository
Browse code

Fix consensus sequence addition in hmmer2-text

  • Loading branch information...
commit 2d86cd8e8b46d626b1a089da827f1592d28f293f 1 parent 1ed793b
Wibowo Arindrarto bow authored

Showing 1 changed file with 18 additions and 8 deletions. Show diff stats Hide diff stats

  1. +18 8 Bio/SearchIO/HmmerIO/hmmer2_text.py
26 Bio/SearchIO/HmmerIO/hmmer2_text.py
@@ -46,7 +46,7 @@ def __iter__(self):
46 46 qresult.version = self._meta.get('version')
47 47 yield qresult
48 48
49   - def read_next(self):
  49 + def read_next(self, rstrip=True):
50 50 """Return the next non-empty line, trailing whitespace removed"""
51 51 if len(self.buf) > 0:
52 52 return self.buf.pop()
@@ -54,7 +54,8 @@ def read_next(self):
54 54 while self.line and not self.line.strip():
55 55 self.line = self.handle.readline()
56 56 if self.line:
57   - self.line = self.line.rstrip()
  57 + if rstrip:
  58 + self.line = self.line.rstrip()
58 59 return self.line
59 60
60 61 def push_back(self, line):
@@ -248,6 +249,7 @@ def parse_hsp_alignments(self):
248 249 consensus = ''
249 250 otherseq = ''
250 251 structureseq = ''
  252 + pad = 0
251 253 while self.read_next() and self.line.startswith(' '):
252 254 # if there's structure information, parse that
253 255 if self.line[16:18] == 'CS':
@@ -258,13 +260,21 @@ def parse_hsp_alignments(self):
258 260
259 261 # skip the *-> start marker if it exists
260 262 if self.line[19] == '*':
261   - hmmseq += self.line[22:]
  263 + seq = self.line[22:]
  264 + pad = 3
262 265 else:
263   - hmmseq += self.line[19:]
  266 + seq = self.line[19:]
  267 + pad = 0
264 268
265   - if not self.read_next():
  269 + # get rid of the end marker
  270 + if seq.endswith('<-*'):
  271 + seq = seq[:-3]
  272 +
  273 + hmmseq += seq
  274 + line_len = len(seq)
  275 + if not self.read_next(rstrip=False):
266 276 break
267   - consensus += self.line[19:].strip()
  277 + consensus += self.line[19+pad:19+pad+line_len]
268 278
269 279 if not self.read_next():
270 280 break
@@ -272,8 +282,8 @@ def parse_hsp_alignments(self):
272 282
273 283 self.push_back(self.line)
274 284
275   - # get rid of the end marker
276   - hmmseq = hmmseq[:-3]
  285 + # add homology sequence to annotation
  286 + frag.aln_annotation['homology'] = consensus
277 287
278 288 # if there's structure information, add it to the fragment
279 289 if structureseq:

0 comments on commit 2d86cd8

Please sign in to comment.
Something went wrong with that request. Please try again.