diff --git a/NAMESPACE b/NAMESPACE index 777fa855..1a99c305 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(agrestiCoullCI) +export(arrayCompartments) export(bootstrapCompartments) export(condenseRE) export(condenseSE) @@ -13,8 +14,6 @@ export(fisherZ) export(fixCompartments) export(flogit) export(getABSignal) -export(getATACABsignal) -export(getArrayABsignal) export(getAssayNames) export(getBinMatrix) export(getChrs) diff --git a/R/arrayCompartments.R b/R/arrayCompartments.R new file mode 100644 index 00000000..4bff477c --- /dev/null +++ b/R/arrayCompartments.R @@ -0,0 +1,97 @@ +#' @title Estimate A/B compartments from methylation array data +#' +#' @description +#' \code{arrayCompartments} returns estimated A/B compartments from methylation array data. +#' +#' @param obj Input SummarizedExperiment object +#' @param res Compartment resolution in bp +#' @param chr What chromosome to work on (leave as NULL to run on all chromosomes) +#' @param targets Samples/cells to shrink towards +#' @param preprocess Whether to preprocess the arrays prior to compartment inference +#' @param parallel Whether to run samples in parallel +#' @param cores How many cores to use when running samples in parallel +#' @param bootstrap Whether we should perform bootstrapping of inferred compartments +#' @param num.bootstraps How many bootstraps to run +#' @param boot.parallel Whether to run the bootstrapping in parallel +#' @param boot.cores How many cores to use for the bootstrapping +#' @param genome What genome to work on ("hg19", "hg38", "mm9", "mm10") +#' @param other Another arbitrary genome to compute compartments on +#' @param group Whether to treat this as a group set of samples +#' @param array.type What type of array is this ("hm450", "EPIC") +#' +#' @return A RaggedExperiment of inferred compartments +#' @import SummarizedExperiment +#' @import RaggedExperiment +#' @importFrom parallel mclapply +#' @importFrom GenomeInfoDb keepSeqlevels +#' @importFrom methods as +#' @export +#' +#' @examples +#' +#' if (requireNamespace("minfi", quietly = TRUE)) { +#' data("array_data_chr14", package = "compartmap") +#' array_compartments <- arrayCompartments( +#' array.data.chr14, +#' chr="chr14", +#' parallel=FALSE, +#' bootstrap=FALSE, +#' genome="hg19", +#' array.type="hm450" +#' ) +#' } +arrayCompartments <- function( + obj, + res = 1e6, + chr = NULL, + targets = NULL, + preprocess = TRUE, + parallel = TRUE, + cores = 2, + bootstrap = TRUE, + num.bootstraps = 1000, + boot.parallel = TRUE, + boot.cores = 2, + genome = c("hg19", "hg38", "mm9", "mm10"), + group = FALSE, + other = NULL, + array.type = c("hm450", "EPIC") +) { + verifySE(obj) + verifyCoords(obj) + verifyAssayNames(obj, assay = "array") + + # preprocess the arrays + if (preprocess) { + obj <- preprocessArrays( + obj = obj, + genome = genome, + other = other, + array.type = array.type + ) + } + + # critical check if imputation was _not_ done + # to send things back to beta land + is.beta <- min(assays(obj)$Beta, na.rm = TRUE) > 0 + if (!is.beta) { + # send things back to beta land + assays(obj)$Beta <- fexpit(assays(obj)$Beta) + } + + getCompartments( + obj = obj, + assay = "array", + res = res, + parallel = parallel, + chr = chr, + targets = targets, + cores = cores, + bootstrap = bootstrap, + num.bootstraps = num.bootstraps, + boot.parallel = boot.parallel, + boot.cores = boot.cores, + genome = genome, + group = group + ) +} diff --git a/R/getArrayABsignal.R b/R/getArrayABsignal.R deleted file mode 100644 index a3eb8670..00000000 --- a/R/getArrayABsignal.R +++ /dev/null @@ -1,298 +0,0 @@ -#' @title Estimate A/B compartments from methylation array data -#' -#' @description -#' \code{getArrayABsignal} returns estimated A/B compartments from methylation array data. -#' -#' @param obj Input SummarizedExperiment object -#' @param res Compartment resolution in bp -#' @param parallel Whether to run samples in parallel -#' @param chr What chromosome to work on (leave as NULL to run on all chromosomes) -#' @param targets Samples/cells to shrink towards -#' @param preprocess Whether to preprocess the arrays prior to compartment inference -#' @param cores How many cores to use when running samples in parallel -#' @param bootstrap Whether we should perform bootstrapping of inferred compartments -#' @param num.bootstraps How many bootstraps to run -#' @param genome What genome to work on ("hg19", "hg38", "mm9", "mm10") -#' @param other Another arbitrary genome to compute compartments on -#' @param array.type What type of array is this ("hm450", "EPIC") -#' @param group Whether to treat this as a group set of samples -#' @param boot.parallel Whether to run the bootstrapping in parallel -#' @param boot.cores How many cores to use for the bootstrapping -#' -#' @return A RaggedExperiment of inferred compartments -#' @import SummarizedExperiment -#' @import RaggedExperiment -#' @importFrom parallel mclapply -#' @importFrom GenomeInfoDb keepSeqlevels -#' @importFrom methods as -#' @export -#' -#' @examples -#' -#' if (requireNamespace("minfi", quietly = TRUE)) { -#' data("array_data_chr14", package = "compartmap") -#' array_compartments <- getArrayABsignal( -#' array.data.chr14, -#' parallel=FALSE, -#' chr="chr14", -#' bootstrap=FALSE, -#' genome="hg19", -#' array.type="hm450" -#' ) -#' } -getArrayABsignal <- function( - obj, - res = 1e6, - parallel = TRUE, - chr = NULL, - targets = NULL, - preprocess = TRUE, - cores = 2, - bootstrap = TRUE, - num.bootstraps = 1000, - genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - array.type = c("hm450", "EPIC"), - group = FALSE, - boot.parallel = TRUE, - boot.cores = 2 -) { - verifySE(obj) - verifyCoords(obj) - verifyAssayNames(obj, assay = "array") - - # preprocess the arrays - if (preprocess) { - obj <- preprocessArrays( - obj = obj, - genome = genome, - other = other, - array.type = array.type - ) - } - - # critical check if imputation was _not_ done - # to send things back to beta land - is.beta <- min(assays(obj)$Beta, na.rm = TRUE) > 0 - if (!is.beta) { - # send things back to beta land - assays(obj)$Beta <- fexpit(assays(obj)$Beta) - } - - # gather the chromosomes we are working on - if (is.null(chr)) { - message("Assuming we want to process all chromosomes.") - # get what chromosomes we want - chr <- getChrs(obj) - } - - # get the column names - if (is.null(colnames(obj))) stop("colnames needs to be sample names.") - columns <- colnames(obj) - names(columns) <- columns - - # precompute global means - prior.means <- getGlobalMeans(obj = obj, targets = targets, assay = "array") - - if (bootstrap) { - message("Pre-computing the bootstrap global means.") - bmeans <- precomputeBootstrapMeans( - obj = obj, - targets = targets, - num.bootstraps = num.bootstraps, - assay = "array", - parallel = parallel, - num.cores = cores - ) - } - - if (group) { - array.compartments.list <- mclapply(chr, function(c) { - .arrayCompartments( - obj, obj, - res = res, - chr = c, - targets = targets, - genome = genome, - bootstrap = bootstrap, - num.bootstraps = num.bootstraps, - prior.means = prior.means, - parallel = boot.parallel, - cores = boot.cores, - group = group, - bootstrap.means = bmeans - ) - }, mc.cores = cores) - array.compartments <- sort(unlist(as(array.compartments.list, "GRangesList"))) - return(array.compartments) - } - - array.compartments <- mclapply(columns, function(s) { - obj.sub <- obj[, s] - message("Working on ", s) - array.compartments.list <- lapply(chr, function(c) { - .arrayCompartments( - obj.sub, obj, - res = res, - chr = c, - targets = targets, - genome = genome, - bootstrap = bootstrap, - prior.means = prior.means, - num.bootstraps = num.bootstraps, - parallel = boot.parallel, - cores = boot.cores, - group = group, - bootstrap.means = bmeans - ) - }) - sort(unlist(as(array.compartments.list, "GRangesList"))) - }, mc.cores = ifelse(parallel, cores, 1), mc.preschedule = F) - - array.compartments <- as(array.compartments, "CompressedGRangesList") - RaggedExperiment(array.compartments, colData = colData(obj)) -} - -#' Preprocess arrays for compartment inference -#' -#' @name preprocessArrays -#' -#' @param obj Input SummarizedExperiment -#' @param genome What genome are we working on ("hg19", "hg38", "mm9", "mm10") -#' @param other Another arbitrary genome to compute compartments on -#' @param array.type What type of array is this ("hm450", "EPIC") -#' -#' @return A preprocessed SummarizedExperiment to compute compartments -#' @import SummarizedExperiment -#' -#' @examples -#' if (requireNamespace("minfiData", quietly = TRUE)) { -#' grSet <- minfi::preprocessNoob(minfiData::RGsetEx.sub) |> -#' minfi::ratioConvert() |> -#' minfi::mapToGenome() -#' preprocessArrays(grSet) -#' } -#' -#' @export -preprocessArrays <- function( - obj, - genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - array.type = c("hm450", "EPIC") -) { - if (!requireNamespace("minfi", quietly = TRUE)) { - stop("The minfi package must be installed for this functionality") - } - - # what genome do we have - genome <- match.arg(genome) - - # subset the array to open sea CpGs - obj.opensea <- filterOpenSea(obj, genome = genome, other = other) - verifyAssayNames(obj.opensea, assay = "array") - - # convert to M-values if beta values given - # this should be default but allows handling if given M-values in Beta slot - is.beta <- min(assays(obj)$Beta, na.rm = TRUE) > 0 - if (is.beta) { - message("Converting to squeezed M-values.") - assays(obj.opensea)$Beta <- flogit(assays(obj.opensea)$Beta) - } - - # impute missing values if possible - if (any(is.na(minfi::getBeta(obj.opensea)))) { - message("Imputing missing values.") - obj.opensea <- imputeKNN(obj.opensea, assay = "array") - } - - obj.opensea -} - - -# this is the main analysis function for computing compartments from arrays -.arrayCompartments <- function( - obj, - original.obj, - res = 1e6, - chr = NULL, - targets = NULL, - genome = c("hg19", "hg38", "mm9", "mm10"), - prior.means = NULL, - bootstrap = TRUE, - num.bootstraps = 1000, - parallel = FALSE, - cores = 2, - group = FALSE, - bootstrap.means = NULL -) { - genome <- match.arg(genome) - if (parallel) options(mc.cores = cores) - - # update - message("Computing compartments for ", chr) - obj <- keepSeqlevels(obj, chr, pruning.mode = "coarse") - original.obj <- keepSeqlevels(original.obj, chr, pruning.mode = "coarse") - - # take care of the global means - if (!is.null(prior.means)) { - # this assumes that we've alread computed the global means - pmeans <- as(prior.means, "GRanges") - pmeans <- keepSeqlevels(pmeans, chr, pruning.mode = "coarse") - # go back to a matrix - prior.means <- as(pmeans, "matrix") - colnames(prior.means) <- "globalMean" - } - - obj.bins <- shrinkBins( - obj, - original.obj, - prior.means = prior.means, - chr = chr, - res = res, - targets = targets, - assay = "array", - genome = genome, - jse = TRUE - ) - - obj.cor <- getCorMatrix(obj.bins, squeeze = !group) - - if (any(is.na(obj.cor$binmat.cor))) { - obj.cor$gr$pc <- matrix(rep(NA, nrow(obj.cor$binmat.cor))) - obj.svd <- obj.cor$gr - } else { - # compute SVD of correlation matrix - obj.svd <- getABSignal(obj.cor, assay = "array") - } - - if (!bootstrap) { - return(obj.svd) - } - - # bootstrap the estimates - # always compute confidence intervals too - # take care of the global means - # this assumes that we've alread computed the global means - bmeans <- as(bootstrap.means, "GRanges") - bmeans <- keepSeqlevels(bmeans, chr, pruning.mode = "coarse") - # go back to a matrix - bmeans <- as(bmeans, "matrix") - colnames(bmeans) <- rep("globalMean", ncol(bmeans)) - - bootstrapCompartments( - obj, - original.obj, - bootstrap.samples = num.bootstraps, - chr = chr, - assay = "array", - parallel = parallel, - cores = cores, - targets = targets, - res = res, - genome = genome, - q = 0.95, - svd = obj.svd, - group = group, - bootstrap.means = bmeans - ) -} diff --git a/R/getATACABsignal.R b/R/getCompartments.R similarity index 54% rename from R/getATACABsignal.R rename to R/getCompartments.R index ec6c19e1..ad8178d6 100644 --- a/R/getATACABsignal.R +++ b/R/getCompartments.R @@ -1,69 +1,28 @@ -#' @title Estimate A/B compartments from ATAC-seq data -#' -#' @description -#' \code{getATACABsignal} returns estimated A/B compartments from ATAC-seq data. -#' -#' @param obj Input SummarizedExperiment object -#' @param res Compartment resolution in bp -#' @param parallel Whether to run samples in parallel -#' @param chr What chromosome to work on (leave as NULL to run on all chromosomes) -#' @param targets Samples/cells to shrink towards -#' @param cores How many cores to use when running samples in parallel -#' @param bootstrap Whether we should perform bootstrapping of inferred compartments -#' @param num.bootstraps How many bootstraps to run -#' @param genome What genome to work on ("hg19", "hg38", "mm9", "mm10") -#' @param other Another arbitrary genome to compute compartments on -#' @param group Whether to treat this as a group set of samples -#' @param boot.parallel Whether to run the bootstrapping in parallel -#' @param boot.cores How many cores to use for the bootstrapping -#' -#' @return A RaggedExperiment of inferred compartments -#' @import SummarizedExperiment -#' @import RaggedExperiment -#' @importFrom parallel mclapply -#' @importFrom methods as -#' @export -#' -#' @aliases getRNAABsignal -#' -#' @examples -#' if (requireNamespace("csaw", quietly = TRUE)) { -#' data("k562_scatac_chr14", package = "compartmap") -#' atac_compartments <- getATACABsignal( -#' k562_scatac_chr14, -#' parallel = FALSE, -#' chr = "chr14", -#' bootstrap = FALSE, -#' genome = "hg19", -#' group = TRUE -#' ) -#' } -getATACABsignal <- function( +getCompartments <- function( obj, - res = 1e6, - parallel = FALSE, - chr = NULL, - targets = NULL, - cores = 2, - bootstrap = TRUE, - num.bootstraps = 100, - genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - group = FALSE, - boot.parallel = FALSE, - boot.cores = 2 + assay, + res, + parallel, + chr, + targets, + cores, + bootstrap, + num.bootstraps, + boot.parallel, + boot.cores, + genome, + group ) { - chr <- chr %||% - { - message("Processing all chromosomes") - getChrs(obj) - } + if (is.null(chr)) { + message("Assuming we want to process all chromosomes.") + chr <- getChrs(obj) + } if (is.null(colnames(obj))) stop("colnames needs to be sample names.") columns <- colnames(obj) names(columns) <- columns - prior.means <- getGlobalMeans(obj = obj, targets = targets, assay = "atac") + prior.means <- getGlobalMeans(obj = obj, targets = targets, assay = assay) if (bootstrap) { message("Pre-computing the bootstrap global means.") @@ -71,17 +30,18 @@ getATACABsignal <- function( obj = obj, targets = targets, num.bootstraps = num.bootstraps, - assay = "atac", + assay = assay, parallel = parallel, num.cores = cores ) } if (group) { - atac.compartments.list <- mclapply(chr, function(c) { - atacCompartments( + compartments.list <- mclapply(chr, function(c) { + .getCompartments( obj, obj, + assay = assay, res = res, chr = c, targets = targets, @@ -96,18 +56,19 @@ getATACABsignal <- function( ) }, mc.cores = ifelse(parallel, cores, 1)) - atac.compartments <- sort(unlist(as(atac.compartments.list, "GRangesList"))) - return(atac.compartments) + compartments <- sort(unlist(as(compartments.list, "GRangesList"))) + return(compartments) } - atac.compartments <- mclapply(columns, function(s) { + compartments <- mclapply(columns, function(s) { obj.sub <- obj[, s] message("Working on ", s) - atac.compartments.list <- lapply(chr, function(c) { - atacCompartments( + compartments.list <- lapply(chr, function(c) { + .getCompartments( obj.sub, obj, + assay = assay, res = res, chr = c, targets = targets, @@ -121,19 +82,18 @@ getATACABsignal <- function( bootstrap.means = bmeans ) }) + sort(unlist(as(compartments.list, "GRangesList"))) + }, mc.cores = ifelse(parallel, cores, 1), mc.preschedule = F) - sort(unlist(as(atac.compartments.list, "GRangesList"))) - }, mc.cores = ifelse(parallel, cores, 1)) - - atac.compartments <- as(atac.compartments, "CompressedGRangesList") - RaggedExperiment(atac.compartments, colData = colData(obj)) + compartments <- as(compartments, "CompressedGRangesList") + RaggedExperiment(compartments, colData = colData(obj)) } -# worker function -# this is the main analysis function for computing compartments from atacs -atacCompartments <- function( +# this is the main analysis function for computing compartments +.getCompartments <- function( obj, original.obj, + assay, res = 1e6, chr = NULL, targets = NULL, @@ -172,7 +132,7 @@ atacCompartments <- function( chr = chr, res = res, targets = targets, - assay = "atac", + assay = assay, genome = genome, jse = TRUE ) @@ -184,7 +144,7 @@ atacCompartments <- function( obj.svd <- obj.cor$gr } else { # compute SVD of correlation matrix - obj.svd <- getABSignal(obj.cor, assay = "atac") + obj.svd <- getABSignal(obj.cor, assay = assay) } if (!bootstrap) { @@ -206,7 +166,7 @@ atacCompartments <- function( original.obj, bootstrap.samples = num.bootstraps, chr = chr, - assay = "atac", + assay = assay, parallel = parallel, cores = cores, targets = targets, @@ -218,7 +178,3 @@ atacCompartments <- function( bootstrap.means = bmeans ) } - -#' @describeIn getATACABsignal Alias for getATACABsignal -#' -getRNAABsignal <- getATACABsignal diff --git a/R/plotAB.R b/R/plotAB.R index b8d1566d..8b4db5b6 100644 --- a/R/plotAB.R +++ b/R/plotAB.R @@ -2,7 +2,7 @@ #' #' Plot A/B compartments bins #' -#' @param grAB The GRanges object returned from scCompartments and getArrayABsignal +#' @param grAB The GRanges object returned from scCompartments and arrayCompartments #' @param chr Chromosome to subset to for plotting #' @param main Title for the plot #' @param ylim Y-axis limits (default is -1 to 1) diff --git a/R/preprocessArrays.R b/R/preprocessArrays.R new file mode 100644 index 00000000..4e24d220 --- /dev/null +++ b/R/preprocessArrays.R @@ -0,0 +1,54 @@ +#' Preprocess arrays for compartment inference +#' +#' @name preprocessArrays +#' +#' @param obj Input SummarizedExperiment +#' @param genome What genome are we working on ("hg19", "hg38", "mm9", "mm10") +#' @param other Another arbitrary genome to compute compartments on +#' @param array.type What type of array is this ("hm450", "EPIC") +#' +#' @return A preprocessed SummarizedExperiment to compute compartments +#' @import SummarizedExperiment +#' +#' @examples +#' if (requireNamespace("minfiData", quietly = TRUE)) { +#' grSet <- minfi::preprocessNoob(minfiData::RGsetEx.sub) |> +#' minfi::ratioConvert() |> +#' minfi::mapToGenome() +#' preprocessArrays(grSet) +#' } +#' +#' @export +preprocessArrays <- function( + obj, + genome = c("hg19", "hg38", "mm9", "mm10"), + other = NULL, + array.type = c("hm450", "EPIC") +) { + if (!requireNamespace("minfi", quietly = TRUE)) { + stop("The minfi package must be installed for this functionality") + } + + # what genome do we have + genome <- match.arg(genome) + + # subset the array to open sea CpGs + obj.opensea <- filterOpenSea(obj, genome = genome, other = other) + verifyAssayNames(obj.opensea, assay = "array") + + # convert to M-values if beta values given + # this should be default but allows handling if given M-values in Beta slot + is.beta <- min(assays(obj)$Beta, na.rm = TRUE) > 0 + if (is.beta) { + message("Converting to squeezed M-values.") + assays(obj.opensea)$Beta <- flogit(assays(obj.opensea)$Beta) + } + + # impute missing values if possible + if (any(is.na(minfi::getBeta(obj.opensea)))) { + message("Imputing missing values.") + obj.opensea <- imputeKNN(obj.opensea, assay = "array") + } + + obj.opensea +} diff --git a/R/scCompartments.R b/R/scCompartments.R index 050b24bb..251bb099 100644 --- a/R/scCompartments.R +++ b/R/scCompartments.R @@ -1,16 +1,18 @@ -#' @title Estimate A/B compartments from single-cell sequencing data +#' @title Estimate A/B compartments from single-cell RNA or ATAC sequencing data #' #' @description #' \code{scCompartments} returns estimated A/B compartments from sc-seq data. #' #' @param obj Input SummarizedExperiment object #' @param res Compartment resolution in bp -#' @param parallel Whether to run samples in parallel #' @param chr What chromosome to work on (leave as NULL to run on all chromosomes) #' @param targets Samples/cells to shrink towards +#' @param parallel Whether to run samples in parallel #' @param cores How many cores to use when running samples in parallel #' @param bootstrap Whether we should perform bootstrapping of inferred compartments #' @param num.bootstraps How many bootstraps to run +#' @param boot.parallel Whether to run the bootstrapping in parallel +#' @param boot.cores How many cores to use for the bootstrapping #' @param genome What genome to work on ("hg19", "hg38", "mm9", "mm10") #' @param group Whether to treat this as a group set of samples #' @param assay What type of single-cell assay is the input data ("atac" or "rna") @@ -24,20 +26,22 @@ #' data("k562_scrna_chr14", package = "compartmap") #' sc_compartments <- scCompartments( #' k562_scrna_chr14, -#' parallel = FALSE, #' chr = "chr14", +#' parallel = FALSE, #' bootstrap = FALSE, #' genome = "hg19" #' ) scCompartments <- function( obj, res = 1e6, - parallel = FALSE, chr = NULL, targets = NULL, + parallel = FALSE, cores = 2, bootstrap = TRUE, num.bootstraps = 100, + boot.parallel = FALSE, + boot.cores = 2, genome = c("hg19", "hg38", "mm9", "mm10"), group = FALSE, assay = c("atac", "rna") @@ -49,18 +53,19 @@ scCompartments <- function( if (!all(assay %in% c("atac", "rna"))) stop("Supported assays are 'atac', and 'rna'.") assay <- tolower(match.arg(assay)) verifyAssayNames(obj, assay = assay) - - sc_compartments <- getATACABsignal( + getCompartments( obj = obj, + assay = assay, res = res, - parallel = parallel, chr = chr, targets = targets, + parallel = parallel, cores = cores, bootstrap = bootstrap, num.bootstraps = num.bootstraps, + boot.parallel = boot.parallel, + boot.cores = boot.cores, genome = genome, group = group ) - return(sc_compartments) } diff --git a/man/getArrayABsignal.Rd b/man/arrayCompartments.Rd similarity index 84% rename from man/getArrayABsignal.Rd rename to man/arrayCompartments.Rd index 330db367..29fcb711 100644 --- a/man/getArrayABsignal.Rd +++ b/man/arrayCompartments.Rd @@ -1,25 +1,25 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getArrayABsignal.R -\name{getArrayABsignal} -\alias{getArrayABsignal} +% Please edit documentation in R/arrayCompartments.R +\name{arrayCompartments} +\alias{arrayCompartments} \title{Estimate A/B compartments from methylation array data} \usage{ -getArrayABsignal( +arrayCompartments( obj, res = 1000000, - parallel = TRUE, chr = NULL, targets = NULL, preprocess = TRUE, + parallel = TRUE, cores = 2, bootstrap = TRUE, num.bootstraps = 1000, + boot.parallel = TRUE, + boot.cores = 2, genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - array.type = c("hm450", "EPIC"), group = FALSE, - boot.parallel = TRUE, - boot.cores = 2 + other = NULL, + array.type = c("hm450", "EPIC") ) } \arguments{ @@ -27,46 +27,46 @@ getArrayABsignal( \item{res}{Compartment resolution in bp} -\item{parallel}{Whether to run samples in parallel} - \item{chr}{What chromosome to work on (leave as NULL to run on all chromosomes)} \item{targets}{Samples/cells to shrink towards} \item{preprocess}{Whether to preprocess the arrays prior to compartment inference} +\item{parallel}{Whether to run samples in parallel} + \item{cores}{How many cores to use when running samples in parallel} \item{bootstrap}{Whether we should perform bootstrapping of inferred compartments} \item{num.bootstraps}{How many bootstraps to run} -\item{genome}{What genome to work on ("hg19", "hg38", "mm9", "mm10")} +\item{boot.parallel}{Whether to run the bootstrapping in parallel} -\item{other}{Another arbitrary genome to compute compartments on} +\item{boot.cores}{How many cores to use for the bootstrapping} -\item{array.type}{What type of array is this ("hm450", "EPIC")} +\item{genome}{What genome to work on ("hg19", "hg38", "mm9", "mm10")} \item{group}{Whether to treat this as a group set of samples} -\item{boot.parallel}{Whether to run the bootstrapping in parallel} +\item{other}{Another arbitrary genome to compute compartments on} -\item{boot.cores}{How many cores to use for the bootstrapping} +\item{array.type}{What type of array is this ("hm450", "EPIC")} } \value{ A RaggedExperiment of inferred compartments } \description{ -\code{getArrayABsignal} returns estimated A/B compartments from methylation array data. +\code{arrayCompartments} returns estimated A/B compartments from methylation array data. } \examples{ if (requireNamespace("minfi", quietly = TRUE)) { data("array_data_chr14", package = "compartmap") - array_compartments <- getArrayABsignal( + array_compartments <- arrayCompartments( array.data.chr14, - parallel=FALSE, chr="chr14", + parallel=FALSE, bootstrap=FALSE, genome="hg19", array.type="hm450" diff --git a/man/getATACABsignal.Rd b/man/getATACABsignal.Rd deleted file mode 100644 index 3a9c419c..00000000 --- a/man/getATACABsignal.Rd +++ /dev/null @@ -1,90 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getATACABsignal.R -\name{getATACABsignal} -\alias{getATACABsignal} -\alias{getRNAABsignal} -\title{Estimate A/B compartments from ATAC-seq data} -\usage{ -getATACABsignal( - obj, - res = 1000000, - parallel = FALSE, - chr = NULL, - targets = NULL, - cores = 2, - bootstrap = TRUE, - num.bootstraps = 100, - genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - group = FALSE, - boot.parallel = FALSE, - boot.cores = 2 -) - -getRNAABsignal( - obj, - res = 1000000, - parallel = FALSE, - chr = NULL, - targets = NULL, - cores = 2, - bootstrap = TRUE, - num.bootstraps = 100, - genome = c("hg19", "hg38", "mm9", "mm10"), - other = NULL, - group = FALSE, - boot.parallel = FALSE, - boot.cores = 2 -) -} -\arguments{ -\item{obj}{Input SummarizedExperiment object} - -\item{res}{Compartment resolution in bp} - -\item{parallel}{Whether to run samples in parallel} - -\item{chr}{What chromosome to work on (leave as NULL to run on all chromosomes)} - -\item{targets}{Samples/cells to shrink towards} - -\item{cores}{How many cores to use when running samples in parallel} - -\item{bootstrap}{Whether we should perform bootstrapping of inferred compartments} - -\item{num.bootstraps}{How many bootstraps to run} - -\item{genome}{What genome to work on ("hg19", "hg38", "mm9", "mm10")} - -\item{other}{Another arbitrary genome to compute compartments on} - -\item{group}{Whether to treat this as a group set of samples} - -\item{boot.parallel}{Whether to run the bootstrapping in parallel} - -\item{boot.cores}{How many cores to use for the bootstrapping} -} -\value{ -A RaggedExperiment of inferred compartments -} -\description{ -\code{getATACABsignal} returns estimated A/B compartments from ATAC-seq data. -} -\section{Functions}{ -\itemize{ -\item \code{getRNAABsignal()}: Alias for getATACABsignal - -}} -\examples{ -if (requireNamespace("csaw", quietly = TRUE)) { - data("k562_scatac_chr14", package = "compartmap") - atac_compartments <- getATACABsignal( - k562_scatac_chr14, - parallel = FALSE, - chr = "chr14", - bootstrap = FALSE, - genome = "hg19", - group = TRUE - ) -} -} diff --git a/man/plotAB.Rd b/man/plotAB.Rd index ad420e8a..10dae644 100644 --- a/man/plotAB.Rd +++ b/man/plotAB.Rd @@ -20,7 +20,7 @@ plotAB( ) } \arguments{ -\item{grAB}{The GRanges object returned from scCompartments and getArrayABsignal} +\item{grAB}{The GRanges object returned from scCompartments and arrayCompartments} \item{chr}{Chromosome to subset to for plotting} diff --git a/man/preprocessArrays.Rd b/man/preprocessArrays.Rd index 972260f5..a040ad43 100644 --- a/man/preprocessArrays.Rd +++ b/man/preprocessArrays.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getArrayABsignal.R +% Please edit documentation in R/preprocessArrays.R \name{preprocessArrays} \alias{preprocessArrays} \title{Preprocess arrays for compartment inference} diff --git a/man/scCompartments.Rd b/man/scCompartments.Rd index acaff07e..92193fcb 100644 --- a/man/scCompartments.Rd +++ b/man/scCompartments.Rd @@ -2,17 +2,19 @@ % Please edit documentation in R/scCompartments.R \name{scCompartments} \alias{scCompartments} -\title{Estimate A/B compartments from single-cell sequencing data} +\title{Estimate A/B compartments from single-cell RNA or ATAC sequencing data} \usage{ scCompartments( obj, res = 1000000, - parallel = FALSE, chr = NULL, targets = NULL, + parallel = FALSE, cores = 2, bootstrap = TRUE, num.bootstraps = 100, + boot.parallel = FALSE, + boot.cores = 2, genome = c("hg19", "hg38", "mm9", "mm10"), group = FALSE, assay = c("atac", "rna") @@ -23,18 +25,22 @@ scCompartments( \item{res}{Compartment resolution in bp} -\item{parallel}{Whether to run samples in parallel} - \item{chr}{What chromosome to work on (leave as NULL to run on all chromosomes)} \item{targets}{Samples/cells to shrink towards} +\item{parallel}{Whether to run samples in parallel} + \item{cores}{How many cores to use when running samples in parallel} \item{bootstrap}{Whether we should perform bootstrapping of inferred compartments} \item{num.bootstraps}{How many bootstraps to run} +\item{boot.parallel}{Whether to run the bootstrapping in parallel} + +\item{boot.cores}{How many cores to use for the bootstrapping} + \item{genome}{What genome to work on ("hg19", "hg38", "mm9", "mm10")} \item{group}{Whether to treat this as a group set of samples} @@ -51,8 +57,8 @@ A RaggedExperiment of inferred compartments data("k562_scrna_chr14", package = "compartmap") sc_compartments <- scCompartments( k562_scrna_chr14, - parallel = FALSE, chr = "chr14", + parallel = FALSE, bootstrap = FALSE, genome = "hg19" ) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 62946a52..c1e753db 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -23,14 +23,13 @@ reference: - title: Compartment mapping contents: - scCompartments - - getArrayABsignal + - arrayCompartments - title: Compartment helper contents: - filterCompartments - fixCompartments - extractOpenClosed - getABSignal - - getATACABsignal - getRNAABsignal - title: Correlation matrix contents: diff --git a/tests/testthat/test-getArrayABsignal.R b/tests/testthat/test-getArrayABsignal.R index f4ded02d..07696f14 100644 --- a/tests/testthat/test-getArrayABsignal.R +++ b/tests/testthat/test-getArrayABsignal.R @@ -1,10 +1,10 @@ se.noranges <- SummarizedExperiment(rowRanges = GRanges()) se.bad <- SummarizedExperiment(rowRanges = GRanges("chr1:1-10"), assays = SimpleList(a = matrix())) -test_that("getArrayABsignal bad inputs", { - expect_error(getArrayABsignal(iris), err.verifySE) - expect_error(getArrayABsignal(se.noranges), err.verifyCoords) - expect_error(getArrayABsignal(se.bad), err.verifyAssayNames.beta) +test_that("arrayCompartments bad inputs", { + expect_error(arrayCompartments(iris), err.verifySE) + expect_error(arrayCompartments(se.noranges), err.verifyCoords) + expect_error(arrayCompartments(se.bad), err.verifyAssayNames.beta) }) test_that(".preprocessArrays", {