[BioPython] SeqRecord to file format as string

Peter biopython at maubp.freeserve.co.uk
Thu Aug 7 10:11:22 UTC 2008


Following discussion both here and on the development mailing list,
the SeqRecord and the Alignment objects are getting methods to present
the object as a string in a requested file format (using Bio.SeqIO and
Bio.AlignIO internally).  This is enhancement Bug 2561,
http://bugzilla.open-bio.org/show_bug.cgi?id=2561

I've added a .format() method, which takes a format name used in
Bio.SeqIO or Bio.AlignIO.  The name of this method final until it is
part of an official Biopython release, so if there are any strong
views on this please voice them sooner rather than later.

For an example of how this works, if your have a SeqRecord object in
variable record, you could do:

print record.format("fasta")
print record.format("tab")

(or any other output format name supported in Bio.SeqIO for a single record)

Similarly, if you had an Alignment object in variable align, you could do:

print align.format("fasta")
print align.format("clustal")
print align.format("stockholm")

(or any other output format name supported in Bio.AlignIO)

This functionality will also be available via the special format()
function being added to Python 2.6 and 3.0, giving the alternative:

print format(align, "fasta")

See PEP 3101 for details about the format system,
http://www.python.org/dev/peps/pep-3101/

Peter



More information about the Biopython mailing list