[BioPython] a sequence set object in biopython?

Peter biopython at maubp.freeserve.co.uk
Thu Nov 13 11:11:10 UTC 2008


Michiel wrote:
>Marco wrote:
>> Take for example this code you [Peter] wrote for me before:
>>
>> > class SeqRecordList(list) :
>> >    def format(self, format) :
>> >        from Bio import SeqIO
>> >        from StringIO import StringIO
>> >        handle = StringIO()
>> >        SeqIO.write(self, handle, format)
>> >        handle.seek(0)
>> >        return handle.read()
>>
>> It's very useful, but I don't think a
>> python/biopython newbie would be
>> able to write it.
>
> I agree that this is too complicated.

This wasn't aimed at a beginner, but rather for Marco if he really
wants to use this kind of object in his own code, or as a basis for
further discussion.

> What if we redefine SeqIO.write as
>
> def write(self, handle=sys.stdout, format='fasta'):
> ...
>
> So by default SeqIO.write prints to the screen. Then you can do
>
> SeqIO.write(records)
>
> where records are a list of SeqRecord's.

We could certainly include something like this in the documentation:

#Just an example to create some records:
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
records = [SeqRecord(Seq("ACGT"),"Alpha"), SeqRecord(Seq("GTGC"),"Beta")]

#One way to "print" records to screen,
import sys
from Bio import SeqIO
SeqIO.write(records, sys.stdout, "fasta")

I'm not so keen on making the handle default to standard out, but this
is nicer than the suggestion you made some time ago that if the handle
were omitted a string be returned (no longer an option since Bug 2628
was committed).

Any other votes for the standard out default?

Peter



More information about the Biopython mailing list