scHopfield.tools.compute_network_centrality
- scHopfield.tools.compute_network_centrality(adata: AnnData, cluster_key: str = 'cell_type', threshold_number: int | None = 2000, weight: str = 'coef_abs', use_igraph: bool = True, copy: bool = False) AnnData | None[source]
Compute network centrality metrics for genes in each cluster.
Uses igraph (fast C implementation) by default, with NetworkX as fallback. Filters network edges before computing centrality for better performance.
- Parameters:
adata (AnnData) – Annotated data object with fitted interaction matrices
cluster_key (str, optional (default: 'cell_type')) – Key in adata.obs for cluster labels
threshold_number (int, optional (default: 2000)) – Maximum number of edges to keep per cluster (top edges by weight). Set to None to use all edges (slower).
weight (str, optional (default: 'coef_abs')) – Weight column to use for filtering: ‘coef_abs’ or ‘coef_mean’
use_igraph (bool, optional (default: True)) – Use igraph library if available (much faster than NetworkX). Falls back to NetworkX if igraph is not installed.
copy (bool, optional (default: False)) – If True, return a copy instead of modifying in-place
- Returns:
Returns adata if copy=True, otherwise None. Adds to adata.var for each cluster: - ‘degree_all_{cluster}’: total degree - ‘degree_centrality_all_{cluster}’: normalized total degree - ‘degree_in_{cluster}’: in-degree - ‘degree_centrality_in_{cluster}’: normalized in-degree - ‘degree_out_{cluster}’: out-degree - ‘degree_centrality_out_{cluster}’: normalized out-degree - ‘betweenness_centrality_{cluster}’: betweenness centrality - ‘eigenvector_centrality_{cluster}’: eigenvector centrality
- Return type:
AnnData or None
Notes
This implementation is based on CellOracle’s approach for efficiency. Edge filtering significantly speeds up computation for large networks.