Skip to contents

Compute clusters for multiple resolutions and saves in the metadata the clustering result that reaches the maximum NMI and/or ARI value for a given cell-type label variable.

Usage

FindOptimalClusters(
  object,
  graph.name = NULL,
  cell.var = NULL,
  cluster.name = "{graph.name}_{cell.var}_{metric}",
  modularity.fxn = 1,
  initial.membership = NULL,
  node.sizes = NULL,
  resolutions = seq(from = 0.1, to = 2, by = 0.1),
  optimisation.metric = c("nmi", "ari"),
  method = "matrix",
  algorithm = 1,
  n.start = 10,
  n.iter = 10,
  random.seed = 0,
  group.singletons = TRUE,
  temp.file.location = NULL,
  edge.file.name = NULL,
  verbose = TRUE,
  ...
)

Arguments

object

a Seurat object

graph.name

the name of the knn graph to score.

cell.var

The name(s) of the column(s) with cell type label variable (must be in the object metadata). Multiple column names are accepted

cluster.name

a (optionally 'glue') string used as the new metadata column name (see Details section)

modularity.fxn

Modularity function (1 = standard; 2 = alternative).

initial.membership, node.sizes

Parameters to pass to the Python leidenalg function.

resolutions

the resolutions to compute clusters for

optimisation.metric

one of "nmi" or "ari" or both (default). The metric(s) to use to check clustering results against the cell.var.

method

Method for running leiden (defaults to matrix which is fast for small datasets). Enable method = "igraph" to avoid casting large data to a dense matrix.

algorithm

Algorithm for modularity optimization (1 = original Louvain algorithm; 2 = Louvain algorithm with multilevel refinement; 3 = SLM algorithm; 4 = Leiden algorithm). Leiden requires the leidenalg python.

n.start

Number of random starts.

n.iter

Maximal number of iterations per random start.

random.seed

Seed of the random number generator.

group.singletons

Group singletons into nearest cluster. If FALSE, assign all singletons to a "singleton" group

temp.file.location

Directory where intermediate files will be written. Specify the ABSOLUTE path.

edge.file.name

Edge file to use as input for modularity optimizer jar.

verbose

Print output

...

Arguments passed to other methods

Value

the updated seurat object with the new metadata column(s)

Details

cluster.name can use the 'glue' syntax to avoid overwriting metadata columns when multiple metrics and/or cell-type label variables are provided. But it can be ignored otherwise. Injectable variables are "graph.name", "cell.var" and "metric" (not "optimisation.metric"). They must be flanked by single curly brackets ("{" and "}").

For instance, if you prefer to name the clusters with an integration instead of the graph.name, don't use the glue syntax for it (e.g. "combat_{cell.var}_{metric}" would work, but any of "{combat}_{cell.var}_{metric}" or "{integration}_{cell.var}_{metric}" would throw an error)

References

Luecken, M. D., Büttner, M., Chaichoompu, K., Danese, A., Interlandi, M., Mueller, M. F., Strobl, D. C., Zappia, L., Dugas, M., Colomé-Tatché, M. & Theis, F. J. Benchmarking atlas-level data integration in single-cell genomics. Nat Methods 19, 41–50 (2021). DOI