squidpy.gr.calculate_niche_spatialleiden
- squidpy.gr.calculate_niche_spatialleiden(data, *, resolutions, latent_connectivities_key='connectivities', spatial_connectivities_key='spatial_connectivities', layer_ratio=1.0, n_iterations=-1, use_weights=True, rng=None, key_added='spatialleiden', min_niche_size=None, copy=False, table_key=None)[source]
Compute niche assignments using the SpatialLeiden algorithm.
This is a wrapper around SpatialLeiden [Müller-Bötticher et al., 2025], which takes
AnnDataas input and works with two layers; one latent space and one spatial layer. Adapted from https://github.com/HiDiHlabs/SpatialLeiden/.- Parameters:
adata – Annotated data object.
latent_connectivities_key (
str) – Key inadata.obspcontaining the latent-space connectivity matrix.spatial_connectivities_key (
str) – Key inanndata.AnnData.obspcontaining the spatial connectivity matrix.resolutions (
float|tuple[float,float] |list[float|tuple[float,float]]) – Resolution parameter(s) for the Leiden optimization. Can be a single float or a list of floats.layer_ratio (
float) – Relative weight assigned to the latent and spatial layers.n_iterations (
int) – Number of optimization iterations used by SpatialLeiden.use_weights (
bool|tuple[bool,bool]) – Whether to use edge weights during clustering.rng (
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None) – Pseudorandom number generator state, following SPEC 7. When None, a newnumpy.random.Generatoris created using entropy from the operating system. Types other thannumpy.random.Generatorare passed tonumpy.random.default_rng()to instantiate a generator. Each resolution is clustered with an independent rng derived from it.min_niche_size (
int|None) – Minimum number of observations required for a niche. Niches with fewer observations are relabeled'not_a_niche'.key_added (
str) – Stem of theanndata.AnnData.obscolumns the labels are written to, one per resolution, namedf"{key_added}_res={resolution}".copy (
bool) – IfTrue, return the result, otherwise save it to theadataobject.table_key (
str|None) – Key inspatialdata.SpatialData.tableswhere the table is stored. Required whenadatais aspatialdata.SpatialDataobject and ignored otherwise.
- Return type:
- Returns:
If
copy = True, returns a copy ofadatawith niche annotations added to.obs. Otherwise, modifiesadatain place and returnsNone.