Skip to contents

Computes a UMAP (Uniform Manifold Approximation and Projection) embedding from a previously computed dimensionality reduction (e.g. LSI, PCA, Harmony) and stores the result in cell metadata. Uses the uwot package.

Usage

# Default S3 method
add_umap(
  x,
  n_neighbors = 40L,
  min_dist = 0.4,
  metric = "cosine",
  n_components = 2L,
  seed = 1L,
  batch = TRUE,
  threads = get_threads(),
  verbose = getOption("MarchR.verbose", FALSE),
  umap_params = list(),
  return_model = FALSE,
  ...
)

# S3 method for class 'MarchRDataset'
add_umap(
  x,
  embedding_name = character(0),
  output_assay_name = "UMAP",
  n_neighbors = 40L,
  min_dist = 0.4,
  metric = "cosine",
  n_components = 2L,
  seed = 1L,
  batch = TRUE,
  store_as_matrix = FALSE,
  overwrite = FALSE,
  threads = get_threads(),
  verbose = getOption("MarchR.verbose", FALSE),
  umap_params = list(),
  ...
)

# S3 method for class 'MarchRProject'
add_umap(
  x,
  embedding_name = character(0),
  dataset_names = character(0),
  output_assay_name = "UMAP",
  n_neighbors = 40L,
  min_dist = 0.4,
  metric = "cosine",
  n_components = 2L,
  seed = 1L,
  batch = TRUE,
  store_as_matrix = FALSE,
  overwrite = FALSE,
  threads = get_threads(),
  verbose = getOption("MarchR.verbose", FALSE),
  umap_params = list(),
  return_model = TRUE,
  ...
)

Arguments

x

(MarchRProject) Project containing embedding assays.

n_neighbors

(integer) Number of nearest neighbors for UMAP. Default is 40 (matching ArchR).

min_dist

(numeric) Minimum distance parameter for UMAP. Default is 0.4 (matching ArchR).

metric

(character) Distance metric. Default is "cosine" (matching ArchR). See uwot::umap2() for available metrics.

n_components

(integer) Number of UMAP dimensions. Default is 2.

seed

(integer) Random seed for reproducibility.

batch

(logical) Use uwot's deterministic batch optimization. Default TRUE.

threads

(integer) Number of threads.

verbose

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

umap_params

(list) Additional parameters passed to uwot::umap2(). These override any other arguments when there is a conflict.

return_model

(logical) For matrix inputs, return the fitted uwot transform model and effective parameters with the coordinates. For MarchRProject inputs, persist and register the model in the project. Defaults to FALSE for matrices and TRUE for projects.

...

Additional arguments passed to specific methods.

embedding_name

(character) Name of the embedding assay to use as input (e.g. "PCA", "LSI", "Harmony"). Auto-selected if only one dimensionality reduction exists.

output_assay_name

(character) Prefix for the output columns stored in cell metadata. Default is "UMAP", producing columns UMAP_1, UMAP_2, etc. Also used as the assay name when store_as_matrix = TRUE.

store_as_matrix

(logical) If TRUE, also store the UMAP coordinates as IterableMatrix assays in addition to cell metadata. Default is FALSE.

overwrite

(logical) If TRUE, overwrite existing metadata columns or assays.

dataset_names

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

Value

A matrix of UMAP coordinates (cells x n_components) with rownames as cell names and colnames as UMAP_1, UMAP_2, etc.

The modified MarchRDataset with UMAP coordinates added as cell metadata columns (and optionally as a matrix assay).

The modified MarchRProject with UMAP coordinates added as cell metadata columns (and optionally as matrix assays) in each dataset.

Details

UMAP is computed on a cells x dimensions dense matrix extracted from a stored embedding assay (e.g. PCA or LSI output). The result is a 2D (or n_components-dimensional) embedding stored as columns in cell metadata (e.g. UMAP_1, UMAP_2). Optionally, the embedding can also be stored as a matrix assay by setting store_as_matrix = TRUE.

The backend is uwot::umap2(), which uses RcppHNSW, multithreading optimizations and defaults closer to the Python UMAP implementation. Results will slightly differ from ArchR's addUMAP() as a result.

The MarchRProject method extracts the joint embedding across all selected datasets, computes UMAP on the concatenated embedding (so coordinates are comparable across datasets), then distributes results back to each dataset as cell metadata columns. By default, the exact transformable uwot model is persisted in the project directory and registered at project level. Set return_model = FALSE to store coordinates without the transform. When store_as_matrix = TRUE, the coordinates are additionally stored as matrix assays.

Methods (by class)

  • add_umap(default): Compute UMAP on a cells x dimensions matrix

  • add_umap(MarchRDataset): Compute UMAP for a MarchRDataset and store in cell metadata

  • add_umap(MarchRProject): Compute UMAP for a MarchRProject and store in cell metadata

ArchR correspondence

This function is analogous to ArchR's addUMAP(). ArchR defaults: nNeighbors = 40, minDist = 0.4, metric = "cosine". MarchR defaults match these values.