rapids_singlecell.tl.leiden#
- rapids_singlecell.tl.leiden(adata, resolution=1.0, *, random_state=0, restrict_to=None, key_added='leiden', adjacency=None, n_iterations=100, use_weights=True, neighbors_key=None, obsp=None, copy=False)[source]#
Performs Leiden clustering using cuGraph, which implements the method described in:
Traag, V.A., Waltman, L., & van Eck, N.J. (2019). From Louvain to Leiden: guaranteeing well-connected communities. Sci. Rep., 9(1), 5233. DOI: 10.1038/s41598-019-41695-z
- Parameters:
- adata
AnnData
annData object
- resolution
float
(default:1.0
) A parameter value controlling the coarseness of the clustering. (called gamma in the modularity formula). Higher values lead to more clusters.
- random_state
int
|None
(default:0
) Change the initialization of the optimization. Defaults to 0.
- 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:'leiden'
) adata.obs
key under which to add the cluster labels.- adjacency
spmatrix
|None
(default:None
) Sparse adjacency matrix of the graph, defaults to neighbors connectivities.
- n_iterations
int
(default:100
) This controls the maximum number of levels/iterations of the Leiden algorithm. When specified, the algorithm will terminate after no more than the specified number of iterations. No error occurs when the algorithm terminates early in this manner.
- use_weights
bool
(default:True
) If
True
, edge weights from the graph are used in the computation (placing more emphasis on stronger edges).- neighbors_key
str
|None
(default:None
) If not specified,
leiden
looks at.obsp['connectivities']
for neighbors connectivities. If specified,leiden
looks at.obsp[.uns[neighbors_key]['connectivities_key']]
for neighbors connectivities.- obsp
str
|None
(default:None
) Use .obsp[obsp] as adjacency. You can’t specify both
obsp
andneighbors_key
at the same time.- copy
bool
(default:False
) Whether to copy
adata
or modify it in place.
- adata
- Return type: