R/TCGAprimaryTumors.R

Defines functions TCGAprimaryTumors

Documented in TCGAprimaryTumors

#' Select primary tumors from TCGA datasets
#'
#' Tumor selection is decided using the `sampleTypes` data. For 'LAML' datasets,
#' the primary tumor code used is "03" otherwise, "01" is used.
#'
#' @param multiassayexperiment A \linkS4class{MultiAssayExperiment} with TCGA
#'     data as obtained from \code{\link[curatedTCGAData]{curatedTCGAData}}
#'
#' @return A MultiAssayExperiment containing only primary tumor samples
#'
#' @examples
#'
#' example(getSubtypeMap)
#'
#' TCGAprimaryTumors(gbm)
#'
#' @export TCGAprimaryTumors
TCGAprimaryTumors <- function(multiassayexperiment) {
    if (!is(multiassayexperiment, "MultiAssayExperiment"))
        stop("Provide a 'MultiAssayExperiment' object as input")

    exptnames <- names(experiments(multiassayexperiment))
    dcodes <- vapply(strsplit(exptnames, "_"), `[[`, character(1L), 1L)

    primaries <- ifelse(dcodes == "LAML", "03", "01")
    primaries <- setNames(primaries, dcodes)

    logisub <- Map(function(barcodes, tumorcode) {
        TCGAsampleSelect(barcodes, tumorcode)
    }, colnames(multiassayexperiment), primaries)

    multiassayexperiment[, logisub, ]
}

Try the TCGAutils package in your browser

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

TCGAutils documentation built on April 17, 2021, 6:04 p.m.