scanpy.metrics.modularity#
- scanpy.metrics.modularity(adata_or_connectivities, /, labels='leiden', *, neighbors_key=None, is_directed=None, mode='calculate')[source]#
Compute the modularity of a graph given its connectivities and labels.
- Parameters:
- adata_or_connectivities
AnnData| AnyArrayLike |spmatrix|sparray The AnnData object containing the data or a weighted adjacency matrix representing the graph.
- labels
str| AnyArrayLike (default:'leiden') Cluster labels for each node in the graph. When
AnnDatais provided, this can be the key inadata.obsthat contains the clustering labels and defaults to"leiden".- neighbors_key
str|None(default:None) When
AnnDatais provided, the key inadata.obspthat contains the connectivities.- is_directed
bool|None(default:None) Whether the connectivities are directed or undirected. Always
FalseifAnnDatais provided, as connectivities are derived from (symmetric) neighbors.- mode
Literal['calculate','update','retrieve'] (default:'calculate') When
AnnDatais provided, this controls if the stored modularity is retrieved, or if we should calculate it (and optionally update it inadata.uns[labels]).
- adata_or_connectivities
- Return type:
- Returns:
The modularity of the graph based on the provided clustering.