R/reverse_complement.R

Defines functions reverse_complement

Documented in reverse_complement

#' reverse-complement some fragments
#'
#' randomly reverse-complement half of the sequences in a DNAStringSet
#' @param tObj DNAStringSet representing sequences.
#' @param seed optional seed to set before randomly selecting the sequences to 
#'   be reverse-complemented.
#' @export
#' @return DNAStringSet that is the same as \code{tObj}, but with about half
#'   the sequences reverse-complemented.
#' @examples
#'   library(Biostrings)
#'   data(srPhiX174)
#'   srPhiX174_halfrc = reverse_complement(srPhiX174, seed=174)

reverse_complement = function(tObj, seed=NULL){
    if(!is.null(seed)) set.seed(seed)
    strand = sample(c(0,1), length(tObj), replace=TRUE)
    tObj[strand==0] = reverseComplement(tObj[strand==0])
    return(tObj)
}

Try the polyester package in your browser

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

polyester documentation built on Nov. 8, 2020, 8:09 p.m.