rapids_singlecell.gr.nhood_enrichment#

rapids_singlecell.gr.nhood_enrichment(adata, cluster_key, *, table_key=None, library_key=None, connectivity_key='spatial_connectivities', n_perms=1000, seed=None, copy=False)[source]#

Compute neighborhood enrichment by permutation test.

Counts the spatial graph edges between every pair of clusters and compares the counts with n_perms random permutations of the cluster labels. All permutations are counted on the GPU in batches. Cells whose cluster label is missing are removed together with their edges.

Parameters:
adata AnnData | SpatialData

Annotated data matrix or a SpatialData object containing the selected table.

cluster_key str

Key in anndata.AnnData.obs with categorical cluster labels.

table_key str | None (default: None)

Key in SpatialData.tables; required for SpatialData input. Ignored for AnnData input.

library_key str | None (default: None)

Key in anndata.AnnData.obs with categorical library labels. If given, cluster labels are only permuted within each library.

connectivity_key str (default: 'spatial_connectivities')

Key in anndata.AnnData.obsp with the spatial connectivity graph.

n_perms int (default: 1000)

Number of permutations for the permutation test.

seed int | None (default: None)

Random seed for the permutations.

copy bool (default: False)

If True, return the result instead of storing it.

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: