#See my webpage:
#http://www.warwick.ac.uk/go/peter_cock/python/genbank2fasta/
from Bio import SeqIO

gbk_filename = "NC_005213.gbk"
faa_filename = "NC_005213_converted.fna"

input_handle  = open(gbk_filename, "r")
output_handle = open(faa_filename, "w")

#Short version:
#SeqIO.write(SeqIO.parse(input_handle, "genbank"), output_handle, "fasta")

#Long version, allows full control of fasta output
for seq_record in SeqIO.parse(input_handle, "genbank") :
    print "Dealing with GenBank record %s" % seq_record.id
    output_handle.write(">%s %s\n%s\n" % (
           seq_record.id,
           seq_record.description,
           seq_record.seq.tostring()))

output_handle.close()
input_handle.close()
print "Done"

