squidpy.gr.nhood_enrichment
- squidpy.gr.nhood_enrichment(adata, cluster_key, library_key=None, connectivity_key=None, n_perms=1000, numba_parallel=False, rng=None, copy=False, n_jobs=None, backend='loky', show_progress_bar=True, *, table_key=None)[source]
Compute neighborhood enrichment by permutation test.
Changed in version 1.8.4: Every permutation now uses an independent
numpy.random.Generatorspawned from anumpy.random.SeedSequence. Consequently the permutation-based results no longer depend onn_jobs/backend, but results obtained with a given seed differ from those produced by squidpy < 1.8.4. See #1232 and #1233.Changed in version 1.8.4:
seed/random_statewere renamed torng, which also accepts anumpy.random.Generator(SPEC 7). The old names still work but emit aFutureWarning.- Parameters:
adata (
AnnData|SpatialData) – Annotated data object.table_key (
str|None) – Key inspatialdata.SpatialData.tableswhere the table is stored. Required whenadatais aspatialdata.SpatialDataobject and ignored otherwise.cluster_key (
str) – Key inanndata.AnnData.obswhere clustering is stored.library_key (
str|None) – If multiple library_id, column inanndata.AnnData.obswhich stores mapping betweenlibrary_idand obs.connectivity_key (
str|None) – Key inanndata.AnnData.obspwhere 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 usenumba.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.rng (
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None) –Pseudorandom number generator state, following SPEC 7. When None, a new
numpy.random.Generatoris created using entropy from the operating system. Types other thannumpy.random.Generatorare passed tonumpy.random.default_rng()to instantiate a generator.copy (
bool) – IfTrue, return the result, otherwise save it to theadataobject.n_jobs (
int|None) – Number of parallel jobs to use. None is serial and-1uses all available cores; asking for more cores than are available warns and falls back to all of them, while0and values below-1raise, since scanpy only supportsn_jobs >= -1. Forbackend="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_THREADSbefore running the program.backend (
str) – Parallelization backend to use. Seejoblib.Parallelfor available options.show_progress_bar (
bool) – Whether to show the progress bar or not.
- Return type:
- Returns:
If
copy = True, returns aNhoodEnrichmentResultwith the z-score and the enrichment count.Otherwise, modifies the
adatawith the following keys:anndata.AnnData.uns['{cluster_key}_nhood_enrichment']['zscore']- the enrichment z-score.anndata.AnnData.uns['{cluster_key}_nhood_enrichment']['count']- the enrichment count.