napari_prism.gr.proximity_density#
- napari_prism.gr.proximity_density(adata, grouping, phenotype, pairs=None, connectivity_key='spatial_connectivities', multi_index=False, inplace=True, n_jobs=4)#
Computes proximity density from scimap’s p-score function compatible with squidpy-generated .obsp spatial graphs. By default, stores the results inplace.
Proximity density is defined as the number of cells of a given pair of phenotypes being in proximity of one another, divided by the total number of cells.
The definition of proximity depends on the adjacency matrix computed via squidpy.gr.spatial_neighbors. To stay true to the original definition of proximity density, the adjacency matrix should be a radial graph of a given radius in um.
- Parameters:
adata (
AnnData) – AnnData object.grouping (
str) – Column name in adata.obs to group by.phenotype (
str) – Column name in adata.obs to compute proximity for.pairs (
Optional[list[tuple[str,str]]] (default:None)) – List of tuples of phenotype pairs to compute proximity for. If None, computes proximity for all unique phenotype pairs.connectivity_key (
str(default:'spatial_connectivities')) – Key for the adjacency matrix in adata.obsp.multi_index (
bool(default:False)) – If True, returns a multi-indexed DataFrame.inplace (
bool(default:True)) – If True, stores the results in adata.uns.
- Return type:
- Returns:
If inplace is False, returns a tuple of three dataframes, the first containing the proximity density results, the second containing the masks for missing values, and the third containing the cell counts for each pair of phenotypes.