[Biopython-dev] [RFC, PATCH] Bio.Iter

Yves Bastide Yves.Bastide at irisa.fr
Wed Sep 10 12:35:14 EDT 2003


Hi all,

here's a small wrapper for using Bio iterators the 'modern' way.
E. g., replacing:

from Bio.Blast import NCBIStandalone

blast_out = open('my_file_of_blast_output', 'r')
b_parser = NCBIStandalone.BlastParser()
b_iterator = NCBIStandalone.Iterator(blast_out, b_parser)

while 1:
     b_record = b_iterator.next()

     if b_record is None:
         break
     # ...


With:

from Bio.Blast import NCBIStandalone
from Bio.Iter import Iter

blast_out = file('my_file_of_blast_output', 'r')
b_parser = NCBIStandalone.BlastParser()
b_iterator = Iter(NCBIStandalone.Iterator(blast_out, b_parser))

for b_record in b_iter:
     # ...


Regards,

yves
-------------- next part --------------
Index: biopython/Bio/__init__.py
===================================================================
RCS file: /home/repository/biopython/biopython/Bio/__init__.py,v
retrieving revision 1.21
diff -u -p -r1.21 __init__.py
--- biopython/Bio/__init__.py	2003/02/20 04:35:37	1.21
+++ biopython/Bio/__init__.py	2003/09/10 16:25:44
@@ -18,6 +18,7 @@ __all__ = [
     "Gobase",
     "Index",
     "InterPro",
+    "Iter",
     "KEGG",
     "Kabat",
     "Medline",
--- /dev/null	2003-01-30 11:24:37.000000000 +0100
+++ biopython/Bio/Iter.py	2003-09-10 18:22:41.000000000 +0200
@@ -0,0 +1,12 @@
+# This code is part of the Biopython distribution and governed by its
+# license.  Please see the LICENSE file that should have been included
+# as part of this package.
+from __future__ import generators
+
+def Iter(bio_iter):
+    """Standard iterator wrapper for Bio iterators"""
+    while True:
+        ret = bio_iter.next()
+        if ret is None:
+            return
+        yield ret


More information about the Biopython-dev mailing list