ocelli.tl.fa2

Contents

ocelli.tl.fa2#

ocelli.tl.fa2(adata: AnnData, graph: str = 'graph', n_components: int = 2, n_iter: int = 4000, linlogmode: bool = False, gravity: float = 1.0, flags: str = '', out: str = 'X_fa2', random_state=None, n_jobs: int = -1, copy=False)#

ForceAtlas2 dimensionality reduction

ForceAtlas2 generates 2D or 3D graph embeddings by simulating node interactions based on attractive and repulsive forces. This function wraps the Klarman Cell Observatory’s Java implementation of ForceAtlas2.

Note

Before using this function, you must construct a graph by running ocelli.tl.neighbors_graph or ocelli.tl.transitions_graph.

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

  • graph (str) – Key in adata.obsm storing the graph to visualize. The graph should be an array of cell indices. (default: ‘graph’)

  • n_components (int) – Dimensionality of the ForceAtlas2 embedding. Valid options: 2 (2D) or 3 (3D). (default: 2)

  • n_iter (int) – Number of iterations for the ForceAtlas2 algorithm. Higher values refine the embedding. (default: 4000)

  • linlogmode (bool) – Whether to switch to the lin-log mode, which tightens clusters. (default: False)

  • gravity (float) – Controls the attraction of nodes to the graph center. (default: 1.0)

  • flags (str) – Additional ForceAtlas2 command-line flags. Refer to the official documentation for details. (default: ‘’)

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

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

  • If copy=True: Returns a modified copy of adata with the ForceAtlas2 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['graph'] = np.random.randint(0, 100, size=(100, 10))

# Construct ForceAtlas2 embedding
oci.tl.fa2(
    adata,
    graph='graph',
    n_components=2,
    n_iter=4000,
    linlogmode=True,
    gravity=1.5,
    random_state=42,
    verbose=True
)