Package Bio :: Package SeqIO :: Module Interfaces :: Class SequenceIterator
[hide private]
[frames] | no frames]

Class SequenceIterator

source code

object --+
         |
        SequenceIterator

Base class for building SeqRecord iterators.

You should write a __next__ method to return SeqRecord objects. You may wish to redefine the __init__ method as well.

Instance Methods [hide private]
 
__init__(self, handle, alphabet=Alphabet())
Create a SequenceIterator object.
source code
 
__next__(self)
Return the next record in the file.
source code
 
next(self)
Python 2 style alias for Python 3 style __next__ method.
source code
 
__iter__(self)
Iterate over the entries as a SeqRecord objects.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, handle, alphabet=Alphabet())
(Constructor)

source code 

Create a SequenceIterator object.

Arguments: - handle - input file - alphabet - optional, e.g. Bio.Alphabet.generic_protein

This method MAY be overridden by any subclass, for example if you need to process a header or accept additional arguments.

Note when subclassing: - there should be a single non-optional argument, the handle. - you do not have to require an alphabet. - you can add additional optional arguments.

Overrides: object.__init__

__next__(self)

source code 

Return the next record in the file.

This method's stub-implementation MUST be overridden by any subclass to actually parse the file and return the next entry as a SeqRecord object.

__iter__(self)

source code 

Iterate over the entries as a SeqRecord objects.

Example usage for Fasta files:

with open("example.fasta","r") as myFile:
    myFastaReader = FastaIterator(myFile)
    for record in myFastaReader:
        print(record.id)
        print(record.seq)

This method SHOULD NOT be overridden by any subclass. It should be left as is, which will call the subclass implementation of __next__ to actually parse the file.