backTranslate: Replace amino acids with codons

View source: R/multialign.R

backTranslateR Documentation

Replace amino acids with codons


Replaces aligned amino acids with their original codon triplets.


backTranslate(aa.msa, nuc.ffn)



A fasta object with a multiple alignment, see msalign.


A fasta object with the coding sequences, see readFasta.


This function replaces the aligned amino acids in aa.msa with their original codon triplets. This is possible only when the nucleotide sequences in nuc.ffn are the exact nucleotide sequences behind the protein sequences that are aligned in aa.msa.

It is required that the first token of the ‘⁠Header⁠’ lines is identical for a protein sequence in aa.msa and its nucleotide version in ‘⁠nuc.ffn⁠’, otherwise it is impossible to match them. Thus, they may not appear in the same order in the two input fasta objects.

When aligning coding sequences, one should in general always align their protein sequences, to keep the codon structure, and then use backTranslate to convert this into a nucleotide alignment, if required.

If the nuclotide sequences contain the stop codons, these will be removed.


A fasta object similar to aa.msa, but where each amino acid has been replace by its corresponding codon. All gaps ‘⁠"-"⁠’ are replaced by triplets ‘⁠"---"⁠’.


Lars Snipen.

See Also

msalign, readFasta.


msa.file <- file.path(file.path(path.package("microseq"),"extdata"), "small.msa")
aa.msa <- readFasta(msa.file)
nuc.file <- file.path(file.path(path.package("microseq"),"extdata"), "small.ffn")
nuc <- readFasta(nuc.file)
nuc.msa <- backTranslate(aa.msa, nuc)

microseq documentation built on Aug. 21, 2023, 5:10 p.m.