Question: Translating Nucleotide MSA to Amino Acid MSA
gravatar for weslfield
5.2 years ago by
European Union
weslfield90 wrote:

Hi, so I have a nucleotide mutliple sequence alignment that I would like to translate into an amino acid MSA based on the reading frame of a reference sequence in that alignment. Looking for the best way to do this, preferably a Biopython way. Thanks!

msa sequence alignment • 1.9k views
ADD COMMENTlink modified 5.0 years ago by Whetting1.5k • written 5.2 years ago by weslfield90
gravatar for Whetting
5.0 years ago by
Bethesda, MD
Whetting1.5k wrote:

not sure you are still interested but...this solution assumes that the nucleotide alignment is a codon alignment. If not, you will end up with a bunch of "X" as aminoacid

from Bio import SeqIO

with open("translated.fas","w") as out:
    for record in SeqIO.parse("alignment.phy","phylip"):  ##change this to whichever format
        for c in range(0,len(record.seq),3): change to 0, 1, 2 depending on the frame of the reference
            codon = record.seq[c:c+3]
            if "-" not in str(codon):
                sequence.append( str(codon.translate()) )
            elif str(codon)=="---":
                sequence.append( "-" )
                sequence.append( "X" )
        print >>out, ">"
        print >>out, "".join(sequence)




ADD COMMENTlink modified 5.0 years ago • written 5.0 years ago by Whetting1.5k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2208 users visited in the last hour