co_occurrence

co_occurrence#

squidpy.gr.co_occurrence(adata, *, cluster_key, spatial_key='spatial', interval=50, copy=False, table_key=None)[source]#

Compute co-occurrence probability of clusters.

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.

spatial_key str (default: 'spatial')

Key in anndata.AnnData.obsm where spatial coordinates are stored.

interval int | NDArray[Any] (default: 50)

Distances interval at which co-occurrence is computed. If int, uniformly spaced interval of the given size will be used.

copy bool (default: False)

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

Returns:

tuple[NDArray[Any], NDArray[Any]] | None – If copy = True, returns the co-occurrence probability and the distance thresholds intervals.

Otherwise, modifies the adata with the following keys:

  • anndata.AnnData.uns ['{cluster_key}_co_occurrence']['occ'] - the co-occurrence probabilities across interval thresholds.

  • anndata.AnnData.uns ['{cluster_key}_co_occurrence']['interval'] - the distance thresholds computed at interval.