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

Class InterlacedSequenceIterator

source code

SequenceIterator --+
                   |
                  InterlacedSequenceIterator

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.

Instance Methods [hide private]
 
__init__(self)
Create the object.
source code
 
__len__(self)
Return the number of records.
source code
 
__getitem__(self, i)
Return the requested record.
source code
 
move_start(self) source code
 
next(self)
Return the next record in the file.
source code
 
__iter__(self)
Iterate over the entries as a SeqRecord objects.
source code
Method Details [hide private]

__init__(self)
(Constructor)

source code 

Create the object.

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

Overrides: SequenceIterator.__init__

__len__(self)
(Length operator)

source code 

Return the number of records.

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

__getitem__(self, i)
(Indexing operator)

source code 

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

next(self)

source code 

Return the next record in the file.

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

Overrides: SequenceIterator.next
(inherited documentation)

__iter__(self)

source code 
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()

Overrides: SequenceIterator.__iter__
(inherited documentation)