[Biopython-dev] SeqRecord to file format as string
Peter
biopython-dev at maubp.freeserve.co.uk
Tue Oct 16 16:49:18 UTC 2007
>> 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
More information about the Biopython-dev
mailing list