squidpy.gr.co_occurrence

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

Compute co-occurrence probability of clusters.

Parameters:
  • adata (AnnData | SpatialData) – 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.

  • interval (int | ndarray[Any, dtype[Any]]) – Distances interval at which co-occurrence is computed. If int, uniformly spaced interval of the given size will be used.

  • 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:

tuple[ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]]] | None

Returns:

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