#' Nucleotide Sequence Translation
#' Translate nucleic acid sequence to corresponding peptide sequences.
#'
#' @docType methods
#' @name NucleoTranslate
#' @rdname NucleoTranslate
#'
#' @param sequence A character, specifying the nucleic acid sequence.
#'
#' @return A character of peptide sequences, in which 'X' means stop codon.
#'
#' @examples
#' sequence = "AATGAGGTTGGTGCGGAGTTTCATCCTACTATGTTG"
#' NucleoTranslate(sequence)
#' @author Wubing Zhang
#' @export
NucleoTranslate <- function(sequence){
# Read DNA codon table
CodonPath = file.path(system.file("extdata", package = "PhageR"),
"DNACodonTable.gz")
CodonFile = gzfile(CodonPath)
CodonTable = read.table(CodonFile, sep = "\t", header = TRUE,
row.names = 1, stringsAsFactors = FALSE)
# Separate DNA codons from sequence and translate
sequence = gsub("(.{3})", "\\1 ", sequence)
codons <- unlist(strsplit(sequence, " "))
Peptide = matrix(CodonTable[codons, "SLC"], nrow = length(sequence), byrow = TRUE)
Peptide[Peptide=="Stop"] = "X"
Peptide = do.call(paste0, as.data.frame(Peptide))
return(Peptide)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.