[BioPython] Sequence from Fasta

Peter biopython at maubp.freeserve.co.uk
Mon Jun 30 05:19:16 EDT 2008


Which version of Biopython do you have?  I'm guessing Biopython 1.44.
On older versions you would have to do explicitly turn the Seq into a
string.

Does this work:

from Bio import SeqIO
handle = open("ls_orchid.fasta")
for seq_record in SeqIO.parse(handle, "fasta") :
    print seq_record.id
    print seq_record.seq.tostring()
    print len(seq_record.seq)
handle.close()

Since Biopython 1.45, doing str(...) on a Seq object gives you the
sequence in full as a plain string.  When you do a print this happens
implicitly.

Peter

P.S. For the implementation, str(object) calls the object.__str__() method.


More information about the BioPython mailing list