rapids_singlecell.gr.calculate_niche_neighborhood#

rapids_singlecell.gr.calculate_niche_neighborhood(adata, *, table_key=None, groups, resolutions, n_neighbors=15, spatial_connectivities_key='spatial_connectivities', scale=True, distance=1, abs_nhood=False, n_hop_weights=None, min_niche_size=None, mask=None, library_key=None, inplace=True)[source]#

Compute spatial niches from cell-type neighborhood profiles on the GPU.

Each cell is described by the frequency of groups labels among its spatial neighbors; the profiles are then clustered with leiden. Mirrors squidpy.gr.calculate_niche_neighborhood [B+23].

Labels are written to adata.obs['nhood_niche_res=<res>'].

Parameters:
adata AnnData | SpatialData

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

table_key str | None (default: None)

Key in SpatialData.tables; required for SpatialData input. All reads and writes use this table; ignored for AnnData input.

groups str

Column in adata.obs with cell-type labels.

resolutions float | Sequence[float]

Resolution(s) for leiden. A label column is written for each value.

n_neighbors int (default: 15)

Neighbors for the post-aggregation kNN graph passed to leiden.

spatial_connectivities_key str (default: 'spatial_connectivities')

Key in adata.obsp with the spatial connectivity matrix.

scale bool (default: True)

Z-score the neighborhood profile before clustering.

distance int (default: 1)

Number of n-hop neighborhoods to include.

abs_nhood bool (default: False)

Use absolute neighbor counts instead of per-cell relative frequencies.

n_hop_weights Sequence[float] | None (default: None)

Per-hop weights when distance > 1.

min_niche_size int | None (default: None)

Discard niches with fewer cells than this; relabel as "not_a_niche".

mask Series | None (default: None)

Boolean Series indexed like adata.obs. Cells that are False are labeled "not_a_niche".

library_key str | None (default: None)

Column in adata.obs identifying samples. If given, niches are computed per sample and labels are prefixed with lib=<id>_.

inplace bool (default: True)

Write the niche columns to adata (the selected table for SpatialData). If False, return a modified AnnData copy of that table.

Return type:

AnnData | None