This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Change The Alphabet Of Seqrecords In A Fasta File With Biopython?

Hi, I am new to python. I am trying to translate some dna sequences (from a multifasta file) with the biopython .translate() method. However, it seems that by default the alphabet of the fasta sequences is set to SingleLetterAlphabet, and this is a problem to do the translation. Is there a way to change the Alphabet feature of my fasta sequences to "unambiguous_dna" or similar? Thanks for any help!

biopython fasta

Can you show us the code you have so far? If you're using SeqIO to read in the file, then you want SeqIO.parse("file.fa", "fasta", alphabet=IUPAC.unambiguous_dna)

Thanks for your reply, Brad. When I try it I get the following error:

for seq in SeqIO.parse('orfs.fasta', 'fasta', alphabet=IUPAC.unambiguous_dna): ... seq.translate() ... Traceback (most recent call last): File "<stdin>", line 2, in <module> AttributeError: 'SeqRecord' object has no attribute 'translate'

The SeqIO parser gives you back SeqRecords (sequences plus name and annotations). translate is a method on Seq objects, so you want to do: 'for rec in SeqIO.parse' and then 'rec.seq.translate()'.

That worked, thank you!!

1 answer

See the example(s) on translating FASTA files in the Biopython Tutorial, e.g. "Translating a FASTA file of CDS entries".

http://biopython.org/DIST/docs/tutorial/Tutorial.html

http://biopython.org/DIST/docs/tutorial/Tutorial.pdf

Log in to answer this question.