R/complement.R

Defines functions complement

Documented in complement

#' complement and reverse complement base of nucleotide sequences
#' 
#' get reverse complement and complement base of nucleotide sequences
#' 
#' @param ntseq Sequence (5' to 3') of one strand of the nucleic acid duplex
#'   as string or vector of characters
#' 
#' @param reverse Logical value, TRUE is reverse complement sequence, FALSE is not.
#' 
#' @references 
#' 
#' \code{citation("TmCalculator")}
#' 
#' @author Junhui Li
#' 
#' @examples
#' 
#' complement("ATCGYCGYsWwsaVv")
#' complement("ATCGYCGYsWwsaVv",reverse=TRUE)
#' 
#' @export complement

complement <- function(ntseq,reverse=FALSE){
  complement_table <- matrix(c('A','T','B','V','C','G','D','H','G','C','H','D','M','K','N','N','R','Y','S',
                               'S','T','A','U','A','V','B','W','W','X','X','Y','R','a','t','b','v','c','g',
                               'd','h','g','c','h','d','m','k','n','n','r','y','s','s','t','a','u','a','v',
                               'b','w','w','x','x','y','r'),ncol = 2, byrow = TRUE)
  new_seq <- NULL
  lineseq <- s2c(ntseq)
  for (i in lineseq){
    if(i %in% complement_table){
      n <- which(complement_table[,1] %in% i)
      new_seq <- append(new_seq,complement_table[n,2])
    }
  }
  if(reverse==TRUE){
    new_seq <- rev(new_seq)
  }
  rc_seq <- c2s(new_seq)
  return(rc_seq)
}

Try the TmCalculator package in your browser

Any scripts or data that you put into this service are public.

TmCalculator documentation built on March 18, 2022, 6:10 p.m.