centrality_scores

centrality_scores#

squidpy.gr.centrality_scores(adata, *, cluster_key, score=None, connectivity_key=None, copy=False, n_jobs=None, show_progress_bar=False, table_key=None)[source]#

Compute centrality scores per cluster or cell type.

Inspired by usage in Gene Regulatory Networks (GRNs) in [Kamimoto et al., 2020].

Changed in version 1.8.4: The scores run on numba threads, and n_jobs = None now uses all NUMBA_NUM_THREADS threads instead of one process. Pass n_jobs = 1 for the old serial default.

Parameters:
adata AnnData | SpatialData

Annotated data object.

table_key str | None (default: None)

Key in spatialdata.SpatialData.tables where the table is stored. Required when adata is a spatialdata.SpatialData object and ignored otherwise.

cluster_key str

Key in anndata.AnnData.obs where clustering is stored.

score Literal['degree_centrality', 'average_clustering', 'closeness_centrality'] | Sequence[Literal['degree_centrality', 'average_clustering', 'closeness_centrality']] | None (default: None)

Group centrality measures as described in networkx.algorithms.centrality [Hagberg et al., 2008]. If None, use all the options below. Valid options are:

  • ’closeness_centrality’ - measure of how close the group is to other nodes.

  • ’average_clustering’ - measure of the degree to which nodes cluster together.

  • ’degree_centrality’ - fraction of non-group members connected to group members.

connectivity_key str | None (default: None)

Key in anndata.AnnData.obsp where spatial connectivities are stored. Default is: anndata.AnnData.obsp ['spatial_connectivities'].

copy bool (default: False)

If True, return the result, otherwise save it to the adata object.

n_jobs int | None (default: None)

Number of parallel threads to use. None and -1 use numba’s default thread count (NUMBA_NUM_THREADS); asking for more threads than that warns and falls back to it, while 0 and values below -1 raise, since scanpy only supports n_jobs >= -1.

show_progress_bar bool (default: False)

Whether to show the progress bar or not.

Returns:

DataFrame | None – If copy = True, returns a pandas.DataFrame. Otherwise, modifies the adata with the following key:

  • anndata.AnnData.uns ['{cluster_key}_centrality_scores'] - the centrality scores, as mentioned above.