Skip to contents

This function implements the meta cell aggregation from Morabito, et al. The generation of metacells is a useful approach for subsequent application of for example correlation-based methods to identify co-regulated genes.

Usage

generate_bt_meta_cells_sc(
  object,
  sc_meta_cell_params = params_sc_bt_metacells(),
  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_meta_cell_params

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

  • max_shared - Maximum number of allowed shared neighbours for the meta cell to be considered.

  • target_no_metacells - Number of target meta cells you wish to reach.

  • max_iter - Maximum number of iterations you want to use for the algorithm.

  • 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

Morabito, et al. Cell Rep Methods, 2023

Examples

# 50 meta cells off the demo object
sc <- demo_single_cells()
mc <- generate_bt_meta_cells_sc(
  sc,
  sc_meta_cell_params = params_sc_bt_metacells(
    target_no_metacells = 50L,
    knn = list(k = 10L)
  ),
  .verbose = FALSE
)
mc
#> Single cell experiment (Meta Cells).
#>   Meta cell method: meta_cells_hdwgcna
#>   Merged: FALSE
#>   No meta cells: 50
#>   No genes: 50
#>   No cells aggregated: 366
#>   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)