rapids_singlecell.gr.calculate_niche_cellcharter#

rapids_singlecell.gr.calculate_niche_cellcharter(adata, *, table_key=None, distance=3, aggregation='mean', random_state=42, spatial_connectivities_key='spatial_connectivities', n_components=10, use_rep=None, min_niche_size=None, mask=None, library_key=None, inplace=True)[source]#

Compute spatial niches with the CellCharter approach on the GPU.

Expression is shell-aggregated over n-hop neighborhoods, PCA-reduced and clustered with a Gaussian mixture. Mirrors squidpy.gr.calculate_niche_cellcharter [VTSM+24].

Labels are written to adata.obs['cellcharter_niche'].

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.

distance int (default: 3)

Number of n-hop neighborhoods to include.

aggregation Literal['mean', 'variance'] (default: 'mean')

Per-shell aggregation. "mean" (default) or "variance".

random_state int (default: 42)

Random seed for the GMM.

spatial_connectivities_key str (default: 'spatial_connectivities')

Key in adata.obsp with the spatial connectivity matrix. Not used when use_rep is provided.

n_components int (default: 10)

Number of mixture components.

use_rep str | None (default: None)

Key in adata.obsm to use as the embedding; if provided, the first n_components columns are used and the shell-aggregation + PCA step is skipped.

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