scanpy.tl.louvain#
- scanpy.tl.louvain(adata, resolution=None, *, random_state=0, restrict_to=None, key_added='louvain', adjacency=None, flavor='vtraag', directed=True, use_weights=False, partition_type=None, partition_kwargs=mappingproxy({}), neighbors_key=None, obsp=None, copy=False)[source]#
Cluster cells into subgroups [Blondel et al., 2008, Levine et al., 2015, Traag, 2015].
Deprecated since version 1.12.0: Use
scanpy.tl.leiden()instead.Cluster cells using the Louvain algorithm [Blondel et al., 2008] in the implementation of Traag [2015]. The Louvain algorithm was proposed for single-cell analysis by Levine et al. [2015].
This requires having run
neighbors()orbbknn()first, or explicitly passing aadjacencymatrix.- Parameters:
- adata
AnnData The annotated data matrix.
- resolution
float|None(default:None) For the default flavor (
'vtraag') or for`RAPIDS`, 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 Lambiotte et al. [2014].- random_state
int|RandomState|None(default:0) Change the initialization of the optimization.
- restrict_to
tuple[str,Sequence[str]] |None(default:None) Restrict the clustering to the categories within the key for sample annotation, tuple needs to contain
(obs_key, list_of_categories).- key_added
str(default:'louvain') Key under which to add the cluster labels. (default:
'louvain')- adjacency
csr_array|csc_array|csr_matrix|csc_matrix|None(default:None) Sparse adjacency matrix of the graph, defaults to neighbors connectivities.
- flavor
Literal['vtraag','igraph','rapids'] (default:'vtraag') Choose between to packages for computing the clustering.
'vtraag'Much more powerful than
'igraph', and the default.'igraph'Built in
igraphmethod.'rapids'GPU accelerated implementation.
Deprecated since version 1.10.0: Use
rapids_singlecell.tl.louvain()instead.
- directed
bool(default:True) Interpret the
adjacencymatrix as directed graph?- use_weights
bool(default:False) Use weights from knn graph.
- partition_type
type[MutableVertexPartition] |None(default:None) Type of partition to use. Only a valid argument if
flavoris'vtraag'.- partition_kwargs
Mapping[str,Any] (default:mappingproxy({})) Key word arguments to pass to partitioning, if
vtraagmethod is being used.- neighbors_key
str|None(default:None) Use neighbors connectivities as adjacency. If not specified, louvain looks .obsp[‘connectivities’] for connectivities (default storage place for pp.neighbors). If specified, louvain looks .obsp[.uns[neighbors_key][‘connectivities_key’]] for connectivities.
- obsp
str|None(default:None) Use .obsp[obsp] as adjacency. You can’t specify both
obspandneighbors_keyat the same time.- copy
bool(default:False) Copy adata or modify it inplace.
- adata
- Return type:
- Returns:
Returns
Noneifcopy=False, else returns anAnnDataobject. Sets the following fields:adata.obs['louvain' | key_added]pandas.Series(dtypecategory)Array of dim (number of samples) that stores the subgroup id (
'0','1', …) for each cell.adata.uns['louvain' | key_added]['params']dictA dict with the values for the parameters
resolution,random_state, andn_iterations.