[BioPython] Bio.SeqIO and files with one record

Peter biopython at maubp.freeserve.co.uk
Wed Jul 11 09:32:13 UTC 2007


Jan Kosinski wrote:
> Hi,
> 
> Do I understand correctly that the function is to return a record 
> instead of a parser? If yes I think it could be useful. parse_single 
> sounds good.

Yes, sorry if I wasn't clear.

Bio.SeqIO.parse(handle, format) would still return an iterator giving 
SeqRecord objects.

The suggested function (possibly called) Bio.SeqIO.parse_single(handle, 
format) would return a single SeqRecord object if the file contains one 
and only one record. It would raise exceptions for no records, or more 
than one record.

e.g.

from Bio import SeqIO
handle = open('example.gbk')
record = Bio.SeqIO.parse_single(handle, genbank')

or,

from Bio import SeqIO
record = Bio.SeqIO.parse_single(open('example.faa'), 'fasta')

As I said, I sometimes find myself wanting to do this - for example 
single query BLAST files in fasta format, or bacterial genomes in 
GenBank format.

The question is, is this worth adding to the interface or is this a 
relatively rare need?

Peter




More information about the Biopython mailing list