[BioPython] Help for a presentation.

Sebastian Bassi sbassi at gmail.com
Wed Apr 15 13:35:55 UTC 2009


I am working in a laptop session for a local workshop where I plan to
show off some biopython features. The file would be available (CC-BY
3.0) after presentation in Crunchy compatible HTML (if you don't know
Crunchy, take a look, it is impressive!).
In the following drill, the task is to read a DNA sequence from a
genbank file, translate it to an aminoacid sequence and save it as a
Fasta file.
The code here does this, but I think it looks a little complex when I
want to show that biopython way to do it is easy. So I wonder if
someone knows how to modify this code to get the same result with less
steps.

from Bio import SeqIO
from Bio.Seq import translate
from Bio.SeqRecord import SeqRecord

handle = open('ampRdna.gb')
seq_record = SeqIO.read(handle, "genbank")
print "DNA Sequence:",seq_record.seq
# make translation (numbers here is where the CDS starts)
# I don't want to grab the translated sequence from genbank file
# , I want to show how to translate it.
protseq = translate(seq_record.seq[89:694])
# show translation
print "Protein Sequence:",protseq
# Make a SeqRecord
seqid = seq_record.id
seqdesc = seq_record.description
protrec = SeqRecord(protseq,id=seqid,description=seqdesc)
# save it to a fasta file.
outfile_h = open('ampRprot.fasta','w')
SeqIO.write([protrec],outfile_h,'fasta')
outfile_h.close()



More information about the Biopython mailing list