Class InterlacedSequenceIterator
source code
SequenceIterator --+
|
InterlacedSequenceIterator
- Known Subclasses:
-
This class should be subclassed by any iterator for 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.
|
|
|
|
|
|
|
|
|
|
|
next(self)
Return the next record in the file This method should be replaced by
any derived class to do something useful. |
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
|
Create the object
This method should be replaced by any derived class to do something
useful.
- Overrides:
SequenceIterator.__init__
|
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)
|
Return the number of record
This method should be replaced by any derived class to do something
useful.
|
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)
|