stlearn.tl.clustering.leiden¶
- stlearn.tl.clustering.leiden(adata: AnnData, resolution: float | None = None, random_state: int | RandomState | None = 0, restrict_to: tuple[str, Sequence[str]] | None = None, key_added: str = 'leiden', adjacency: spmatrix | None = None, directed: bool = False, use_weights: bool = False, partition_type: type[MutableVertexPartition] | None = None, obsp: str | None = None, copy: bool = False, flavor: Literal['leidenalg', 'igraph'] = 'igraph', n_iterations: int = 2) AnnData | None[source]¶
Wrap function scanpy.tl.leiden
This requires having ran
neighbors()orbbknn()first, or explicitly passing aadjacencymatrix.- Parameters:
adata – The annotated data matrix.
resolution – A parameter value controlling the coarseness of the clustering. Higher values lead to more clusters. Set to None if overriding partition_type to one that doesn’t accept a resolution_parameter.
random_state – Change the initialization of the optimization.
restrict_to – Restrict the cluster to the categories within the key for sample annotation, tuple needs to contain
(obs_key, list_of_categories).key_added – Key under which to add the cluster labels. (default:
'leiden')adjacency – Sparse adjacency matrix of the graph, defaults to
adata.uns['neighbors']['connectivities'].directed – Interpret the
adjacencymatrix as directed graph?use_weights – Use weights from knn graph.
partition_type – Type of partition to use. Defaults to
RBConfigurationVertexPartition. For the available options, consult the documentation forfind_partition().obsp – Use .obsp[obsp] as adjacency. You can’t specify both obsp and neighbors_key at the same time.
copy – Copy adata or modify it inplace.
flavor – Which package’s implementation to use.
n_iterations – How many iterations of the Leiden clustering algorithm to perform.
- Returns:
By default (
copy=False), updatesadatawith the following fields:adata.obs['leiden'](pandas.Series, dtypecategory) - Array of dim (number of samples) that stores the subgroup id ('0','1', …) for each cell.
When
copy=Trueis set, a copy ofadatawith those fields is returned.- Return type:
None or AnnData