Skip to contents

This function implements the meta cell aggregation from Bilous, et al. The core idea is to use the walktrap community detection on the kNN graph. For details, please refer to the paper.

Usage

generate_supercells_sc(
  object,
  sc_supercell_params = params_sc_supercell(),
  regenerate_knn = FALSE,
  embd_to_use = "pca",
  no_embd_to_use = NULL,
  cells_to_use = NULL,
  target_size = 1e+05,
  seed = 42L,
  .verbose = TRUE
)

Arguments

object

SingleCells or SingleCellsSubset class.

sc_supercell_params

List. Output of params_sc_supercell(). A list with the following items:

  • walk_length - Integer. Walk length for the Walktrap algorithm.

  • graining_factor - Numeric. Graining level of data (proportion of number of single cells in the initial dataset to the number of metacells in the final dataset)

  • use_kernel - Boolean. Shall a kernel be applied.

  • kith_neighbour - Optional integer. Which neighbour to use for the sigma estimation.

  • knn - List of kNN parameters. See params_knn_defaults() for available parameters and their defaults.

regenerate_knn

Boolean. Shall a kNN graph be regenerated.

embd_to_use

String. The embedding to use. Only relevant if you set regenerate_knn to TRUE.

no_embd_to_use

Optional integer. Number of embedding dimensions to use. If NULL all will be used. Only relevant if you set regenerate_knn to TRUE.

cells_to_use

Optional string. Names of the cells to use for the generation of the meta-cells. If provided, this function will regenerate the kNN graph no matter what.

target_size

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

seed

Integer. Seed for reproducibility.

.verbose

Boolean or integer. Controls verbosity and returns run times. FALSE -> quiet, TRUE or 1L -> normal verbosity, 2L -> detailed verbosity.

Value

A MetaCells() with the data generated by this meta cell aggregation method.

References

Bilous, et al. BMC Bioinform., 2022

Examples

# walktrap based super cells at a graining factor of 10
sc <- demo_single_cells()
mc <- generate_supercells_sc(
  sc,
  sc_supercell_params = params_sc_supercell(
    graining_factor = 10,
    knn = list(k = 10L)
  ),
  regenerate_knn = TRUE,
  .verbose = FALSE
)
mc
#> Single cell experiment (Meta Cells).
#>   Meta cell method: supercells
#>   Merged: FALSE
#>   No meta cells: 50
#>   No genes: 50
#>   No cells aggregated: 500
#>   No obs rows in source: 500
#>   HVG calculated: FALSE
#>   PCA calculated: FALSE
#>   Other embeddings: none
#>   KNN generated: FALSE
#>   SNN generated: FALSE
#>   Stale artefacts: none

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