Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.SeqIO.Interfaces.SequenceIterator Class Reference
Inheritance diagram for Bio.SeqIO.Interfaces.SequenceIterator:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def next
def __iter__

Public Attributes

 handle
 alphabet

Detailed Description

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.

Definition at line 14 of file Interfaces.py.


Constructor & Destructor Documentation

def Bio.SeqIO.Interfaces.SequenceIterator.__init__ (   self,
  handle,
  alphabet = generic_alphabet 
)
Create a SequenceIterator object.

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

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.

Definition at line 21 of file Interfaces.py.

00021 
00022     def __init__(self, handle, alphabet=generic_alphabet):
00023         """Create a SequenceIterator object.
00024 
00025         handle - input file
00026         alphabet - optional, e.g. Bio.Alphabet.generic_protein
00027 
00028         Note when subclassing:
00029         - there should be a single non-optional argument,
00030           the handle.
00031         - you do not have to require an alphabet.
00032         - you can add additional optional arguments."""
00033         self.handle = handle
00034         self.alphabet = alphabet
00035         #####################################################
00036         # You may want to subclass this, for example        #
00037         # to read through the file to find the first record,#
00038         # or if additional arguments are required.          #
00039         #####################################################


Member Function Documentation

Iterate over the entries as a SeqRecord objects.

Example usage for Fasta files:

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

Reimplemented in Bio.SeqIO.Interfaces.InterlacedSequenceIterator.

Definition at line 51 of file Interfaces.py.

00051 
00052     def __iter__(self):
00053         """Iterate over the entries as a SeqRecord objects.
00054 
00055         Example usage for Fasta files:
00056 
00057         myFile = open("example.fasta","r")
00058         myFastaReader = FastaIterator(myFile)
00059         for record in myFastaReader:
00060             print record.id
00061             print record.seq
00062         myFile.close()"""
00063         return iter(self.next, None)

Here is the call graph for this function:

Return the next record in the file.

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

Reimplemented in Bio.SeqIO.Interfaces.InterlacedSequenceIterator.

Definition at line 40 of file Interfaces.py.

00040 
00041     def next(self):
00042         """Return the next record in the file.
00043 
00044         This method should be replaced by any derived class to do something useful."""
00045         raise NotImplementedError("This object should be subclassed")
00046         #####################################################
00047         # You SHOULD subclass this, to split the file up    #
00048         # into your individual records, and convert these   #
00049         # into useful objects, e.g. return SeqRecord object #
00050         #####################################################


Member Data Documentation

Definition at line 33 of file Interfaces.py.

Definition at line 32 of file Interfaces.py.


The documentation for this class was generated from the following file: