Skip to content

Automatically filter out cell types with <10 cells in get_mean_ratio() #16

Description

@cyntsc

Hi Louise,

Thanks for the helpful function get_mean_ratio(). I wanted to suggest a small improvement to make it more robust when working with sparse or imbalanced datasets.

Current behavior
When running get_mean_ratio() without removing low-abundance cell types, I see the following warnings:

marker_stats <- get_mean_ratio(
    sce,
    assay_name = "logcounts",
    cellType_col = "cluster_ann", 
    gene_name = "gene_symbol",
    gene_ensembl = "gene_id"
)

Warning messages:
1: In get_mean_ratio(...) :
  One or more cell types has < 10 cells, this may result in unstable marker genes results. Check details of get_mean_ratio() for more info
2: In asMethod(object) :
  sparse->dense coercion: allocating vector of size 12.3 GiB

This can lead to:

Unstable marker selection
Memory overload when coercing sparse matrices to dense, as I describe in my previous issue: #15 (comment)

Describe the solution

In addition to the warning, it would be great if the function could internally filter out cell types with fewer than 10 cells, optionally controlled by an argument like min_cells = 10.

For example:

# remove cell types with fewer than 10 cells
celltypes <- colData(sce)$cluster_ann
celltype_counts <- table(celltypes)
low_ct <- names(celltype_counts[celltype_counts <= 10])
sce <- sce[, !(celltypes %in% low_ct)]

I think this could be a nice improvement, especially for users not aware of this limitation, and prevent downstream issues like memory overload.

Thanks for considering this suggestion!

Best,
Cynthia SC

R session()

[1] "Reproducibility information:"
> Sys.time()
[1] "2025-06-20 13:21:22 EDT"
> proc.time()
    user   system  elapsed 
 431.608   37.802 8952.417 
> options(width = 120)
> session_info()
01 [2] CRAN (R 4.4.0)
 benchmarkme            1.0.8     2022-06-12 [2] CRAN (R 4.4.0)
 benchmarkmeData        1.0.4     2020-04-23 [2] CRAN (R 4.4.0)
 Biobase              * 2.66.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 BiocFileCache          2.14.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 BiocGenerics         * 0.52.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 BiocIO                 1.16.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 BiocManager            1.30.26   2025-06-05 [1] CRAN (R 4.4.3)
 BiocNeighbors          2.0.1     2024-11-28 [2] Bioconductor 3.20 (R 4.4.2)
 BiocParallel           1.40.2    2025-04-10 [2] Bioconductor
 BiocSingular           1.22.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 BiocVersion            3.20.0    2024-05-01 [2] Bioconductor 3.20 (R 4.4.0)
 Biostrings             2.74.1    2024-12-16 [2] Bioconductor 3.20 (R 4.4.2)
 bit                    4.6.0     2025-03-06 [2] CRAN (R 4.4.3)
 bit64                  4.6.0-1   2025-01-16 [2] CRAN (R 4.4.2)
 bitops                 1.0-9     2024-10-03 [2] CRAN (R 4.4.1)
 blob                   1.2.4     2023-03-17 [2] CRAN (R 4.4.0)
 bluster                1.16.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 bslib                  0.9.0     2025-01-30 [2] CRAN (R 4.4.2)
 cachem                 1.1.0     2024-05-16 [2] CRAN (R 4.4.0)
 circlize               0.4.16    2024-02-20 [2] CRAN (R 4.4.0)
 cli                    3.6.5     2025-04-23 [2] CRAN (R 4.4.3)
 clue                   0.3-66    2024-11-13 [2] CRAN (R 4.4.2)
 cluster                2.1.8     2024-12-11 [3] CRAN (R 4.4.3)
 codetools              0.2-20    2024-03-31 [3] CRAN (R 4.4.3)
 colorspace             2.1-1     2024-07-26 [2] CRAN (R 4.4.1)
 ComplexHeatmap         2.22.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 config                 0.3.2     2023-08-30 [2] CRAN (R 4.4.0)
 cowplot                1.1.3     2024-01-22 [2] CRAN (R 4.4.0)
 crayon                 1.5.3     2024-06-20 [2] CRAN (R 4.4.1)
 curl                   6.3.0     2025-06-06 [1] CRAN (R 4.4.3)
 data.table             1.17.6    2025-06-17 [1] CRAN (R 4.4.3)
 DBI                    1.2.3     2024-06-02 [2] CRAN (R 4.4.0)
 dbplyr                 2.5.0     2024-03-19 [2] CRAN (R 4.4.0)
 DeconvoBuddies       * 0.99.39   2025-06-19 [1] Github (LieberInstitute/DeconvoBuddies@1d16d86)
 DelayedArray           0.32.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 dichromat              2.0-0.1   2022-05-02 [2] CRAN (R 4.4.0)
 digest                 0.6.37    2024-08-19 [2] CRAN (R 4.4.1)
 doParallel             1.0.17    2022-02-07 [2] CRAN (R 4.4.0)
 dplyr                * 1.1.4     2023-11-17 [2] CRAN (R 4.4.0)
 dqrng                  0.4.1     2024-05-28 [2] CRAN (R 4.4.0)
 DT                     0.33      2024-04-04 [2] CRAN (R 4.4.0)
 edgeR                  4.4.2     2025-01-27 [2] Bioconductor 3.20 (R 4.4.2)
 ExperimentHub          2.14.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 farver                 2.1.2     2024-05-13 [2] CRAN (R 4.4.0)
 fastmap                1.2.0     2024-05-15 [2] CRAN (R 4.4.0)
 filelock               1.0.3     2023-12-11 [2] CRAN (R 4.4.0)
 foreach                1.5.2     2022-02-02 [2] CRAN (R 4.4.0)
 generics               0.1.4     2025-05-09 [2] CRAN (R 4.4.3)
 GenomeInfoDb         * 1.42.3    2025-01-27 [2] Bioconductor 3.20 (R 4.4.2)
 GenomeInfoDbData       1.2.13    2024-10-01 [2] Bioconductor
 GenomicAlignments      1.42.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 GenomicRanges        * 1.58.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 GetoptLong             1.0.5     2020-12-15 [2] CRAN (R 4.4.0)
 ggbeeswarm             0.7.2     2023-04-29 [2] CRAN (R 4.4.0)
 ggplot2                3.5.2     2025-04-09 [2] CRAN (R 4.4.3)
 ggrepel                0.9.6     2024-09-07 [2] CRAN (R 4.4.1)
 GlobalOptions          0.1.2     2020-06-10 [2] CRAN (R 4.4.0)
 glue                   1.8.0     2024-09-30 [2] CRAN (R 4.4.1)
 golem                  0.5.1     2024-08-27 [2] CRAN (R 4.4.1)
 gridExtra              2.3       2017-09-09 [2] CRAN (R 4.4.0)
 gtable                 0.3.6     2024-10-25 [2] CRAN (R 4.4.2)
 here                 * 1.0.1     2020-12-13 [2] CRAN (R 4.4.0)
 htmltools              0.5.8.1   2024-04-04 [2] CRAN (R 4.4.0)
 htmlwidgets            1.6.4     2023-12-06 [2] CRAN (R 4.4.0)
 httpuv                 1.6.16    2025-04-16 [2] CRAN (R 4.4.3)
 httr                   1.4.7     2023-08-15 [2] CRAN (R 4.4.0)
 igraph                 2.1.4     2025-01-23 [2] CRAN (R 4.4.2)
 IRanges              * 2.40.1    2024-12-05 [2] Bioconductor 3.20 (R 4.4.2)
 irlba                  2.3.5.1   2022-10-03 [2] CRAN (R 4.4.0)
 iterators              1.0.14    2022-02-05 [2] CRAN (R 4.4.0)
 jquerylib              0.1.4     2021-04-26 [2] CRAN (R 4.4.0)
 jsonlite               2.0.0     2025-03-27 [2] CRAN (R 4.4.3)
 KEGGREST               1.46.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 later                  1.4.2     2025-04-08 [2] CRAN (R 4.4.3)
 lattice                0.22-6    2024-03-20 [3] CRAN (R 4.4.3)
 lazyeval               0.2.2     2019-03-15 [2] CRAN (R 4.4.0)
 lifecycle              1.0.4     2023-11-07 [2] CRAN (R 4.4.0)
 limma                  3.62.2    2025-01-09 [2] Bioconductor 3.20 (R 4.4.2)
 locfit                 1.5-9.12  2025-03-05 [2] CRAN (R 4.4.3)
 magick                 2.8.7     2025-06-06 [1] CRAN (R 4.4.3)
 magrittr               2.0.3     2022-03-30 [2] CRAN (R 4.4.0)
 Matrix                 1.7-2     2025-01-23 [3] CRAN (R 4.4.3)
 MatrixGenerics       * 1.18.1    2025-01-09 [2] Bioconductor 3.20 (R 4.4.2)
 matrixStats          * 1.5.0     2025-01-07 [2] CRAN (R 4.4.2)
 memoise                2.0.1     2021-11-26 [2] CRAN (R 4.4.0)
 metapod                1.14.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 mime                   0.13      2025-03-17 [2] CRAN (R 4.4.3)
 paletteer              1.6.0     2024-01-21 [2] CRAN (R 4.4.0)
 pillar                 1.10.2    2025-04-05 [2] CRAN (R 4.4.3)
 pkgconfig              2.0.3     2019-09-22 [2] CRAN (R 4.4.0)
 plotly                 4.10.4    2024-01-13 [2] CRAN (R 4.4.0)
 png                    0.1-8     2022-11-29 [2] CRAN (R 4.4.0)
 promises               1.3.3     2025-05-29 [1] CRAN (R 4.4.3)
 purrr                * 1.0.4     2025-02-05 [2] CRAN (R 4.4.2)
 R6                     2.6.1     2025-02-15 [2] CRAN (R 4.4.2)
 rafalib                1.0.4     2025-04-08 [1] CRAN (R 4.4.3)
 rappdirs               0.3.3     2021-01-31 [2] CRAN (R 4.4.0)
 RColorBrewer           1.1-3     2022-04-03 [2] CRAN (R 4.4.0)
 Rcpp                   1.0.14    2025-01-12 [2] CRAN (R 4.4.2)
 RCurl                  1.98-1.17 2025-03-22 [2] CRAN (R 4.4.3)
 rematch2               2.1.2     2020-05-01 [2] CRAN (R 4.4.0)
 restfulr               0.0.15    2022-06-16 [2] CRAN (R 4.4.0)
 rjson                  0.2.23    2024-09-16 [2] CRAN (R 4.4.1)
 rlang                  1.1.6     2025-04-11 [2] CRAN (R 4.4.3)
 rprojroot              2.0.4     2023-11-05 [2] CRAN (R 4.4.0)
 Rsamtools              2.22.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 RSQLite                2.4.1     2025-06-08 [1] CRAN (R 4.4.3)
 rstudioapi             0.17.1    2024-10-22 [2] CRAN (R 4.4.2)
 rsvd                   1.0.5     2021-04-16 [2] CRAN (R 4.4.0)
 rtracklayer            1.66.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 S4Arrays               1.6.0     2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 S4Vectors            * 0.44.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 sass                   0.4.10    2025-04-11 [2] CRAN (R 4.4.3)
 ScaledMatrix           1.14.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 scales                 1.4.0     2025-04-24 [2] CRAN (R 4.4.3)
 scater                 1.34.1    2025-03-03 [2] Bioconductor 3.20 (R 4.4.3)
 scran                  1.34.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 scuttle                1.16.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 sessioninfo          * 1.2.3     2025-02-05 [2] CRAN (R 4.4.2)
 shape                  1.4.6.1   2024-02-23 [2] CRAN (R 4.4.0)
 shiny                  1.10.0    2024-12-14 [2] CRAN (R 4.4.2)
 shinyWidgets           0.9.0     2025-02-21 [2] CRAN (R 4.4.3)
 SingleCellExperiment * 1.28.1    2024-11-10 [2] Bioconductor 3.20 (R 4.4.2)
 SparseArray            1.6.2     2025-02-20 [2] Bioconductor 3.20 (R 4.4.3)
 SpatialExperiment      1.16.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 spatialLIBD            1.21.5    2025-05-16 [1] Github (LieberInstitute/spatialLIBD@aff00db)
 statmod                1.5.0     2023-01-06 [2] CRAN (R 4.4.0)
 stringi                1.8.7     2025-03-27 [2] CRAN (R 4.4.3)
 stringr              * 1.5.1     2023-11-14 [2] CRAN (R 4.4.0)
 SummarizedExperiment * 1.36.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 tibble                 3.3.0     2025-06-08 [1] CRAN (R 4.4.3)
 tidyr                  1.3.1     2024-01-24 [2] CRAN (R 4.4.0)
 tidyselect             1.2.1     2024-03-11 [2] CRAN (R 4.4.0)
 UCSC.utils             1.2.0     2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 utf8                   1.2.6     2025-06-08 [1] CRAN (R 4.4.3)
 vctrs                  0.6.5     2023-12-01 [2] CRAN (R 4.4.0)
 vipor                  0.4.7     2023-12-18 [2] CRAN (R 4.4.0)
 viridis                0.6.5     2024-01-29 [2] CRAN (R 4.4.0)
 viridisLite            0.4.2     2023-05-02 [2] CRAN (R 4.4.0)
 withr                  3.0.2     2024-10-28 [2] CRAN (R 4.4.2)
 XML                    3.99-0.18 2025-01-01 [2] CRAN (R 4.4.2)
 xtable                 1.8-4     2019-04-21 [2] CRAN (R 4.4.0)
 XVector                0.46.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)
 yaml                   2.3.10    2024-07-26 [2] CRAN (R 4.4.1)
 zlibbioc               1.52.0    2024-10-29 [2] Bioconductor 3.20 (R 4.4.2)

 [1] /users/csoto/R/4.4.x
 [2] /jhpce/shared/community/core/conda_R/4.4.x/R/lib64/R/site-library
 [3] /jhpce/shared/community/core/conda_R/4.4.x/R/lib64/R/library
 * ── Packages attached to the search path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions