ocelli.tl.MDM

Contents

ocelli.tl.MDM#

ocelli.tl.MDM(adata: AnnData, n_components: int = 10, modalities: list | None = None, weights: str = 'weights', out: str = 'X_mdm', bandwidth_reach: int = 20, unimodal_norm: bool = True, eigval_times_eigvec: bool = True, save_eigvec: bool = True, save_eigval: bool = True, save_mmc: bool = False, n_jobs: int = -1, random_state=None, verbose: bool = False, copy: bool = False)#

Multimodal Diffusion Maps

This function computes a multimodal latent space based on weighted modalities using diffusion maps. Each modality contributes to the multimodal Markov chain proportionally to its weights, enabling integrative single-cell analysis across modalities.

Note

It is necessary to run ocelli.pp.neighbors before using this function to ensure that nearest neighbors and distances are computed.

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

  • n_components (int) – Number of MDM components to compute. (default: 10)

  • modalities (list or None) – List of keys in adata.obsm storing the modalities. If None, the list is loaded from adata.uns[‘modalities’]. (default: None)

  • weights (str) – Key in adata.obsm storing modality weights. (default: ‘weights’)

  • out (str) – Key in adata.obsm where the MDM embedding is saved. (default: ‘X_mdm’)

  • bandwidth_reach (int) – Index of the nearest neighbor used for calculating kernel bandwidths (epsilons). (default: 20)

  • unimodal_norm (bool) – Whether to normalize unimodal kernel matrices mid-training. (default: True)

  • eigval_times_eigvec (bool) – Whether to scale eigenvectors by eigenvalues in the final embedding. If False, only eigenvectors are used. (default: True)

  • save_eigvec (bool) – Whether to save the eigenvectors to adata.uns[‘eigenvectors’]. (default: True)

  • save_eigval (bool) – Whether to save the eigenvalues to adata.uns[‘eigenvalues’]. (default: True)

  • save_mmc (bool) – Whether to save the multimodal Markov chain matrix to adata.uns[‘multimodal_markov_chain’]. (default: False)

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

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

  • verbose (bool) – Whether to print progress notifications. (default: False)

  • 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 following fields:
    • adata.obsm[out]: MDM embedding.

    • adata.uns[‘multimodal_markov_chain’] (if save_mmc=True): Multimodal Markov chain.

    • adata.uns[‘eigenvectors’] (if save_eigvec=True): Eigenvectors.

    • adata.uns[‘eigenvalues’] (if save_eigval=True): Eigenvalues.

  • If copy=True: Returns a modified copy of adata with these fields.

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['modality1'] = np.random.rand(100, 10)
adata.obsm['modality2'] = np.random.rand(100, 15)
adata.uns['modalities'] = ['modality1', 'modality2']

# Compute nearest neighbors
oci.pp.neighbors(adata, x=['modality1', 'modality2'], n_neighbors=20)

# Compute modality weights
oci.tl.modality_weights(adata, n_jobs=4, verbose=True)

# Run Multimodal Diffusion Maps
oci.tl.MDM(adata, n_components=10, verbose=True)