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!
• 7,816 views
•
link
1 answer
See the example(s) on translating FASTA files in the Biopython Tutorial, e.g. "Translating a FASTA file of CDS entries".
• 0 views
•
link
Log in to answer this question.
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:
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!!