Skip to contents

Computes diffusion-based imputation weights using the MAGIC algorithm (van Dijk et al., Cell 2018). Weights describe each cell as a linear combination of neighboring cells in reduced-dimension space, enabling smoothed visualization of sparse gene scores or accessibility signals.

Usage

add_impute_weights(
  proj,
  embedding_name = character(0),
  dims_to_use = NULL,
  td = 3L,
  ka = 4L,
  knn_method = knn_hnsw(k = 15L),
  epsilon = 1,
  sample_cells = 5000L,
  n_rep = 2L,
  seed = 1L,
  verbose = getOption("MarchR.verbose", FALSE)
)

Arguments

proj

(MarchRProject) Project containing a dimensionality reduction.

embedding_name

(character) Name of the dimensionality reduction to use (e.g., "IterativeLSI", "RNA_PCA"). Uses smart selection if not specified.

dims_to_use

(integer; optional) Which dimensions to use. Default is all available dimensions.

td

(integer) Diffusion time - number of matrix power iterations. Higher values produce more smoothing. Default is 3 (matching ArchR).

ka

(integer) Auto-tune parameter - normalize distances by the ka-th nearest neighbor distance to equalize effective neighborhood sizes across density variations. Default is 4.

knn_method

(function) BPCells KNN method. Default is knn_hnsw(k = 15L). Put KNN-specific arguments such as k, metric, or ef inside the partial function. See BPCells::knn_hnsw() and BPCells::knn_annoy().

epsilon

(numeric) Kernel bandwidth. Distances are transformed via exp(-(d/epsilon)^2). Set to 0 for unweighted KNN. Default is 1.

sample_cells

(integer; optional) Maximum block size for sub-sampling cells. If total cells exceed this, they are split into blocks for memory efficiency. Default is 5000. Set to NULL to use all cells in one block.

n_rep

(integer) Number of imputation replicates to average. Default is 2.

seed

(integer) Random seed. Default is 1.

verbose

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

Value

The MarchRProject with imputation weights stored in proj$impute_weights.

Details

ArchR correspondence: This function corresponds to ArchR's addImputeWeights(). MarchR uses BPCells KNN (knn_hnsw/knn_annoy) instead of nabor::knn()

See also

get_impute_weights for retrieving weights impute_matrix for applying imputation to a matrix BPCells::knn_hnsw, BPCells::knn_annoy for KNN methods