[Biopython-dev] SeqRecord to file format as string

Michiel De Hoon mdehoon at c2b2.columbia.edu
Wed Oct 17 02:45:34 UTC 2007


How about the following:

SeqIO.write(sequences, handle, format) returns the properly formatted string
if handle==None.

--Michiel.


Michiel de Hoon
Center for Computational Biology and Bioinformatics
Columbia University
1150 St Nicholas Avenue
New York, NY 10032



-----Original Message-----
From: biopython-dev-bounces at lists.open-bio.org on behalf of Peter
Sent: Tue 10/16/2007 12:49 PM
To: Jared Flatow
Cc: biopython-dev at lists.open-bio.org
Subject: Re: [Biopython-dev] SeqRecord to file format as string
 

 >> Did you know you can write to a string using any Bio.SeqIO supported
 >> file format using StringIO?  Perhaps we should spell this out more
 >> explicitly in the documentation, but a motivating example would help.
 >
 > This is what I do now, but it seems like a hack to me to go this
 > route. To always have to write to a file feels strange, but I see
 > that it would be messy to go OO since there are so many formats.
 > However, giving preference to fasta over other formats by making it
 > innate doesn't seem like such a terrible idea. I do have mixed
 > feelings about 'bloating' the code which is why I asked, and you have
 > convinced me that this is not quite appropriate given existing
 > convention. However the idea would be to put the to_fasta or
 > to_format method inside the SeqRecord, then to call it from the IO
 > when needed to actually write to a file, but call it directly when
 > all that is wanted is a string...

Its debatable isn't it?  I suspect that for most users, when they want a 
record in a particular file format its for writing to a file.  However, 
adding a to_format() method to a SeqRecord some sense (suitable for 
sequential file formats only).  This would take a format name and return 
a string, by calling Bio.SeqIO with a StringIO object internally.

Peter

_______________________________________________
Biopython-dev mailing list
Biopython-dev at lists.open-bio.org
http://lists.open-bio.org/mailman/listinfo/biopython-dev





More information about the Biopython-dev mailing list