ocelli.tl.umap

Contents

ocelli.tl.umap#

ocelli.tl.umap(adata: AnnData, x=None, n_components: int = 2, n_neighbors: int = 20, min_dist: float = 0.1, spread: float = 1.0, out: str = 'X_umap', random_state=None, n_jobs: int = -1, copy=False)#

UMAP dimensionality reduction

Uniform Manifold Approximation and Projection (UMAP) is a dimensionality reduction technique that is particularly useful for visualizing high-dimensional data in 2D or 3D space. This function is a wrapper for the umap-learn library.

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

  • x (str or None) – Key in adata.obsm storing the data to be reduced. If None, adata.X is used. (default: None)

  • n_components (int) – Number of dimensions in the UMAP embedding. (default: 2)

  • n_neighbors (int) – Number of neighboring points used for manifold approximation. Larger values preserve more global structures, while smaller values focus on local structures. (default: 20)

  • min_dist (float) – Minimum distance between embedded points. Smaller values result in tighter clusters, while larger values spread points more evenly. (default: 0.1)

  • spread (float) – Scale of the embedded points. Works in conjunction with min_dist to control clustering. (default: 1.0)

  • out (str) – Key in adata.obsm where the UMAP embedding will be stored. (default: ‘X_umap’)

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

  • n_jobs (int) – Number of parallel jobs to use. If -1, all available CPUs are used. (default: -1)

  • 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 UMAP embedding stored in adata.obsm[out].

  • If copy=True: Returns a modified copy of adata with the UMAP embedding.

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 UMAP embedding
oci.tl.umap(adata, x='embedding', n_components=2, n_neighbors=15, min_dist=0.3, random_state=42)