GabrielHoffman / dreamlet

Perform differential expression analysis on multi-sample single cell datasets using linear mixed models
https://gabrielhoffman.github.io/dreamlet
20 stars 4 forks source link

Resync the package with the most recent developments in packages SparseArray and DelayedArray #23

Closed hpages closed 3 weeks ago

hpages commented 2 months ago

Hi,

This patch repairs dreamlet:::colsum2() which stopped working after some recent changes in the devel branch of packages SparseArray and DelayedArray. Sorry for that!

Note that an alternative would be to drop dreamlet:::colsum2() and to just use colsum() instead. The latter has recently been optimized on DelayedMatrix objects (you will need S4Vectors >= 0.43.2 and SparseArray >= 1.5.23 to get these optimizations):

library(HDF5Array)
library(dreamlet)
library(ExperimentHub)
hub <- ExperimentHub()

## Dense DelayedMatrix:
counts <- HDF5Array(hub[["EH1040"]], "counts")
M1 <- counts[ , 1:50000]
group <- sample(letters, ncol(M1), replace=TRUE)

system.time(cs1a <- colsum(M1, group))
#    user  system elapsed 
#  11.778   1.441  13.218 
system.time(cs1b <- dreamlet:::colsum2(M1, group))
#    user  system elapsed 
#  13.027   1.485  14.510
identical(cs1a, cs1b)  # TRUE

## Sparse DelayedMatrix:
tenx <- TENxMatrix(hub[["EH1039"]], group="mm10")
M2 <- tenx[ , 1:50000]

system.time(cs2a <- colsum(M2, group))
#    user  system elapsed 
#   5.539   0.079   5.626 
system.time(cs2b <- dreamlet:::colsum2(M2, group))
#    user  system elapsed 
#   6.089   0.056   6.144 
identical(cs2a, cs2b)  # TRUE

This is on a laptop running Ubuntu 23.10 and R 4.4.0, and with S4Vectors 0.43.2 and SparseArray 1.5.23.

Let me know if you have questions,

H.

sessionInfo() ``` R version 4.4.0 (2024-04-24) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 23.10 Matrix products: default BLAS: /home/hpages/R/R-4.4.0/lib/libRblas.so LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C time zone: America/Los_Angeles tzcode source: system (glibc) attached base packages: [1] stats4 stats graphics grDevices utils datasets methods [8] base other attached packages: [1] TENxBrainData_1.25.0 ExperimentHub_2.13.0 [3] AnnotationHub_3.13.0 BiocFileCache_2.13.0 [5] dbplyr_2.5.0 dreamlet_1.3.3 [7] SingleCellExperiment_1.27.2 SummarizedExperiment_1.35.1 [9] Biobase_2.65.0 GenomicRanges_1.57.1 [11] GenomeInfoDb_1.41.1 variancePartition_1.35.4 [13] BiocParallel_1.39.0 limma_3.61.4 [15] ggplot2_3.5.1 HDF5Array_1.33.4 [17] rhdf5_2.49.0 DelayedArray_0.31.9 [19] SparseArray_1.5.23 S4Arrays_1.5.5 [21] IRanges_2.39.2 abind_1.4-5 [23] S4Vectors_0.43.2 MatrixGenerics_1.17.0 [25] matrixStats_1.3.0 BiocGenerics_0.51.0 [27] Matrix_1.7-0 loaded via a namespace (and not attached): [1] splines_4.4.0 bitops_1.0-7 [3] filelock_1.0.3 tibble_3.2.1 [5] graph_1.83.0 XML_3.99-0.17 [7] lifecycle_1.0.4 Rdpack_2.6 [9] mixsqp_0.3-54 edgeR_4.3.5 [11] lattice_0.22-6 MASS_7.3-61 [13] backports_1.5.0 magrittr_2.0.3 [15] metafor_4.6-0 yaml_2.3.9 [17] DBI_1.2.3 minqa_1.2.7 [19] zlibbioc_1.51.1 EnvStats_2.8.1 [21] purrr_1.0.2 rmeta_3.0 [23] msigdbr_7.5.1 RCurl_1.98-1.16 [25] rappdirs_0.3.3 GenomeInfoDbData_1.2.12 [27] ggrepel_0.9.5 pbkrtest_0.5.3 [29] irlba_2.3.5.1 annotate_1.83.0 [31] DelayedMatrixStats_1.27.2 codetools_0.2-20 [33] tidyselect_1.2.1 UCSC.utils_1.1.0 [35] lme4_1.1-35.5 mathjaxr_1.6-0 [37] jsonlite_1.8.8 iterators_1.0.14 [39] tools_4.4.0 progress_1.2.3 [41] Rcpp_1.0.12 zenith_1.7.0 [43] glue_1.7.0 dplyr_1.1.4 [45] withr_3.0.0 numDeriv_2016.8-1.1 [47] BiocManager_1.30.23 fastmap_1.2.0 [49] boot_1.3-30 rhdf5filters_1.17.0 [51] fansi_1.0.6 caTools_1.18.2 [53] truncnorm_1.0-9 mime_0.12 [55] R6_2.5.1 colorspace_2.1-0 [57] scattermore_1.2 gtools_3.9.5 [59] RSQLite_2.3.7 RhpcBLASctl_0.23-42 [61] utf8_1.2.4 tidyr_1.3.1 [63] generics_0.1.3 data.table_1.15.4 [65] corpcor_1.6.10 prettyunits_1.2.0 [67] httr_1.4.7 pkgconfig_2.0.3 [69] gtable_0.3.5 blob_1.2.4 [71] XVector_0.45.0 remaCor_0.0.18 [73] GSEABase_1.67.0 scales_1.3.0 [75] png_0.1-8 fANCOVA_0.6-1 [77] ashr_2.2-63 reshape2_1.4.4 [79] nlme_3.1-165 curl_5.2.1 [81] nloptr_2.1.1 cachem_1.1.0 [83] stringr_1.5.1 BiocVersion_3.20.0 [85] KernSmooth_2.23-24 parallel_4.4.0 [87] vipor_0.4.7 metadat_1.2-0 [89] RcppZiggurat_0.1.6 AnnotationDbi_1.67.0 [91] pillar_1.9.0 grid_4.4.0 [93] vctrs_0.6.5 gplots_3.1.3.1 [95] mashr_0.2.79 xtable_1.8-4 [97] beeswarm_0.4.0 Rgraphviz_2.49.0 [99] KEGGgraph_1.65.0 invgamma_1.1 [101] mvtnorm_1.2-5 cli_3.6.3 [103] locfit_1.5-9.10 compiler_4.4.0 [105] rlang_1.1.4 crayon_1.5.3 [107] SQUAREM_2021.1 plyr_1.8.9 [109] ggbeeswarm_0.7.2 stringi_1.8.4 [111] assertthat_0.2.1 babelgene_22.9 [113] lmerTest_3.1-3 munsell_0.5.1 [115] Biostrings_2.73.1 aod_1.3.3 [117] hms_1.1.3 sparseMatrixStats_1.17.2 [119] bit64_4.0.5 Rhdf5lib_1.27.0 [121] KEGGREST_1.45.1 statmod_1.5.0 [123] rbibutils_2.2.16 Rfast_2.1.0 [125] broom_1.0.6 memoise_2.0.1 [127] RcppParallel_5.1.8 bit_4.0.5 [129] EnrichmentBrowser_2.35.1 ```
hpages commented 3 weeks ago

@GEHoffman Looks like you manually incorporated these changes in commit 8a427bee3071e63aaa5cf1b867e2fc4db9d89a63. Any reason to keep that PR open then?

GabrielHoffman commented 3 weeks ago

Thanks for the feedback. I fixed it on my end. Closing here

Gabriel