spatialleiden.spatialleiden
- spatialleiden.spatialleiden(adata, *, resolution=1, latent_neighbors=None, spatial_neighbors=None, key_added='spatialleiden', directed=True, use_weights=True, n_iterations=-1, partition_type=<class 'leidenalg.VertexPartition.RBConfigurationVertexPartition'>, layer_ratio=1, latent_neighbors_key='connectivities', spatial_neighbors_key='spatial_connectivities', latent_partition_kwargs=None, spatial_partition_kwargs=None, random_state=42)
Perform SpatialLeiden clustering.
This is a wrapper around
spatialleiden.multiplex_leiden()that usesanndata.AnnDataas input and works with two layers; one latent space and one spatial layer.- Parameters:
adata (AnnData)
resolution (float | tuple[float, float], optional) – Resolution for the latent space and spatial layer, respectively. A single float applies to both layers.
latent_neighbors (sparray | spmatrix | ndarray) – Matrix of row-wise neighbor definitions in the latent space layer i.e. cij is the connectivity of i \(\to\) j.
spatial_neighbors (sparray | spmatrix | ndarray) – Matrix of row-wise neighbor definitions in the spatial layer i.e. cij is the connectivity of i \(\to\) j.
key_added (str, optional) – Key to store the clustering results in
anndata.AnnData.obsdirected (bool | tuple[bool, bool], optional) – Whether to use a directed graph for latent space and spatial neighbors, respectively. A single bool applies to both layers.
use_weights (bool | tuple[bool, bool], optional) – Whether to use weights for the edges for latent space and spatial neighbors, respectively. A single bool applies to both layers.
n_iterations (int, optional) – Number of iterations to run the Leiden algorithm. If the number is negative it runs until convergence.
partition_type (Type[leidenalg.VertexPartition.MutableVertexPartition], optional) – A
leidenalg.VertexPartition.MutableVertexPartitionto be used.layer_ratio (float, optional) – The ratio of the weighting of the layers; latent space vs spatial. A higher ratio will increase relevance of the spatial neighbors and lead to more spatially homogeneous clusters.
latent_neighbors_key (str, optional) – Key to use for the latent neighbor connectivities in
anndata.AnnData.obsp. Only used if latent_neighbors is None.spatial_neighbors_key (str, optional) – Key to use for the spatial neighbor connectivities in
anndata.AnnData.obsp. Only used if spatial_neighbors is None.latent_partition_kwargs (dict | None, optional) – Keyword arguments for the latent space partition.
spatial_partition_kwargs (dict | None, optional) – Keyword arguments for the spatial partition.
random_state (int, optional) – Random seed.