From 0485e12a50bad945ed8e1839dac548feb531649b Mon Sep 17 00:00:00 2001 From: James Eapen Date: Wed, 22 Oct 2025 09:54:55 -0400 Subject: [PATCH 1/6] refactor(getArrayABsignal): extract preprocessArrays to own file --- R/getArrayABsignal.R | 56 -------------------------------------------- R/preprocessArrays.R | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 56 deletions(-) create mode 100644 R/preprocessArrays.R diff --git a/R/getArrayABsignal.R b/R/getArrayABsignal.R index a3eb8670..bdcc7b72 100644 --- a/R/getArrayABsignal.R +++ b/R/getArrayABsignal.R @@ -153,62 +153,6 @@ getArrayABsignal <- function( 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, 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 +} From e6d4189c82144cb152d6a60a07d3190a8469b8cb Mon Sep 17 00:00:00 2001 From: James Eapen Date: Wed, 22 Oct 2025 09:55:20 -0400 Subject: [PATCH 2/6] refactor(getCompartments): extract common compartment worker --- R/getATACABsignal.R | 169 +++------------------------------------- R/getArrayABsignal.R | 165 +++------------------------------------ R/getCompartments.R | 180 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+), 314 deletions(-) create mode 100644 R/getCompartments.R diff --git a/R/getATACABsignal.R b/R/getATACABsignal.R index ec6c19e1..954b2835 100644 --- a/R/getATACABsignal.R +++ b/R/getATACABsignal.R @@ -53,169 +53,20 @@ getATACABsignal <- function( boot.parallel = FALSE, boot.cores = 2 ) { - chr <- chr %||% - { - message("Processing all chromosomes") - 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") - - if (bootstrap) { - message("Pre-computing the bootstrap global means.") - bmeans <- precomputeBootstrapMeans( - obj = obj, - targets = targets, - num.bootstraps = num.bootstraps, - assay = "atac", - parallel = parallel, - num.cores = cores - ) - } - - if (group) { - atac.compartments.list <- mclapply(chr, function(c) { - atacCompartments( - 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 = ifelse(parallel, cores, 1)) - - atac.compartments <- sort(unlist(as(atac.compartments.list, "GRangesList"))) - return(atac.compartments) - } - - atac.compartments <- mclapply(columns, function(s) { - obj.sub <- obj[, s] - - message("Working on ", s) - atac.compartments.list <- lapply(chr, function(c) { - atacCompartments( - 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(atac.compartments.list, "GRangesList"))) - }, mc.cores = ifelse(parallel, cores, 1)) - - atac.compartments <- as(atac.compartments, "CompressedGRangesList") - RaggedExperiment(atac.compartments, colData = colData(obj)) -} - -# worker function -# this is the main analysis function for computing compartments from atacs -atacCompartments <- 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 = "atac", - 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 = "atac") - } - - 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, + getCompartments( + obj = obj, assay = "atac", + res = res, parallel = parallel, - cores = cores, + chr = chr, targets = targets, - res = res, + cores = cores, + bootstrap = bootstrap, + num.bootstraps = num.bootstraps, + boot.parallel = boot.parallel, + boot.cores = boot.cores, genome = genome, - q = 0.95, - svd = obj.svd, - group = group, - bootstrap.means = bmeans + group = group ) } diff --git a/R/getArrayABsignal.R b/R/getArrayABsignal.R index bdcc7b72..24a286c1 100644 --- a/R/getArrayABsignal.R +++ b/R/getArrayABsignal.R @@ -79,164 +79,19 @@ getArrayABsignal <- function( 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)) -} - -# 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, + getCompartments( + obj = obj, assay = "array", + res = res, parallel = parallel, - cores = cores, + chr = chr, targets = targets, - res = res, + cores = cores, + bootstrap = bootstrap, + num.bootstraps = num.bootstraps, + boot.parallel = boot.parallel, + boot.cores = boot.cores, genome = genome, - q = 0.95, - svd = obj.svd, - group = group, - bootstrap.means = bmeans + group = group ) } diff --git a/R/getCompartments.R b/R/getCompartments.R new file mode 100644 index 00000000..ad8178d6 --- /dev/null +++ b/R/getCompartments.R @@ -0,0 +1,180 @@ +getCompartments <- function( + obj, + assay, + res, + parallel, + chr, + targets, + cores, + bootstrap, + num.bootstraps, + boot.parallel, + boot.cores, + genome, + group +) { + 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 = assay) + + if (bootstrap) { + message("Pre-computing the bootstrap global means.") + bmeans <- precomputeBootstrapMeans( + obj = obj, + targets = targets, + num.bootstraps = num.bootstraps, + assay = assay, + parallel = parallel, + num.cores = cores + ) + } + + if (group) { + compartments.list <- mclapply(chr, function(c) { + .getCompartments( + obj, + obj, + assay = assay, + 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 = ifelse(parallel, cores, 1)) + + compartments <- sort(unlist(as(compartments.list, "GRangesList"))) + return(compartments) + } + + compartments <- mclapply(columns, function(s) { + obj.sub <- obj[, s] + + message("Working on ", s) + compartments.list <- lapply(chr, function(c) { + .getCompartments( + obj.sub, + obj, + assay = assay, + 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(compartments.list, "GRangesList"))) + }, mc.cores = ifelse(parallel, cores, 1), mc.preschedule = F) + + compartments <- as(compartments, "CompressedGRangesList") + RaggedExperiment(compartments, colData = colData(obj)) +} + +# this is the main analysis function for computing compartments +.getCompartments <- function( + obj, + original.obj, + assay, + 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 = assay, + 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 = assay) + } + + 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 = assay, + parallel = parallel, + cores = cores, + targets = targets, + res = res, + genome = genome, + q = 0.95, + svd = obj.svd, + group = group, + bootstrap.means = bmeans + ) +} From bef8044f247f8421ef25ddb2c2f886f7ad044ba6 Mon Sep 17 00:00:00 2001 From: James Eapen Date: Thu, 23 Oct 2025 12:27:14 -0400 Subject: [PATCH 3/6] refactor(scCompartments): directly call getCompartments without getATACABsignal --- NAMESPACE | 1 - R/getATACABsignal.R | 75 ---------------------------------- R/scCompartments.R | 7 ++-- man/getATACABsignal.Rd | 90 ----------------------------------------- man/preprocessArrays.Rd | 2 +- pkgdown/_pkgdown.yml | 1 - 6 files changed, 5 insertions(+), 171 deletions(-) delete mode 100644 R/getATACABsignal.R delete mode 100644 man/getATACABsignal.Rd diff --git a/NAMESPACE b/NAMESPACE index 777fa855..87c6c4d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,7 +13,6 @@ export(fisherZ) export(fixCompartments) export(flogit) export(getABSignal) -export(getATACABsignal) export(getArrayABsignal) export(getAssayNames) export(getBinMatrix) diff --git a/R/getATACABsignal.R b/R/getATACABsignal.R deleted file mode 100644 index 954b2835..00000000 --- a/R/getATACABsignal.R +++ /dev/null @@ -1,75 +0,0 @@ -#' @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( - 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 -) { - getCompartments( - obj = obj, - assay = "atac", - 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 - ) -} - -#' @describeIn getATACABsignal Alias for getATACABsignal -#' -getRNAABsignal <- getATACABsignal diff --git a/R/scCompartments.R b/R/scCompartments.R index 050b24bb..9d9d196c 100644 --- a/R/scCompartments.R +++ b/R/scCompartments.R @@ -49,9 +49,9 @@ 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 = "atac", res = res, parallel = parallel, chr = chr, @@ -59,8 +59,9 @@ scCompartments <- function( 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/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/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/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 62946a52..43db4c94 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -30,7 +30,6 @@ reference: - fixCompartments - extractOpenClosed - getABSignal - - getATACABsignal - getRNAABsignal - title: Correlation matrix contents: From 62e6e41bd532fdde099305799e5613eb8917ca24 Mon Sep 17 00:00:00 2001 From: James Eapen Date: Thu, 23 Oct 2025 12:48:37 -0400 Subject: [PATCH 4/6] !fix(sc|arrayCompartments): add missing args and reorder for consistency --- R/getArrayABsignal.R | 20 ++++++++++---------- R/scCompartments.R | 14 +++++++++----- man/getArrayABsignal.Rd | 26 +++++++++++++------------- man/scCompartments.Rd | 14 ++++++++++---- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/R/getArrayABsignal.R b/R/getArrayABsignal.R index 24a286c1..5353795f 100644 --- a/R/getArrayABsignal.R +++ b/R/getArrayABsignal.R @@ -5,19 +5,19 @@ #' #' @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 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 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 +#' @param array.type What type of array is this ("hm450", "EPIC") #' #' @return A RaggedExperiment of inferred compartments #' @import SummarizedExperiment @@ -33,8 +33,8 @@ #' data("array_data_chr14", package = "compartmap") #' array_compartments <- getArrayABsignal( #' array.data.chr14, -#' parallel=FALSE, #' chr="chr14", +#' parallel=FALSE, #' bootstrap=FALSE, #' genome="hg19", #' array.type="hm450" @@ -43,19 +43,19 @@ getArrayABsignal <- function( obj, res = 1e6, - 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") ) { verifySE(obj) verifyCoords(obj) diff --git a/R/scCompartments.R b/R/scCompartments.R index 9d9d196c..606db7f6 100644 --- a/R/scCompartments.R +++ b/R/scCompartments.R @@ -5,12 +5,14 @@ #' #' @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") @@ -51,11 +55,11 @@ scCompartments <- function( verifyAssayNames(obj, assay = assay) getCompartments( obj = obj, - assay = "atac", + assay = assay, res = res, - parallel = parallel, chr = chr, targets = targets, + parallel = parallel, cores = cores, bootstrap = bootstrap, num.bootstraps = num.bootstraps, diff --git a/man/getArrayABsignal.Rd b/man/getArrayABsignal.Rd index 330db367..2b6e76c9 100644 --- a/man/getArrayABsignal.Rd +++ b/man/getArrayABsignal.Rd @@ -7,19 +7,19 @@ getArrayABsignal( 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,31 +27,31 @@ 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 @@ -65,8 +65,8 @@ if (requireNamespace("minfi", quietly = TRUE)) { data("array_data_chr14", package = "compartmap") array_compartments <- getArrayABsignal( array.data.chr14, - parallel=FALSE, chr="chr14", + parallel=FALSE, bootstrap=FALSE, genome="hg19", array.type="hm450" diff --git a/man/scCompartments.Rd b/man/scCompartments.Rd index acaff07e..15275e8e 100644 --- a/man/scCompartments.Rd +++ b/man/scCompartments.Rd @@ -7,12 +7,14 @@ 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" ) From 815ae54c4fdedd17cfe35314fc4b1fbf5a86317a Mon Sep 17 00:00:00 2001 From: James Eapen Date: Thu, 23 Oct 2025 12:49:45 -0400 Subject: [PATCH 5/6] !fix(arrayCompartments): rename getArrayABsignal to arrayCompartments --- NAMESPACE | 2 +- R/{getArrayABsignal.R => arrayCompartments.R} | 6 +++--- R/plotAB.R | 2 +- man/{getArrayABsignal.Rd => arrayCompartments.Rd} | 12 ++++++------ man/plotAB.Rd | 2 +- pkgdown/_pkgdown.yml | 2 +- tests/testthat/test-getArrayABsignal.R | 8 ++++---- 7 files changed, 17 insertions(+), 17 deletions(-) rename R/{getArrayABsignal.R => arrayCompartments.R} (94%) rename man/{getArrayABsignal.Rd => arrayCompartments.Rd} (87%) diff --git a/NAMESPACE b/NAMESPACE index 87c6c4d7..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,7 +14,6 @@ export(fisherZ) export(fixCompartments) export(flogit) export(getABSignal) -export(getArrayABsignal) export(getAssayNames) export(getBinMatrix) export(getChrs) diff --git a/R/getArrayABsignal.R b/R/arrayCompartments.R similarity index 94% rename from R/getArrayABsignal.R rename to R/arrayCompartments.R index 5353795f..4bff477c 100644 --- a/R/getArrayABsignal.R +++ b/R/arrayCompartments.R @@ -1,7 +1,7 @@ #' @title Estimate A/B compartments from methylation array data #' #' @description -#' \code{getArrayABsignal} returns estimated A/B compartments from methylation array data. +#' \code{arrayCompartments} returns estimated A/B compartments from methylation array data. #' #' @param obj Input SummarizedExperiment object #' @param res Compartment resolution in bp @@ -31,7 +31,7 @@ #' #' if (requireNamespace("minfi", quietly = TRUE)) { #' data("array_data_chr14", package = "compartmap") -#' array_compartments <- getArrayABsignal( +#' array_compartments <- arrayCompartments( #' array.data.chr14, #' chr="chr14", #' parallel=FALSE, @@ -40,7 +40,7 @@ #' array.type="hm450" #' ) #' } -getArrayABsignal <- function( +arrayCompartments <- function( obj, res = 1e6, chr = NULL, 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/man/getArrayABsignal.Rd b/man/arrayCompartments.Rd similarity index 87% rename from man/getArrayABsignal.Rd rename to man/arrayCompartments.Rd index 2b6e76c9..29fcb711 100644 --- a/man/getArrayABsignal.Rd +++ b/man/arrayCompartments.Rd @@ -1,10 +1,10 @@ % 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, chr = NULL, @@ -57,13 +57,13 @@ getArrayABsignal( 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, chr="chr14", parallel=FALSE, 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/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 43db4c94..c1e753db 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -23,7 +23,7 @@ reference: - title: Compartment mapping contents: - scCompartments - - getArrayABsignal + - arrayCompartments - title: Compartment helper contents: - filterCompartments 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", { From 9382e7b2d0449bbbab9e9145b98b70d69bb370da Mon Sep 17 00:00:00 2001 From: James Eapen Date: Thu, 23 Oct 2025 13:06:11 -0400 Subject: [PATCH 6/6] docs(scCompartments): specify that inputs are RNA or ATAC --- R/scCompartments.R | 2 +- man/scCompartments.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/scCompartments.R b/R/scCompartments.R index 606db7f6..251bb099 100644 --- a/R/scCompartments.R +++ b/R/scCompartments.R @@ -1,4 +1,4 @@ -#' @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. diff --git a/man/scCompartments.Rd b/man/scCompartments.Rd index 15275e8e..92193fcb 100644 --- a/man/scCompartments.Rd +++ b/man/scCompartments.Rd @@ -2,7 +2,7 @@ % 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,