Permalink
Browse files

Fix consensus sequence addition in hmmer2-text

  • Loading branch information...
1 parent 1ed793b commit 2d86cd8e8b46d626b1a089da827f1592d28f293f @bow bow committed Dec 9, 2012
Showing with 18 additions and 8 deletions.
  1. +18 −8 Bio/SearchIO/HmmerIO/hmmer2_text.py
@@ -46,15 +46,16 @@ def __iter__(self):
qresult.version = self._meta.get('version')
yield qresult
- def read_next(self):
+ def read_next(self, rstrip=True):
"""Return the next non-empty line, trailing whitespace removed"""
if len(self.buf) > 0:
return self.buf.pop()
self.line = self.handle.readline()
while self.line and not self.line.strip():
self.line = self.handle.readline()
if self.line:
- self.line = self.line.rstrip()
+ if rstrip:
+ self.line = self.line.rstrip()
return self.line
def push_back(self, line):
@@ -248,6 +249,7 @@ def parse_hsp_alignments(self):
consensus = ''
otherseq = ''
structureseq = ''
+ pad = 0
while self.read_next() and self.line.startswith(' '):
# if there's structure information, parse that
if self.line[16:18] == 'CS':
@@ -258,22 +260,30 @@ def parse_hsp_alignments(self):
# skip the *-> start marker if it exists
if self.line[19] == '*':
- hmmseq += self.line[22:]
+ seq = self.line[22:]
+ pad = 3
else:
- hmmseq += self.line[19:]
+ seq = self.line[19:]
+ pad = 0
- if not self.read_next():
+ # get rid of the end marker
+ if seq.endswith('<-*'):
+ seq = seq[:-3]
+
+ hmmseq += seq
+ line_len = len(seq)
+ if not self.read_next(rstrip=False):
break
- consensus += self.line[19:].strip()
+ consensus += self.line[19+pad:19+pad+line_len]
if not self.read_next():
break
otherseq += self.line[19:].split()[0].strip()
self.push_back(self.line)
- # get rid of the end marker
- hmmseq = hmmseq[:-3]
+ # add homology sequence to annotation
+ frag.aln_annotation['homology'] = consensus
# if there's structure information, add it to the fragment
if structureseq:

0 comments on commit 2d86cd8

Please sign in to comment.