stlearn.tl.clustering.louvain¶
-
stlearn.tl.clustering.louvain(adata: anndata._core.anndata.AnnData, resolution: Optional[float] = None, random_state: Union[int, numpy.random.mtrand.RandomState, None] = 0, restrict_to: Optional[Tuple[str, Sequence[str]]] = None, key_added: str = 'louvain', adjacency: Optional[scipy.sparse.base.spmatrix] = None, flavor: Literal[vtraag, igraph, rapids] = 'vtraag', directed: bool = True, use_weights: bool = False, partition_type: Optional[Type[louvain.VertexPartition.MutableVertexPartition]] = None, partition_kwargs: Mapping[str, Any] = mappingproxy({}), copy: bool = False) → Optional[anndata._core.anndata.AnnData]¶ Wrap function scanpy.tl.louvain Cluster cells into subgroups [Blondel08] [Levine15] [Traag17]. Cluster cells using the Louvain algorithm [Blondel08] in the implementation of [Traag17]. The Louvain algorithm has been proposed for single-cell analysis by [Levine15]. This requires having ran
neighbors()orbbknn()first, or explicitly passing aadjacencymatrix. :param adata: The annotated data matrix. :param resolution: For the default flavor ('vtraag'), you can provide a resolution(higher resolution means finding more and smaller clusters), which defaults to 1.0. See “Time as a resolution parameter” in [Lambiotte09].
- Parameters
random_state – Change the initialization of the optimization.
restrict_to – Restrict the clustering 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:
'louvain')adjacency – Sparse adjacency matrix of the graph, defaults to
adata.uns['neighbors']['connectivities'].flavor – Choose between to packages for computing the clustering.
'vtraag'is much more powerful, and the default.directed – Interpret the
adjacencymatrix as directed graph?use_weights – Use weights from knn graph.
partition_type – Type of partition to use. Only a valid argument if
flavoris'vtraag'.partition_kwargs – Key word arguments to pass to partitioning, if
vtraagmethod is being used.copy – Copy adata or modify it inplace.
- Returns
None– By default (copy=False), updatesadatawith the following fields:adata.obs['louvain'](pandas.Series, dtypecategory)Array of dim (number of samples) that stores the subgroup id (
'0','1', …) for each cell.AnnData– Whencopy=Trueis set, a copy ofadatawith those fields is returned.