Skip to content

Commit

Permalink
Raise StopIteration (not return None) in Bio.AlignIO (Bug 3147)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Oct 20, 2010
1 parent 0afc10d commit 208d926
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Bio/AlignIO/ClustalIO.py
Expand Up @@ -91,7 +91,7 @@ def next(self):
except AttributeError:
line = handle.readline()
if not line:
return None
raise StopIteration

#Whitelisted headers we know about
known_headers = ['CLUSTAL', 'PROBCONS', 'MUSCLE']
Expand Down Expand Up @@ -245,7 +245,7 @@ def next(self):

assert len(ids) == len(seqs)
if len(seqs) == 0 or len(seqs[0]) == 0:
return None
raise StopIteration

if self.records_per_alignment is not None \
and self.records_per_alignment != len(ids):
Expand Down
4 changes: 2 additions & 2 deletions Bio/AlignIO/EmbossIO.py
Expand Up @@ -76,12 +76,12 @@ def next(self):
except AttributeError:
line = handle.readline()
if not line:
return None
raise StopIteration

while line.rstrip() != "#=======================================":
line = handle.readline()
if not line:
return None
raise StopIteration

length_of_seqs = None
number_of_seqs = None
Expand Down
6 changes: 3 additions & 3 deletions Bio/AlignIO/FastaIO.py
Expand Up @@ -76,7 +76,7 @@ def next(self):
except AttributeError:
line = handle.readline()
if not line:
return None
raise StopIteration

if line.startswith("#"):
#Skip the file header before the alignments. e.g.
Expand All @@ -90,10 +90,10 @@ def next(self):
#Now should be some alignments, but if not we move onto the next query
if not line:
#End of file
return None
raise StopIteration
if ">>><<<" in line:
#Reached the end of the alignments, no need to read the footer...
return None
raise StopIteration


#Should start >>... and not >>>...
Expand Down
3 changes: 2 additions & 1 deletion Bio/AlignIO/PhylipIO.py
Expand Up @@ -145,7 +145,8 @@ def next(self):
except AttributeError:
line = handle.readline()

if not line: return
if not line:
raise StopIteration
line = line.strip()
parts = filter(None, line.split())
if len(parts)!=2:
Expand Down
4 changes: 2 additions & 2 deletions Bio/AlignIO/StockholmIO.py
Expand Up @@ -318,7 +318,7 @@ def next(self):
line = self.handle.readline()
if not line:
#Empty file - just give up.
return
raise StopIteration
if not line.strip() == '# STOCKHOLM 1.0':
raise ValueError("Did not find STOCKHOLM header")
#import sys
Expand Down Expand Up @@ -453,7 +453,7 @@ def next(self):

return alignment
else:
return None
raise StopIteration


def _identifier_split(self, identifier):
Expand Down
4 changes: 1 addition & 3 deletions Bio/AlignIO/__init__.py
Expand Up @@ -269,9 +269,7 @@ def _SeqIO_to_alignment_iterator(handle, format, alphabet=None, seq_count=None):
records = list(SeqIO.parse(handle, format, alphabet))
if records:
yield MultipleSeqAlignment(records, alphabet)
else:
#No alignment found!
pass
raise StopIteration

def _force_alphabet(alignment_iterator, alphabet):
"""Iterate over alignments, over-riding the alphabet (PRIVATE)."""
Expand Down
6 changes: 2 additions & 4 deletions Tests/test_AlignIO.py
Expand Up @@ -238,11 +238,9 @@ def simple_alignment_comparison(alignments, alignments2, format):
try:
record = seq_iterator.next()
except StopIteration:
record = None
if record:
alignments3.append(record)
else:
break
assert record is not None, "Should raise StopIteration not return None"
alignments3.append(record)

#Try a mixture of next() and list (a torture test!)
seq_iterator = AlignIO.parse(handle=open(t_filename,"r"), format=t_format)
Expand Down

0 comments on commit 208d926

Please sign in to comment.