rapids_singlecell.tl.leiden#
- rapids_singlecell.tl.leiden(adata, resolution=1.0, *, random_state=0, theta=1.0, restrict_to=None, key_added='leiden', adjacency=None, n_iterations=100, use_weights=True, neighbors_key=None, obsp=None, dtype=<class 'numpy.float32'>, use_dask=False, copy=False)[source]#
Cluster cells into subgroups using the Leiden algorithm [TWvE19].
Performs Leiden clustering using cuGraph, an improved version of the Louvain algorithm [BGLL08].
- Parameters:
- adata AnnData
annData object
- resolution float | list[float] (default:
1.0) A parameter value or a list of parameter values controlling the coarseness of the clustering. (called gamma in the modularity formula). Higher values lead to more clusters. If a list of values is provided, the Leiden algorithm will be run for each value in the list.
- random_state int | None (default:
0) Change the initialization of the optimization. Defaults to 0.
- theta float (default:
1.0) Called theta in the Leiden algorithm, this is used to scale modularity gain in Leiden refinement phase, to compute the probability of joining a random leiden community.
- 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.obskey under which to add the cluster labels.- adjacency sparse.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,
leidenlooks at.obsp['connectivities']for neighbors connectivities. If specified,leidenlooks 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
obspandneighbors_keyat the same time.- dtype str | np.dtype | cp.dtype (default:
<class 'numpy.float32'>) Data type to use for the adjacency matrix.
- use_dask bool (default:
False) If
True, use Dask to create the graph and cluster. This will use all GPUs available. This feature is experimental. For datasets with less than 10 Million cells, it is recommended to useuse_dask=False.- copy bool (default:
False) Whether to copy
adataor modify it in place.
- Return type:
AnnData | None