Skip to contents

Compute peak-to-gene links

Usage

add_peak2gene_links(proj, ...)

# S3 method for class 'MarchRProject'
add_peak2gene_links(
  proj,
  embedding_name = character(0),
  atac_assay_name = "PeakMatrix",
  use_matrix = "GeneIntegrationMatrix",
  dataset_names = character(0),
  dims_to_use = 1:30,
  cells_to_use = NULL,
  exclude_chr = NULL,
  k = 100L,
  knn_iteration = 500L,
  overlap_cutoff = 0.8,
  max_dist = 250000L,
  scale_to = 10000,
  log2_norm = TRUE,
  prediction_cutoff = 0.4,
  add_empirical_pval = FALSE,
  add_permuted_pval = FALSE,
  n_perm = 100L,
  knn_method = knn_hnsw(),
  seed = 1L,
  verbose = getOption("MarchR.verbose", FALSE),
  overwrite = FALSE,
  ...
)

Arguments

proj

(MarchRProject) Project with a PeakMatrix, a gene expression matrix, and a dim reduction.

...

Additional arguments passed to methods.

embedding_name

(character) Dim reduction assay name; auto-selected if only one exists.

atac_assay_name

(character) Peak matrix assay name. Default "PeakMatrix".

use_matrix

(character) Gene expression/integration assay name. Default "GeneIntegrationMatrix".

dataset_names

(character) Datasets to include. Default all.

dims_to_use

(integer) Embedding dimensions to use. Default 1:30.

cells_to_use

(character; optional) Cell subset. Default NULL (all cells).

exclude_chr

(character; optional) Chromosomes to skip. Default NULL.

k

(integer) Cells per metacell. Default 100L.

knn_iteration

(integer) Anchor cells sampled. Default 500L.

overlap_cutoff

(numeric) Max fractional overlap between accepted metacells. Default 0.8.

max_dist

(integer) Max peak-to-TSS distance in bp for a candidate pair. Default 250000L.

scale_to

(numeric) Per-metacell depth normalization target. Default 1e4.

log2_norm

(logical) Apply log2(x + 1) after depth normalization. Default TRUE.

prediction_cutoff

(numeric) Minimum predictedScore cell-metadata value to keep a cell. Default 0.4.

add_empirical_pval

(logical) Add EmpPval/EmpFDR from a trans-chromosome null correlation background. Default FALSE.

add_permuted_pval

(logical) Add PermPval/PermFDR from column-shuffled correlation permutations. Default FALSE.

n_perm

(integer) Permutations for add_permuted_pval. Default 100L.

knn_method

(function) KNN engine (BPCells partial-application). Default knn_hnsw().

seed

(integer) Random seed for metacell sampling and p-value resampling. Default 1L.

verbose

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

overwrite

(logical) Replace an existing peak2gene_links result. Default FALSE.

Value

proj with proj$peak2gene_links populated as a data.frame with columns idxATAC (row index into proj$peak_set), idxRNA (row index into attr(proj$peak2gene_links, "geneSet")), Correlation, TStat, Pval, FDR, VarQATAC, VarQRNA, distance, and, when requested, EmpPval/EmpFDR and/or PermPval/PermFDR.

Details

Reproduces ArchR's addPeak2GeneLinks(): cells are grouped into low-overlap KNN metacells built from a dim reduction, peak and gene matrices are aggregated over the same metacells and depth-normalized, and Pearson correlation is computed for every peak-gene pair whose peak summit falls within max_dist of the gene's TSS.

add_empirical_pval reproduces ArchR's .getNullCorrelations(): for each chromosome represented among the candidate peaks, up to 1000 peaks on a different chromosome are sampled and correlated against every gene paired with a peak on that chromosome; the pooled null correlations give a mean/sd used to convert each observed correlation to a two-sided normal p-value (EmpPval), BH-adjusted into EmpFDR.

add_permuted_pval reproduces ArchR's Regner et al. 2021-style permutation p-value: n_perm column permutations of the aggregated ATAC metacell matrix are each correlated against the unpermuted RNA matrix for every observed pair, and the resulting p-values are averaged into PermPval. PermFDR compares the empirical CDF of PermPval and of the observed Pval, each evaluated at Pval, matching ArchR's pmin(ecdf(PermPval)(Pval) / ecdf(Pval)(Pval), 1).

Two deviations from ArchR: (a) the permuted t-statistic is computed through the shared correlation helper, which floors the denominator at pmax(1 - r^2, 1e-17); ArchR omits this floor in its permutation branch, so results differ only at |r| == 1, unreachable with real depth-normalized data. (b) Zero-variance features contribute a correlation of 0 to the null pool, whereas ArchR drops their NaN correlations via na.omit; this matters only when many features have literally zero variance across metacells.