squidpy.gr.nhood_enrichment

squidpy.gr.nhood_enrichment(adata, cluster_key, library_key=None, connectivity_key=None, n_perms=1000, numba_parallel=False, seed=None, copy=False, n_jobs=None, backend='loky', show_progress_bar=True)[source]

Compute neighborhood enrichment by permutation test.

Parameters:
  • adata (AnnData | SpatialData) – Annotated data object.

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

  • library_key (str | None) – If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

  • connectivity_key (str | None) – Key in anndata.AnnData.obsp where spatial connectivities are stored. Default is: anndata.AnnData.obsp ['spatial_connectivities'].

  • n_perms (int) – Number of permutations for the permutation test.

  • numba_parallel (bool) – Whether to use numba.prange() or not. If None, it is determined automatically. For small datasets or small number of interactions, it’s recommended to set this to False.

  • seed (int | None) – Random seed for reproducibility.

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

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

NhoodEnrichmentResult | None

Returns:

If copy = True, returns a NhoodEnrichmentResult with the z-score and the enrichment count.

Otherwise, modifies the adata with the following keys: