Back to index

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

List of all members.

Public Member Functions

def __init__
def __len__
def __getitem__
def move_start
def next
def __iter__

Public Attributes

 handle
 alphabet

Private Attributes

 _n

Detailed Description

Base class for any iterator of a non-sequential file type.

This object is not intended for use directly.

When writing a parser for any interlaced sequence file where the whole
file must be read in order to extract any single record, then you should
subclass this object.

All you need to do is to define your own:
(1) __init__ method to parse the file and call self.move_start()
(2) __len__ method to return the number of records
(3) __getitem__ to return any requested record.

This class will then provide the iterator methods including next(), but relies
on knowing the total number of records and tracking the pending record index in
as self._n

It is up to the subclassed object to decide if it wants to generate a cache of
SeqRecords when initialised, or simply use its own lists and dicts and create
SeqRecords on request.

Definition at line 64 of file Interfaces.py.


Constructor & Destructor Documentation

Create the object.

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

Definition at line 87 of file Interfaces.py.

00087 
00088     def __init__(self):
00089         """Create the object.
00090 
00091         This method should be replaced by any derived class to do something useful."""
00092         #We assume that your implementation of __init__ will ensure self._n=0
00093         self.move_start()
00094         raise NotImplementedError("This object method should be subclassed")
00095         #####################################################
00096         # You SHOULD subclass this                          #
00097         #####################################################

Here is the call graph for this function:


Member Function Documentation

Return the requested record.

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

It should NOT touch the value of self._n

Definition at line 107 of file Interfaces.py.

00107 
00108     def __getitem__(self, i):
00109         """Return the requested record.
00110 
00111         This method should be replaced by any derived class to do something
00112         useful.
00113 
00114         It should NOT touch the value of self._n"""
00115         raise NotImplementedError("This object method should be subclassed")
00116         #####################################################
00117         # You SHOULD subclass this                          #
00118         #####################################################

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 from Bio.SeqIO.Interfaces.SequenceIterator.

Definition at line 131 of file Interfaces.py.

00131 
00132     def __iter__(self):
00133         return iter(self.next, None)

Here is the call graph for this function:

Return the number of records.

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

Definition at line 98 of file Interfaces.py.

00098 
00099     def __len__(self):
00100         """Return the number of records.
00101 
00102         This method should be replaced by any derived class to do something useful."""
00103         raise NotImplementedError("This object method should be subclassed")
00104         #####################################################
00105         # You SHOULD subclass this                          #
00106         #####################################################

Definition at line 119 of file Interfaces.py.

00119 
00120     def move_start(self):
00121         self._n = 0

Here is the caller 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 from Bio.SeqIO.Interfaces.SequenceIterator.

Definition at line 122 of file Interfaces.py.

00122 
00123     def next(self):
00124         next_record = self._n
00125         if next_record < len(self):
00126             self._n = next_record+1
00127             return self[next_record]
00128         else:
00129             #StopIteration
00130             return None
    

Member Data Documentation

Definition at line 120 of file Interfaces.py.

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: