R/removeSeq.R

Defines functions removeSeq

Documented in removeSeq

#' Remove sequence
#' 
#' Removes an amino acid sequence and associated data from all instances within 
#' a list of data frames and then recomputes the frequencyCount.
#' 
#' @param file.list A list of data frames imported using the LymphoSeq function 
#' readImmunoSeq.  "aminoAcid", "count", and "frequencyCount" are required columns.
#' @param sequence A character vector of one or more amino acid sequences to 
#' remove from the list of data frames.
#' @return Returns a list of data frames like the one imported except all rows 
#' with the specified amino acid sequence are removed.  The frequencyCount is 
#' recalculated.
#' @examples
#' file.path <- system.file("extdata", "TCRB_sequencing", package = "LymphoSeq")
#' 
#' file.list <- readImmunoSeq(path = file.path)
#' 
#' searchSeq(list = file.list, sequence = "CASSDLIGNGKLFF")
#' 
#' cleansed <- removeSeq(file.list = file.list, sequence = "CASSDLIGNGKLFF")
#' 
#' searchSeq(list = cleansed, sequence = "CASSDLIGNGKLFF")
#' @export
#' @importFrom plyr llply
removeSeq <- function(file.list, sequence) {
    cleansed <- plyr::llply(file.list, function(x) 
        x[which(!(x[, "aminoAcid"] %in% sequence)), ])
    recompute <- list()
    i <- 1
    for (i in 1:length(cleansed)) {
        file <- cleansed[[i]]
        file$frequencyCount <- file$count/sum(file$count) * 100
        recompute <- c(recompute, list(file))
    }
    names(recompute) <- names(cleansed)
    return(recompute)
}

Try the LymphoSeq package in your browser

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

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