rapids_singlecell.gr.calculate_niche#
- rapids_singlecell.gr.calculate_niche(adata, *, table_key=None, flavor, groups=None, n_neighbors=15, resolutions=None, distance=None, n_hop_weights=None, abs_nhood=False, scale=True, min_niche_size=None, mask=None, library_key=None, aggregation='mean', n_components=10, use_rep=None, spatial_connectivities_key='spatial_connectivities', random_state=42, inplace=True, copy=None, **kwargs)[source]#
Compute spatial niches on the GPU.
Deprecated since version 0.17.0:
calculate_nicheis deprecated and will be removed in a future release, followingsquidpy. Use the flavor-specific functions instead:Deprecated since version 0.17.0: Use
calculate_niche_neighborhood,calculate_niche_utag, orcalculate_niche_cellcharterinstead.The spatial graph in
adata.obsp[spatial_connectivities_key]must be precomputed (e.g. viaspatial_neighbors_knn()), except forflavor="cellcharter"whenuse_repis provided.- 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.- flavor
Literal['neighborhood','utag','cellcharter'] - groups
str|None(default:None) Column in
adata.obswith cell-type labels. Required forflavor="neighborhood".- n_neighbors
int(default:15) Neighbors for the post-aggregation kNN graph passed to leiden.
- resolutions
float|Sequence[float] |None(default:None) Resolution(s) for leiden, defaulting to
(0.5,). A label column is written for each value. Ignored forflavor="cellcharter".- distance
int|None(default:None) Number of n-hop neighborhoods to include. Defaults to 3 for
cellcharter, 1 forneighborhood.- n_hop_weights
Sequence[float] |None(default:None) Per-hop weights when
distance > 1(flavor="neighborhood"only).- abs_nhood
bool(default:False) Use absolute neighbor counts instead of per-cell relative frequencies (
flavor="neighborhood"only).- scale
bool(default:True) Z-score the neighborhood profile before clustering (
flavor="neighborhood"only).- 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>_.- aggregation
Literal['mean','variance'] (default:'mean') Per-shell aggregation for
flavor="cellcharter"."mean"(default) or"variance".- n_components
int(default:10) Number of mixture components for
flavor="cellcharter".- use_rep
str|None(default:None) Key in
adata.obsmto use as the embedding forflavor="cellcharter"; if provided, the firstn_componentscolumns are used and the shell-aggregation + PCA step is skipped.- spatial_connectivities_key
str(default:'spatial_connectivities') Key in
adata.obspwith the spatial connectivity matrix. Not used forflavor="cellcharter"whenuse_repis provided.- random_state
int(default:42) Random seed for the GMM (
flavor="cellcharter"only).- inplace
bool(default:True) Write the niche columns to
adata(the selected table for SpatialData). IfFalse, return a modified AnnData copy of that table.- copy
bool|None(default:None) Deprecated alias for
inplace;copy=Trueisinplace=False.- kwargs
Accepts the removed
gmm_initargument, which is ignored with a warning.
- adata
- Return type: