Skip to contents

Compute per-cell module scores for user-defined gene sets by comparing mean foreground gene signal to a background of expression-matched control genes. This is the MarchR equivalent of ArchR's addModuleScore().

Usage

# S3 method for class 'MarchRDataset'
add_module_score(
  proj,
  features,
  assay_name = character(0),
  name = "Module",
  n_bins = 25L,
  n_background = 100L,
  seed = 1L,
  overwrite = FALSE,
  threads = 1L,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

# S3 method for class 'MarchRProject'
add_module_score(
  proj,
  features,
  assay_name = character(0),
  dataset_names = character(0),
  name = "Module",
  n_bins = 25L,
  n_background = 100L,
  seed = 1L,
  overwrite = FALSE,
  threads = 1L,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

Arguments

proj

(MarchRProject) Project containing datasets with the assay.

features

(named list of character vectors) Each element is a gene set (character vector of feature/gene names). Names become column suffixes in cell metadata. If unnamed, modules are numbered sequentially.

assay_name

(character) Name of the matrix assay to score against (e.g. "GeneScoreMatrix", "RNA"). Auto-selected if only one assay exists.

name

(character) Prefix for output cell metadata columns. Columns are named {name}.{module_name}. Default is "Module".

n_bins

(integer) Number of quantile bins for grouping features by mean expression. Default is 25 (matching ArchR).

n_background

(integer) Number of background genes to sample per foreground gene from the matching expression bin. Default is 100 (matching ArchR).

seed

(integer) Random seed for background gene sampling.

overwrite

(logical) If TRUE, overwrite existing cell metadata columns with the same name. Default is FALSE.

threads

(integer) Threads for the matrix_stats() pass. Default 1L; not read from set_threads().

verbose

(logical) Print progress messages. Default getOption("MarchR.verbose", FALSE).

...

Additional arguments passed to methods.

dataset_names

(character) Names of datasets to score. Defaults to all datasets containing the specified assay.

Value

The modified MarchRDataset with module score columns added to cell metadata.

The modified MarchRProject with module score columns added to cell metadata in each scored dataset.

Details

Algorithm:

  1. Compute the mean signal of each feature (row) across all cells using BPCells::matrix_stats() to remain disk-backed.

  2. Rank features by mean signal and divide into n_bins equal-frequency quantile bins.

  3. For each module, identify the bin of each foreground gene and sample n_background control genes from the same bin.

  4. For each cell, score = mean(foreground genes) - mean(background genes).

  5. Store scores as cell metadata columns named {name}.{module_name}.

ArchR correspondence: This function corresponds to ArchR's addModuleScore().

  • ArchR parameter useMatrix maps to MarchR assay_name.

  • ArchR parameter nBin maps to MarchR n_bins.

  • ArchR parameter nBgd maps to MarchR n_background.

  • MarchR accepts any matrix assay (GeneScoreMatrix, RNA, etc.), while ArchR restricts to GeneScoreMatrix and TileMatrix.

  • When a module has no expression-matched background features (all of its features are zero-signal), ArchR returns NaN, while MarchR scores the module against all other features and warns.

Methods (by class)

  • add_module_score(MarchRDataset): Compute module scores for a MarchRDataset

  • add_module_score(MarchRProject): Compute module scores for a MarchRProject

See also

get_marker_features for differential marker analysis, add_gene_score_matrix for gene activity scoring.