Skip to contents

Rust port of the metacells (MC2) divide and conquer pipeline from Ben-Kiki, et al. It works on the raw counts directly and builds its own similarity graph per pile, so no embedding or kNN graph is needed. Cells are split into piles, each pile gets its own feature selection, balanced kNN graph and partition, deviant cells are pulled out and re-run in further rounds, and whatever is still not convincing ends up as an outlier (unassigned). Cells sharing a rare gene module are piled together first, so small populations do not get spread across piles; switch that off via rare_gene_modules in dac_params.

Unlike the other methods, MC2 does not aim for a fixed number of meta cells but for a target size (target_metacell_size) and UMI count (target_metacell_umis), and it will leave cells unassigned.

Usage

generate_metacells2_sc(
  object,
  mc2_params = params_sc_metacells2(),
  dac_params = params_sc_metacells2_dac(),
  cells_to_use = NULL,
  target_size = 1e+05,
  seed = 42L,
  .verbose = TRUE
)

Arguments

object

SingleCells or SingleCellsSubset class.

mc2_params

List. Output of params_sc_metacells2(), the per-pile parameters.

dac_params

List. Output of params_sc_metacells2_dac(), the piling and rare gene module parameters.

cells_to_use

Optional string. Names of the cells to use for the generation of the meta cells. Cells not kept by the object are ignored.

target_size

Numeric. The library target size to normalise the meta cells to.

seed

Integer. Seed for reproducibility.

.verbose

Boolean. Controls verbosity.

Value

A MetaCells() with the data generated by this meta cell aggregation method. The other_data slot holds

  • cell_info - data.table with original_cell_idx (1-indexed position in the count file), dissolved (was the cell's candidate dissolved in its last pile), level (outlier round that placed it) and rare_module (1-indexed rare gene module, NA for none) per included cell.

  • rare_gene_modules - data.table with gene_id and rare_module for the genes in a rare gene module.

  • selected_genes - Character vector. Genes selected in any pile plus the rare module genes.

References

Ben-Kiki, et al., Genome Biol., 2022

Examples

# small meta cells on the demo data, no rare gene module detection
sc <- demo_single_cells()
mc <- generate_metacells2_sc(
  sc,
  mc2_params = params_sc_metacells2(
    target_metacell_size = 20L,
    target_metacell_umis = 20000
  ),
  dac_params = params_sc_metacells2_dac(rare_gene_modules = FALSE),
  .verbose = FALSE
)
mc
#> Single cell experiment (Meta Cells).
#>   Meta cell method: metacells2
#>   Merged: FALSE
#>   No meta cells: 15
#>   No genes: 50
#>   No cells aggregated: 489
#>   No obs rows in source: 500
#>   HVG calculated: FALSE
#>   PCA calculated: FALSE
#>   Other embeddings: none
#>   KNN generated: FALSE
#>   Graph generated: FALSE
#>   Stale artefacts: none

unlink(sc@dir_data, recursive = TRUE, force = TRUE)