[Biopython] need help ,parse fasta format

Peter biopython at maubp.freeserve.co.uk
Wed May 5 05:55:30 EDT 2010


On Wed, May 5, 2010 at 9:50 AM, ning luwen <bioinformaticsing at gmail.com> wrote:
> Hi,
>
> the code like bellow:
>   x=SeqRecord(Seq(temp),id=rec.id,description=rec.description)
>   y=x.format('fasta')
>   print type(y)
>   z=SeqIO.parse(y,'fasta')
>
> I generator a fasta sequence y, but y is  str type,  then can not be
> parse by SeqIO.
>
> Is there anyway not save y into a file, then parse it by open the saved file?

Yes, using the Python StringIO or cStringIO module to turn the string
into a handle.
http://docs.python.org/library/stringio.html

e.g.:

from Bio import SeqIO
from StringIO import StringIO
handle = StringIO(">Example\nACGT\n")
record = SeqIO.read(handle, "fasta")

Peter



More information about the Biopython mailing list