ocelli.tl.louvain

Contents

ocelli.tl.louvain#

ocelli.tl.louvain(adata, x: str | None = None, out: str = 'louvain', n_neighbors: int = 20, resolution: float = 1.0, random_state=None, copy: bool = False)#

Louvain clustering

Computes Louvain clusters based on the nearest neighbor graph of the data. This function is a wrapper for scanpy.tl.louvain.

Parameters:
  • adata (anndata.AnnData) – The annotated data matrix.

  • x (str or None) – Key in adata.obsm storing the representation for clustering. If None, adata.X is used. (default: None)

  • out (str) – Key in adata.obs where Louvain cluster labels are stored. (default: ‘louvain’)

  • n_neighbors (int) – Number of nearest neighbors to use in graph construction. (default: 20)

  • resolution (float) – Resolution parameter for Louvain clustering. Higher values result in more clusters. (default: 1.0)

  • random_state (int or None) – Seed for reproducibility. If None, no seed is set. (default: None)

  • copy (bool) – Whether to return a copy of adata. If False, updates are made in-place. (default: False)

Returns:

  • If copy=False: Updates adata with the Louvain clusters stored in adata.obs[out].

  • If copy=True: Returns a modified copy of adata with the Louvain clusters.

Return type:

anndata.AnnData or None

Example:
import ocelli as oci
from anndata import AnnData
import numpy as np

# Example data
adata = AnnData(X=np.random.rand(100, 50))
adata.obsm['embedding'] = np.random.rand(100, 10)

# Compute Louvain clusters
oci.tl.louvain(adata, x='embedding', n_neighbors=15, resolution=0.8, random_state=42)