From 1663262d07d62c4803307eeeb4e970cf836ff63e Mon Sep 17 00:00:00 2001 From: Jonathan Griffiths <7976085+jonathangriffiths@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:19:51 +0100 Subject: [PATCH] deprecate beachmat::whichNonZero (#111) * deprecate beachmat::whichNonZero --- DESCRIPTION | 4 ++-- NAMESPACE | 3 ++- R/emptyDrops.R | 17 ++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe9144d..f5b61d7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: DropletUtils -Version: 1.25.1 -Date: 2024-07-09 +Version: 1.25.2 +Date: 2024-07-23 Title: Utilities for Handling Single-Cell Droplet Data Authors@R: c( person("Aaron", "Lun", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index fdd3dfe..ef24259 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -86,10 +86,11 @@ importFrom(S4Vectors,extractROWS) importFrom(S4Vectors,make_zero_col_DFrame) importFrom(S4Vectors,metadata) importFrom(SingleCellExperiment,SingleCellExperiment) +importFrom(SparseArray,nzvals) +importFrom(SparseArray,nzwhich) importFrom(SummarizedExperiment,assay) importFrom(SummarizedExperiment,colData) importFrom(beachmat,colBlockApply) -importFrom(beachmat,whichNonZero) importFrom(dqrng,generateSeedVectors) importFrom(edgeR,goodTuringProportions) importFrom(edgeR,q2qnbinom) diff --git a/R/emptyDrops.R b/R/emptyDrops.R index 1b8479a..65cedee 100644 --- a/R/emptyDrops.R +++ b/R/emptyDrops.R @@ -311,16 +311,16 @@ testEmptyDrops <- function(m, lower=100, niters=10000, test.ambient=FALSE, ignor list(seeds=seeds.per.core, streams=streams.per.core) } -#' @importFrom beachmat whichNonZero +#' @importFrom SparseArray nzwhich nzvals .compute_multinom_prob_data <- function(block, prop, alpha=Inf, BPPARAM=SerialParam()) # Efficiently calculates the data-dependent component of the log-multinomial probability # for a column-wise chunk of the full matrix (or, indeed, the full matrix itself). # Also does so for the Dirichlet-multinomial log-probability for a given 'alpha'. { - nonzero <- whichNonZero(block) - i <- nonzero$i - j <- nonzero$j - x <- nonzero$x + idx <- nzwhich(block, arr.ind=TRUE) + i <- idx[,1] + j <- idx[,2] + x <- nzvals(block) if (is.infinite(alpha)) { p.n0 <- x * log(prop[i]) - lfactorial(x) @@ -346,14 +346,13 @@ testEmptyDrops <- function(m, lower=100, niters=10000, test.ambient=FALSE, ignor } } -#' @importFrom beachmat whichNonZero +#' @importFrom SparseArray nzwhich nzvals #' @importFrom stats optimize .estimate_alpha <- function(mat, prop, totals, interval=c(0.01, 10000)) # Efficiently finds the MLE for the overdispersion parameter of a Dirichlet-multinomial distribution. { - nonzero <- whichNonZero(mat) - i <- nonzero$i - x <- nonzero$x + i <- nzwhich(mat, arr.ind=TRUE)[,1] + x <- nzvals(mat) per.prop <- prop[i] LOGLIK <- function(alpha) {