R/dna2aa.r

Defines functions dna2aa

Documented in dna2aa

#' Translating a codon sequence to into animo-acids
#'
#' This function translate an array of codons into the corresponding amino acid sequence using the codon table of choice.
#'
#' @param x a KZsqns object of codons or a list of such objects
#' @param aaNoLetters a number to assign the format of animo acid. 1 = one-letter abbreviation, 3 = three-letter abbreviation. If it defaults into the 3-letter abbreviation when no number or a different number is specified
#' @param y a number to assign the type of codon table to be used for the translation. 0 = standard codon table, 2 = vertibrate mitchodrial, 3 = yeast mitochondrial, 4 = mold, protozoan, and Coelenterate mitochondrial and Mycoplasma/Spiroplasma, 5 = invertebrate mitochondrial, 6 = Ciliate, Dasycladacean and Hexamita nuclear, 9 = Echinoderm and flatworm mitochondrial, 10 = Euplotid nuclear, 11 = bacterial, Archaeal and plant plastid, 12 = alternative yeast nuclear, 13 = Ascidian mitochondrial, 14 = alternative flatworm mitochondrial, 16 = Chlorophycean mitochondrial, 21 = Trematode mitochondrial, 22 = Scenedesmus obliquus mitochondrial, 23 = Thraustochytrium mitochondrial, 24 = Pterobranchia mitochondrial, 25 = candidate division SR1 and Gracilibacteria, 26 = Pachysolen tannophilus nuclear, 29 = Mesodinium nuclear, 30 = Peritrich nuclear. If no number is specified or an option other than those provided above is specified, there will be a warning and the standard codon table will be used
#' @return a character array of animo-acids, or a list of such arrays when \emph{x} is a list
#' @details Codon tables were based on the list compiled by Andrzej Elzanowski and Jim Ostell [1] at NCBI, Bethesda, Maryland, USA. The numbering of codon tables respects the order in Elzanowski and Ostell [1] (except the standard code, which was numbered 0 in this package). There are three addditional codon tables listed in Elzanowski and Ostell [1] (27 Karyorelict nuclear, 28 Condylostoma nuclear and 31 Blastocrithidia nuclear), but were excluded in this package, because these codon tables include codons that can be either intepreted as a AA coding codon or stop codon, and the AA sequence can not be determined based on the DNA sequence alone.
#'The codon table data were available as "CodonTable#", where "#" denote the numeric order of the codon table. For example, "CodonTable21" is the Trematode mitochonrial code table.
#' @references [1] https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi#SG13 [retrieved on 2/4/2019]
#' @examples
#' data('CodonTable0')
#' sqs = sample(1:64, 100, replace=T)
#' codonSequence = CodonTable0[sqs,1] # an arbitrary sequence of codons is genereated based on the standard codon table
#' cat("The sequence of aa based on the standard codon table:\n")
#' cat(CodonTable0[sqs,2])
#' cat("The translated aa sequence:\n")
#' cat(dna2aa(codonSequence, 1, 0))
#'
#' @export

dna2aa <- function(x, aaNoLetters = 3, y = 0){
  if(is.list(x)){
    return(lapply(x, dna2aa_, aaNoLetters, y))
  } else {
    return(dna2aa_(x, aaNoLetters, y))
  }

}
HVoltBb/kondonz documentation built on Jan. 11, 2020, 3:30 a.m.