[Biopython-dev] [Bug 2561] SeqRecord format method to get a string in a given file format

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Fri Aug 1 14:49:00 UTC 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2561





------- Comment #7 from biopython-bugzilla at maubp.freeserve.co.uk  2008-08-01 10:48 EST -------
Created an attachment (id=981)
 --> (http://bugzilla.open-bio.org/attachment.cgi?id=981&action=view)
Patch to Bio/SeqRecord.py and Bio/Align/Generic.py

This is a little different from the above suggestion:

(a) I am calling the method .to_format() rather than .tostring().

I think this makes it clearer that it is intended to give some kind file
format, rather than being a variation on the str(...) functionality.  Also,
this name seems to match the planned Python 2.6/3.0 feature fairly well.

We've already labeled the Seq/MutableSeq .tostring() method as "old" and
suggest using str(my_seq) in the documentation instead.  To introducing a new
methods for other objects called .tostring() could be seen as a step backwards.

(b) There is no default format.

While for the SeqRecord, using the raw sequence as a string makes a good file
format neutral choice for the sequence there is no obvious choice for the
Alignment object.  Defaulting to FASTA format in both cases might make sense.

On the other hand, the new format() functionality in python will default to
using the str() behaviour in the absence of a format:

http://www.python.org/dev/peps/pep-3101/
> For all built-in types, an empty format specification will produce
> the equivalent of str(value).  It is recommended that objects
> defining their own format specifiers follow this convention as
> well.

One might argue therefore that if we want a default format, our .to_format()
method should default to calling __str__ if no format is given - but these are
just "pretty print" output for use at the command prompt.


I decided to go with the Zen-of-python rule #2 ("Explicit is better than
implicit" http://www.python.org/dev/peps/pep-0020/ ) as a good justification
for no default format.  Also note that Bio.SeqIO and Bio.AlignIO don't have a
default format.


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list