nichesphere.coloc.compute_sc_spatial_radius_coloc_matrix

nichesphere.coloc.compute_sc_spatial_radius_coloc_matrix#

nichesphere.coloc.compute_sc_spatial_radius_coloc_matrix(adata, cluster_col, radius=40.0)#

Compute a radius-based co-localization probability matrix between cell type pairs.

For each cell, all neighbors within a fixed spatial radius are identified. Interaction counts are symmetrized (so that A→B and B→A are treated equally) and normalized to obtain interaction probabilities.

Parameters:
  • adata (anndata.AnnData) – Spatial AnnData object. Must contain cell centroid coordinates in adata.obsm['spatial'] and a categorical cluster annotation column in adata.obs.

  • cluster_col (str) – Name of the categorical column in adata.obs containing cluster labels.

  • radius (float, default 40.0) – Spatial radius within which two cells are considered co-localized. Units match those of adata.obsm['spatial'] (e.g. pixels or micrometers).

Returns:

Symmetric co-localization probability matrix of shape (n_clusters, n_clusters). Entry (i, j) is the symmetrized probability of finding cluster j within radius of cluster i, normalized so that all entries sum to 1.

Return type:

pd.DataFrame

Notes

The cluster_col column must be of dtype category; cluster order follows adata.obs[cluster_col].cat.categories.

Unlike compute_sc_spatial_knn_coloc_matrix, this function uses a fixed spatial radius rather than a fixed number of neighbors, making it more suitable for datasets where cell density varies across the tissue.

Examples

>>> coloc = compute_sc_spatial_radius_coloc_matrix(adata, cluster_col='cell_type', radius=300.0)
>>> sns.heatmap(coloc, cmap='Blues')