How To Change The Alphabet Of Seqrecords In A Fasta File With Biopython?
1
1
Entering edit mode
13.2 years ago
Laura ▴ 40

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 • 7.2k views
ADD COMMENT
0
Entering edit mode

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)

ADD REPLY
0
Entering edit mode

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'

ADD REPLY
0
Entering edit mode

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()'.

ADD REPLY
0
Entering edit mode

That worked, thank you!!

ADD REPLY
3
Entering edit mode
13.2 years ago
Peter 6.0k

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

ADD COMMENT

Login before adding your answer.

Traffic: 1796 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6