FastaIterator(handle,
alphabet=SingleLetterAlphabet(),
title2ids=None)
| source code
|
Generator function to iterate over Fasta records (as SeqRecord objects).
handle - input file
alphabet - optional alphabet
title2ids - A function that, when given the title of the FASTA
file (without the beginning >), will return the id, name and
description (in that order) for the record as a tuple of strings.
If this is not given, then the entire title line will be used
as the description, and the first word as the id and name.
By default this will act like calling Bio.SeqIO.parse(handle, "fasta")
with no custom handling of the title lines:
>>> for record in FastaIterator(open("Fasta/dups.fasta")):
... print record.id
alpha
beta
gamma
alpha
delta
However, you can supply a title2ids function to alter this:
>>> def take_upper(title):
... return title.split(None,1)[0].upper(), "", title
>>> for record in FastaIterator(open("Fasta/dups.fasta"), title2ids=take_upper):
... print record.id
ALPHA
BETA
GAMMA
ALPHA
DELTA
|