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
groupslabels among its spatial neighbors; the profiles are then clustered with leiden. Mirrorssquidpy.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.obswith 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.obspwith 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
Seriesindexed likeadata.obs. Cells that areFalseare labeled"not_a_niche".- library_key
str|None(default:None) Column in
adata.obsidentifying samples. If given, niches are computed per sample and labels are prefixed withlib=<id>_.- inplace
bool(default:True) Write the niche columns to
adata(the selected table for SpatialData). IfFalse, return a modified AnnData copy of that table.
- adata
- Return type: