Bio.SeqIO.Interfaces module
Bio.SeqIO support module (not for general use).
Unless you are writing a new parser or writer for Bio.SeqIO, you should not use this module. It provides base classes to try and simplify things.
- class Bio.SeqIO.Interfaces.SequenceIterator(source, alphabet=None, mode='t', fmt=None)
Bases:
abc.ABC
Base class for building SeqRecord iterators.
You should write a parse method that returns a SeqRecord generator. You may wish to redefine the __init__ method as well.
- __init__(source, alphabet=None, mode='t', fmt=None)
Create a SequenceIterator object.
Arguments: - source - input file stream, or path to input file - alphabet - no longer used, should be None
This method MAY be overridden by any subclass.
Note when subclassing: - there should be a single non-optional argument, the source. - you do not have to require an alphabet. - you can add additional optional arguments.
- __next__()
Return the next entry.
- __iter__()
Iterate over the entries as a SeqRecord objects.
Example usage for Fasta files:
with open("example.fasta","r") as myFile: myFastaReader = FastaIterator(myFile) for record in myFastaReader: print(record.id) print(record.seq)
This method SHOULD NOT be overridden by any subclass. It should be left as is, which will call the subclass implementation of __next__ to actually parse the file.
- abstract parse(handle)
Start parsing the file, and return a SeqRecord iterator.
- __abstractmethods__ = frozenset({'parse'})
- class Bio.SeqIO.Interfaces.SequenceWriter(target, mode='w')
Bases:
object
Base class for sequence writers. This class should be subclassed.
It is intended for sequential file formats with an (optional) header, repeated records, and an (optional) footer, as well as for interlaced file formats such as Clustal.
The user may call the write_file() method to write a complete file containing the sequences.
Alternatively, users may call the write_header(), followed by multiple calls to write_record() and/or write_records(), followed finally by write_footer().
Note that write_header() cannot require any assumptions about the number of records.
- __init__(target, mode='w')
Create the writer object.
- clean(text)
Use this to avoid getting newlines in the output.
- write_header()
Write the file header to the output file.
Write the file footer to the output file.
- write_record(record)
Write a single record to the output file.
record - a SeqRecord object
- write_records(records, maxcount=None)
Write records to the output file, and return the number of records.
records - A list or iterator returning SeqRecord objects maxcount - The maximum number of records allowed by the file format, or None if there is no maximum.
- write_file(records, mincount=0, maxcount=None)
Write a complete file with the records, and return the number of records.
records - A list or iterator returning SeqRecord objects