squidpy.gr.co_occurrence(adata, cluster_key, spatial_key='spatial', n_steps=50, copy=False, n_splits=None, n_jobs=None, backend='loky', show_progress_bar=True)[source]

Compute co-occurrence probability of clusters.

The co-occurrence is computed across n_steps distance thresholds in spatial dimensions.

  • adata (AnnData) – Annotated data object.

  • cluster_key (str) – Key in anndata.AnnData.obs where clustering is stored.

  • spatial_key (str) – Key in anndata.AnnData.obsm where spatial coordinates are stored.

  • n_steps (int) – Number of distance thresholds at which co-occurrence is computed.

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

  • n_splits (Optional[int]) – Number of splits in which to divide the spatial coordinates in anndata.AnnData.obsm ['{spatial_key}'].

  • n_jobs (Optional[int]) – Number of parallel jobs.

  • 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

Optional[Tuple[ndarray, ndarray]]


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 n_steps.