Package Bio :: Package AlignIO :: Module Interfaces :: Class AlignmentIterator
[hide private]
[frames] | no frames]

Class AlignmentIterator

source code

object --+
         |
        AlignmentIterator
Known Subclasses:

Base class for building MultipleSeqAlignment iterators.

You should write a next() method to return Aligment objects. You may wish to redefine the __init__ method as well.

Instance Methods [hide private]
 
__init__(self, handle, seq_count=None, alphabet=SingleLetterAlphabet())
Create an AlignmentIterator object.
source code
 
next(self)
Return the next alignment in the file.
source code
 
__iter__(self)
Iterate over the entries as MultipleSeqAlignment 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, seq_count=None, alphabet=SingleLetterAlphabet())
(Constructor)

source code 
Create an AlignmentIterator object.

handle   - input file
count    - optional, expected number of records per alignment
           Recommend for fasta file format.
alphabet - optional, e.g. Bio.Alphabet.generic_protein

Note when subclassing:
- there should be a single non-optional argument, the handle,
  and optional count and alphabet IN THAT ORDER.
- you do not have to require an alphabet (?).
- you can add additional optional arguments.

Overrides: object.__init__

next(self)

source code 

Return the next alignment in the file.

This method should be replaced by any derived class to do something useful.

__iter__(self)

source code 
Iterate over the entries as MultipleSeqAlignment objects.

Example usage for (concatenated) PHYLIP files:

myFile = open("many.phy","r")
for alignment in PhylipIterator(myFile):
    print "New alignment:"
    for record in alignment:
        print record.id
        print record.seq
myFile.close()