squidpy.gr.centrality_scores

squidpy.gr.centrality_scores(adata, cluster_key, score=None, connectivity_key=None, copy=False, n_jobs=None, backend='loky', 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].

Parameters:
  • adata (AnnData | SpatialData) – Annotated data object.

  • table_key (str | 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 (str | Iterable[str] | None) –

    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) – Key in anndata.AnnData.obsp where spatial connectivities are stored. Default is: anndata.AnnData.obsp ['spatial_connectivities'].

  • copy (bool) – If True, return the result, otherwise save it to the adata object.

  • n_jobs (int | None) – Number of parallel jobs to use. For backend="loky", the number of cores used by numba for each job spawned by the backend will be set to 1 in order to overcome the oversubscription issue in case you run numba in your function to parallelize. To set the absolute maximum number of threads in numba for your python program, set the environment variable: NUMBA_NUM_THREADS before running the program.

  • backend (str) – Parallelization backend to use. See joblib.Parallel for available options.

  • show_progress_bar (bool) – Whether to show the progress bar or not.

Return type:

DataFrame | None

Returns:

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.