[Biopython-dev] SeqRecord to file format as string

Jared Flatow jflatow at northwestern.edu
Wed Jun 18 11:25:18 EDT 2008


Quick correction:

On Jun 18, 2008, at 10:16 AM, Jared Flatow wrote:

> Hi Peter,
>
> On Jun 18, 2008, at 9:00 AM, Peter wrote:
>
>> Jared - On reflection, do you think adding a method like this to the
>> SeqRecord (or even just for the FASTA format) would be useful?
>
> Yes I still think so. In fact, for sequences, I would say that I  
> pretty much never deal with a format ever than FASTA, so even making  
> the __str__ method of SeqRecord return the FASTA format as well  
> seems reasonable, though perhaps my use cases are different than  
> others.
>
> However, py3k and 2.6 will make available the functionality  
> described in PEP 3101:
>
> http://www.python.org/dev/peps/pep-3101/
>
> I think it would be best to define some semantics that are  
> compatible with this PEP. This would basically mean using the  
> __format__ method (which could be the same as the tostring method  
> you have defined below). To achieve backward compatibility and/or a  
> more OO interface, tostring could just be an alias for __format__.  
> Thus, instead of calling format(seq_rec, 'fasta') one could call  
> seq_rec.tostring('fasta') and these would be equivalent. The PEP  
> also states that format(seq_rec) should be the same as str(seq_rec).

On second thought it seems like a .format method (similar to the one  
the string class is acquiring) should be used as an alias to  
__format__ (somehow I think tostring should always be the same as  
__str__)

> In short, I think creating methods to return formatted versions of  
> objects (SeqRecords) is a good idea, but most especially if it is  
> done in a way consistent with the language's vision.
>
> Best,
> jared



More information about the Biopython-dev mailing list