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