Skip to content

Commit e99b49e

Browse files
Merge pull request #161 from toobiwankenobi/utilsFix
conditional loading of DelayedMatrixStats
2 parents c260ec6 + 6ee9298 commit e99b49e

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Suggests:
2828
AUCell,
2929
BiocParallel,
3030
BiocStyle,
31+
DelayedMatrixStats,
3132
dplyr,
3233
fgsea,
3334
GSEABase,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(splitEnrichment)
1818
import(ggplot2)
1919
importFrom(MatrixGenerics,rowMeans2)
2020
importFrom(MatrixGenerics,rowSds)
21+
importFrom(MatrixGenerics,rowSums2)
2122
importFrom(SummarizedExperiment,colData)
2223
importFrom(ggdist,stat_pointinterval)
2324
importFrom(grDevices,hcl.pals)

R/utils.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
# -----------------------------------------------------------------------------
151151
# EXPRESSION MATRIX EXTRACTOR -------------------------------------------------
152152
# -----------------------------------------------------------------------------
153+
#' @importFrom MatrixGenerics rowSums2
153154
.cntEval <- function(obj, assay = "RNA", type = "counts") {
154155
if (.is_seurat(obj)) {
155156
# Use generic accessor if available
@@ -177,10 +178,16 @@
177178
} else {
178179
cnts <- obj
179180
}
181+
# Conditionally require DelayedMatrixStats if cnts is dgCMatrix
182+
if (inherits(cnts, "dgCMatrix")) {
183+
if (!requireNamespace("DelayedMatrixStats", quietly = TRUE)) {
184+
stop("Package 'DelayedMatrixStats' is required to handle sparse matrices. Please install it with BiocManager::install('DelayedMatrixStats').")
185+
}
186+
loadNamespace("DelayedMatrixStats")
187+
}
180188
cnts[MatrixGenerics::rowSums2(cnts) != 0, , drop = FALSE]
181189
}
182190

183-
184191
# -----------------------------------------------------------------------------
185192
# ATTACH / PULL ENRICHMENT MATRICES ------------------------------------------
186193
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)