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[tuple[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 (int | None) – Number of splits in which to divide the spatial coordinates in anndata.AnnData.obsm ['{spatial_key}'].

  • n_jobs (int | None) – Number of parallel jobs to use. For backend="loky", the number of cores used by numba for each job spawned by the backend will be set to 1 in order to overcome the oversubscription issue in case you run numba in your function to parallelize. To set the absolute maximum number of threads in numba for your python program, set the environment variable: NUMBA_NUM_THREADS before running the program.

  • 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[tuple[Any, ...], dtype[Any]], ndarray[tuple[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.