Skip to contents

Matches each peak to background peaks with similar accessibility and GC content; "bpcells" also matches peak length. "chromVAR" and "bpcells" store a peak x n_iterations integer matrix of sampled background peak indices. "betterChromVAR" stores the bias bins those samples are drawn from, so add_deviations_matrix() needs no sampling. Required upstream of peak_annotation_enrichment(background = "background_peaks") and add_deviations_matrix().

Usage

# S3 method for class 'MarchRProject'
add_background_peaks(
  proj,
  method = c("chromVAR", "bpcells", "betterChromVAR"),
  n_iterations = 50L,
  w = 0.1,
  bin_size = 50L,
  seed = 1L,
  knn_ef = 200L,
  overwrite = FALSE,
  verbose = getOption("MarchR.verbose", FALSE),
  dataset_names = NULL,
  ...
)

Arguments

proj

(MarchRProject) Project with peak_set, peak_set$gc, and a PeakMatrix.

method

(character) "chromVAR" (default, via chromVAR::getBackgroundPeaks()), "bpcells" (dependency-free, via BPCells::knn_hnsw()), "betterChromVAR" (dependency-free; deterministic bias bins with closed-form deviations).

n_iterations

(integer) Background peaks sampled per peak. Default 50. For "betterChromVAR", used only when enrichment draws peaks from the bins.

w

(numeric) Gaussian bias-kernel width in whitened bias units, for "chromVAR" and "betterChromVAR". Default 0.1, suited to bin_size = 50; raise it when bin_size is smaller.

bin_size

(integer) Bins per bias dimension for "chromVAR" and "betterChromVAR". Default 50.

seed

(integer) Random seed. Default 1L. For "betterChromVAR", used only when enrichment draws peaks from the bins.

knn_ef

(integer) ef parameter for BPCells::knn_hnsw() (only used when method = "bpcells").

overwrite

(logical) Replace existing background_peaks. Default FALSE keeps the stored background, warning if it was built with another method.

verbose

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

dataset_names

(character or NULL) Reference datasets whose PeakMatrix counts are pooled for background matching and deviation expectations. NULL (default) uses all datasets with a PeakMatrix. An explicit selection fixes the reference population even when other datasets are added.

...

Unused.

Value

Modified MarchRProject with proj$background_peaks populated: a peak x n_iterations integer matrix for "chromVAR" and "bpcells", or for "betterChromVAR" a MarchRBinBackground list with bs (grid dimensions), peak2bin (bin of each peak), bin_density (peaks per bin), and bin_probs (sparse bin x bin per-peak selection probabilities).

Details

ArchR correspondence: method = "chromVAR" corresponds to ArchR's addBgdPeaks(), except that seed is honored where ArchR hard-codes set.seed(1).

betterChromVAR correspondence: method = "betterChromVAR" stores the bias bins reintegrated from the betterChromVAR package (Wang et al., bioRxiv 2026) instead of sampled peaks; see the preprint for the method. Unlike betterChromVAR::getBackgroundBins(), bins are chosen by kernel weight alone, as in chromVAR::getBackgroundPeaks() (Schep et al., Nat Methods 2017). Enrichment functions draw n_iterations peaks per peak from the bins, as betterChromVAR::sampleBackgroundPeaks() does. Building the bins needs memory growing with bin_size^4, about 0.25 GB at the default.

Background consumers validate reference cells, peak keys, GC, and streamed peak totals before reuse. After these inputs change, or for backgrounds saved without reference provenance, rerun with overwrite = TRUE.

References

Schep AN, Wu B, Buenrostro JD, Greenleaf WJ (2017). chromVAR: inferring transcription-factor-associated accessibility from single-cell epigenomic data. Nature Methods 14(10), 975-978. doi:10.1038/nmeth.4401

Wang J, Sonder E, Domcke S, Robinson MD, Germain P-L (2026). Addressing technical variations in ATAC-seq data and improving motif accessibility analyses. bioRxiv. doi:10.64898/2026.08.21.746151