schist.inference._pmleiden

Module Contents

Classes

MutableVertexPartition

Functions

leiden(→ Optional[anndata.AnnData])

Cluster cells into subgroups [Traag18].

class schist.inference._pmleiden.MutableVertexPartition
schist.inference._pmleiden.leiden(adata: anndata.AnnData, resolution: float = 1, n_init: int = 100, *, restrict_to: Tuple[str, Sequence[str]] | None = None, random_state: scanpy._utils.AnyRandom = 0, key_added: str = 'leiden', adjacency: scipy.sparse.spmatrix | None = None, directed: bool = True, use_weights: bool = True, n_iterations: int = -1, partition_type: Type[leidenalg.VertexPartition.MutableVertexPartition] | None = None, neighbors_key: str | None = None, obsp: str | None = None, collect_marginals: bool = True, n_jobs: int = -1, copy: bool = False, save_model: str | None = None, dispatch_backend: str | None = 'threads', **partition_kwargs) anndata.AnnData | None

Cluster cells into subgroups [Traag18].

Cluster cells using the Leiden algorithm [Traag18], an improved version of the Louvain algorithm [Blondel08]. It has been proposed for single-cell analysis by [Levine15].

This requires having ran neighbors() or bbknn() first.

Parameters

adata

The annotated data matrix.

resolution

A parameter value controlling the coarseness of the clustering. Higher values lead to more clusters. Set to None if overriding partition_type to one that doesn’t accept a resolution_parameter.

n_init

The number of random initializations to take for consensus

random_state

Change the initialization of the optimization.

restrict_to

Restrict the clustering to the categories within the key for sample annotation, tuple needs to contain (obs_key, list_of_categories).

key_added

adata.obs key under which to add the cluster labels.

adjacency

Sparse adjacency matrix of the graph, defaults to neighbors connectivities.

directed

Whether to treat the graph as directed or undirected.

use_weights

If True, edge weights from the graph are used in the computation (placing more emphasis on stronger edges).

n_iterations

How many iterations of the Leiden clustering algorithm to perform. Positive values above 2 define the total number of iterations to perform, -1 has the algorithm run until it reaches its optimal clustering.

partition_type

Type of partition to use. Defaults to RBConfigurationVertexPartition. For the available options, consult the documentation for find_partition().

neighbors_key

Use neighbors connectivities as adjacency. If not specified, leiden looks .obsp[‘connectivities’] for connectivities (default storage place for pp.neighbors). If specified, leiden looks .obsp[.uns[neighbors_key][‘connectivities_key’]] for connectivities.

obsp

Use .obsp[obsp] as adjacency. You can’t specify both obsp and neighbors_key at the same time.

collect_marginals

Wheter to retrieve the marginal probability to belong to a group

n_jobs

Number of parallel jobs to calculate partitions

copy

Whether to copy adata or modify it inplace.

save_model

If provided, this will be the filename for the PartitionModeState to be saved

**partition_kwargs

Any further arguments to pass to ~leidenalg.find_partition (which in turn passes arguments to the partition_type).

Returns

adata.obs[key_added]

Array of dim (number of cells) that stores the subgroup id (‘0’, ‘1’, …) for each cell.

adata.uns[‘leiden’][‘params’]

A dict with the values for the parameters resolution, random_state, and n_iterations.