Skip to content

Commit

Permalink
Replace colsum with scrapper for consistent parallelization.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Dec 15, 2024
1 parent 07121b6 commit 2845bcb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ importFrom(BiocNeighbors,defineBuilder)
importFrom(BiocParallel,SerialParam)
importFrom(BiocParallel,bpnworkers)
importFrom(DelayedArray,DelayedArray)
importFrom(DelayedArray,colsum)
importFrom(DelayedArray,getAutoBPPARAM)
importFrom(DelayedArray,is_sparse)
importFrom(DelayedArray,rowMaxs)
importFrom(DelayedArray,rowMins)
importFrom(DelayedArray,setAutoBPPARAM)
importFrom(DelayedArray,sweep)
importFrom(DelayedMatrixStats,rowAnyNAs)
importFrom(DelayedMatrixStats,rowMedians)
importFrom(Matrix,rowMeans)
Expand Down
9 changes: 4 additions & 5 deletions R/SingleR.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#' @importFrom SummarizedExperiment assay
#' @importClassesFrom SummarizedExperiment SummarizedExperiment
#' @importFrom methods is
#' @importFrom DelayedArray colsum DelayedArray getAutoBPPARAM setAutoBPPARAM
#' @importFrom DelayedArray DelayedArray
#' @importFrom BiocParallel SerialParam
SingleR <- function(
test,
Expand Down Expand Up @@ -144,10 +144,9 @@ SingleR <- function(
}

if (!is.null(clusters)) {
oldp <- getAutoBPPARAM()
setAutoBPPARAM(BPPARAM)
on.exit(setAutoBPPARAM(oldp), add=TRUE)
test <- colsum(DelayedArray(test), clusters)
agg <- scrapper::aggregateAcrossCells(test, list(clusters=clusters), num.threads=num.threads)
test <- agg$sums
colnames(test) <- agg$combinations$clusters
}

classifySingleR(
Expand Down
7 changes: 3 additions & 4 deletions R/aggregateReference.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#' @importFrom SummarizedExperiment SummarizedExperiment
#' @importFrom S4Vectors DataFrame
#' @importFrom Matrix rowMeans
#' @importFrom DelayedArray sweep colsum DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom BiocParallel SerialParam bpnworkers
aggregateReference <- function(
ref,
Expand Down Expand Up @@ -125,9 +125,8 @@ aggregateReference <- function(
}

clustered <- scrapper::clusterKmeans(pcs, k=cur.ncenters, num.threads=num.threads)
agg <- colsum(current, clustered$cluster)
tab <- table(clustered$cluster)[colnames(agg)]
output <- sweep(agg, 2, tab, "/")
agg <- scrapper::aggregateAcrossCells(current, list(cluster=clustered$cluster), num.threads=num.threads)
output <- sweep(agg$sums, 2, agg$counts, "/")
}

output.vals[[lab]] <- output
Expand Down

0 comments on commit 2845bcb

Please sign in to comment.