#' Translates DNA or RNA sequence to Amino Acids
#'
#' @param dna the sequence of DNA or RNA to be translated, must be divisible by 3
#' @examples
#' x <- "ATGCTGGGG"
#' Dna2AA(x)
#'
#'
#' @export
Dna2AA <- function(dna){
codon.table <- matrix(c("TTT", "TTC", "TTA", "TTG",
"CTT", "CTC", "CTA", "CTG",
"GTT", "GTC", "GTA", "GTG",
"ATT", "ATC", "ATA", "ATG",
"TCT", "TCC", "TCA", "TCG",
"CCT", "CCC", "CCA", "CCG",
"GCT", "GCC", "GCA", "GCG",
"ACT", "ACC", "ACA", "ACG",
"TAT", "TAC", "TAA", "TAG",
"CAT", "CAC", "CAA", "CAG",
"GAT", "GAC", "GAA", "GAG",
"AAT", "AAC", "AAA", "AAG",
"TGT", "TGC", "TGA", "TGG",
"CGT", "CGC", "CGA", "CGG",
"GGT", "GGC", "GGA", "GGG",
"AGT", "AGC", "AGA", "AGG",
"F", "F", "L", "L",
"L", "L", "L", "L",
"V", "V", "V", "V",
"I", "I", "I", "M",
"S", "S", "S", "S",
"P", "P", "P", "P",
"A", "A", "A", "A",
"T", "T", "T", "T",
"Y", "Y", "*", "*",
"H", "H", "Q", "Q",
"D", "D", "E", "E",
"N", "N", "K", "K",
"C", "C", "*", "W",
"R", "R", "R", "R",
"G", "G", "G", "G",
"S", "S", "R", "R"), 64, 2)
dna <- toupper(dna)
dna <- gsub("U","T", dna)
numcodons <- nchar(dna)/3
pos.codon <- seq(from=1, by=3, length.out = numcodons)
results <- c()
for (i in 1:numcodons){
cur.code <- substring(dna, pos.codon[i], pos.codon[i]+2)
results <- c(results, codon.table[codon.table[,1]==cur.code, 2])
}
return(results)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.