Skip to contents

Partitions cells into pseudobulk replicate groups suitable for downstream peak calling (add_reproducible_peak_set), differential testing, and coverage track visualization. For each cell group (e.g., cluster), cells are assigned to replicates that balance sample-of-origin labels and cell counts.

Usage

# Default S3 method
add_group_coverages(
  proj,
  sample_labels = NULL,
  min_cells = 40L,
  max_cells = 500L,
  min_replicates = 2L,
  max_replicates = 5L,
  sample_ratio = 0.8,
  seed = 1L,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

# S3 method for class 'MarchRProject'
add_group_coverages(
  proj,
  group_by = "clusters",
  sample_labels = NULL,
  dataset_names = character(0),
  min_cells = 40L,
  max_cells = 500L,
  min_replicates = 2L,
  max_replicates = 5L,
  sample_ratio = 0.8,
  seed = 1L,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

Arguments

proj

(named character vector) Group assignments where names are cell names and values are group labels.

sample_labels

(character or named vector) NULL or metadata column name or named character vector (names = cell names) of sample-of-origin labels. NULL on the project method uses dataset membership; NULL on the default method disables label-aware assignment. Default NULL.

min_cells

(integer) Minimum number of cells per replicate. Groups with fewer than min_cells * min_replicates cells use overlap- minimizing sampling. Default is 40 (matching ArchR).

max_cells

(integer) Maximum number of cells per replicate. Replicates exceeding this are randomly downsampled. Default is 500 (matching ArchR).

min_replicates

(integer) Minimum number of pseudobulk replicates per group. Default is 2 (matching ArchR).

max_replicates

(integer) Maximum number of replicates per group. Default is 5 (matching ArchR).

sample_ratio

(numeric) Fraction of cells to sample when the group has fewer than min_cells * min_replicates cells. Default is 0.8 (matching ArchR).

seed

(integer) Random seed for reproducibility. Default is 1.

verbose

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

group_by

(character or named character vector) Either a metadata column name (e.g., "clusters") or a named character vector of custom group labels (names = cell names, values = group labels). When a column name is given, each unique value becomes a group. When a named vector is given, groups are stored under "custom_groups". Default is "clusters" (matching add_clusters() default). Not used for the default method.

dataset_names

(character) Names of datasets to include. Defaults to all datasets.

Value

  • default method: A named list (one entry per group) where each entry is a list of character vectors (one per replicate) containing cell names.

  • MarchRProject method: The modified MarchRProject with group coverages stored in proj$group_coverages[[group_by]].

Details

Algorithm (matching ArchR's addGroupCoverages()):

For each cell group, cells are assigned to replicates using one of three strategies based on available cell count:

  1. Abundant cells (n >= min_cells * min_replicates and labels available): Cells are split by sample label. Samples with >= min_cells cells become individual replicates. Remaining cells are merged or redistributed to reach min_replicates.

  2. Moderate cells (n >= min_cells / sample_ratio): Overlap-minimizing random sampling creates min_replicates replicates of min_cells cells each.

  3. Few cells (n < min_cells / sample_ratio): Same as moderate but with replacement to reach min_cells per replicate.

After assignment, each replicate is capped at max_cells and the total number of replicates is capped at max_replicates.

ArchR correspondence: This function implements the cell assignment logic of ArchR's addGroupCoverages(). Coverage computation is handled lazily via BPCells::merge_cells().

Methods (by class)

  • add_group_coverages(default): Create pseudobulk replicates from a named group vector. Returns the bare list of replicate assignments.

  • add_group_coverages(MarchRProject): Create pseudobulk replicates for a MarchRProject and store in proj$group_coverages[[group_by]].

See also

get_group_coverages for retrieving stored groups BPCells::merge_cells for creating pseudobulk fragment objects get_marker_features for differential testing