Skip to contents

Graph-based clustering via BPCells::cluster_cells_graph() with ArchR-compatible post-processing: outlier reassignment, max-cluster merging, and hierarchical relabeling.

Usage

# Default S3 method
add_clusters(
  x,
  knn_method = knn_hnsw(k = 20L),
  knn_to_graph_method = knn_to_snn_graph,
  cluster_graph_method = cluster_graph_leiden(resolution = 0.8),
  n_outlier = 5L,
  max_clusters = 25L,
  prefix = "C",
  seed = 1L,
  threads = NULL,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

# S3 method for class 'MarchRProject'
add_clusters(
  x,
  embedding_name = character(0),
  dataset_names = character(0),
  col_name = "clusters",
  knn_method = knn_hnsw(k = 20L),
  knn_to_graph_method = knn_to_snn_graph,
  cluster_graph_method = cluster_graph_leiden(resolution = 0.8),
  n_outlier = 5L,
  max_clusters = 25L,
  prefix = "C",
  seed = 1L,
  overwrite = FALSE,
  threads = NULL,
  verbose = getOption("MarchR.verbose", FALSE),
  ...
)

Arguments

x

(MarchRProject) Project containing embedding assays.

knn_method

(function) KNN method. Default knn_hnsw(k = 20L).

knn_to_graph_method

(function) Graph construction. Default knn_to_snn_graph.

cluster_graph_method

(function) Graph clustering. Default cluster_graph_leiden(resolution = 0.8). Pass cluster_graph_seurat(resolution = 0.8) to use Seurat instead, which requires the optional Seurat package.

n_outlier

(integer) Minimum cluster size; smaller clusters are reassigned via KNN; errors if every cluster is smaller. Default 5.

max_clusters

(integer) Maximum clusters; excess merged via hierarchical clustering on centroids. Default 25. NULL to disable.

prefix

(character) Label prefix. Default "C".

seed

(integer) Random seed.

threads

(integer) Threads for the KNN search. Default runs single-threaded. Note that result is non-deterministic if threads > 1.

verbose

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

...

Additional arguments passed to specific methods.

embedding_name

(character) Embedding to cluster on. Auto-selected if only one exists.

dataset_names

(character) Datasets to include. Default all.

col_name

(character) Metadata column for labels. Default "clusters".

overwrite

(logical) Overwrite existing column.

Value

Named character vector of cluster labels.

Modified MarchRProject with cluster labels in cell metadata.

Details

Defaults follow ArchR's addClusters(): SNN graph with k=20 (FindNeighbors), resolution 0.8, outlier reassignment (nOutlier = 5), and max-cluster merging (maxClusters = 25).

ArchR clusters with Seurat::FindClusters(), whereas MarchR defaults to cluster_graph_leiden(), so that clustering works without the optional Seurat package. Leiden and Seurat's Louvain both optimize modularity and the resolution parameter is on a comparable scale, but labels are not identical. Pass cluster_graph_method = cluster_graph_seurat(resolution = 0.8) to reproduce ArchR exactly.

Depth-correlated dimensions are already filtered during IterativeLSI() / LSI() via corr_cutoff.

Methods (by class)

  • add_clusters(default): Cluster a cells x dimensions embedding matrix

  • add_clusters(MarchRProject): Cluster cells across datasets in a MarchRProject

See also