Skip to main content

GNODEVAE: A Graph-Based ODE-VAE Enhances Clustering of Single-Cell Data

PyPI DOI

Graphical Abstract

GNODEVAE Graphical Abstract

Introduction

GNODEVAE is a computational framework that integrates Graph Attention Networks (GAT), Neural Ordinary Differential Equations (NODE), and Variational Autoencoders (VAE). It targets three common challenges in single-cell RNA sequencing data analysis:

  1. Capturing complex topological relationships between cells
  2. Modeling continuous dynamic processes of cell differentiation
  3. Handling high levels of technical noise and biological variation

The integration is intended to support identification of cell subpopulations, reconstruction of developmental trajectories, and analysis of cellular heterogeneity.

Key Contributions

1. Dynamic Attention Weighting for Biological Significance

The GAT attention mechanism adaptively weights gene expression profiles, prioritizing biological relationships while reducing technical noise in heterogeneous cell populations.

2. Continuous-Time Developmental Modeling via Neural ODEs

Neural ordinary differential equations transform static representations into dynamic systems, with time variables providing a continuous parameterization of developmental processes.

3. Biologically Consistent Latent Space Representations

The model's latent space is designed to capture variation in cell differentiation rates, while attention weights can be inspected alongside known developmental relationships between cell types.

4. Benchmarking Summary

The accompanying study compares GNODEVAE with several single-cell analysis methods, including scVI, DIP-VAE, TC-VAE, beta-VAE, Info-VAE, and scTour, across 13 datasets.

5. Gene Trend Analysis

The accompanying study also reports stronger Calinski-Harabasz scores than selected baselines for gene trend analysis.

Installation

Prerequisites

  • Python 3.9 or higher
  • PyTorch 1.13 or higher (with CUDA support recommended for GPU acceleration)
  • PyTorch Geometric
  • A METIS backend, pyg-lib or torch-sparse, for training with agent, agent_r or GNODEVAE_agent_r: these split the cell graph with PyTorch Geometric's ClusterData, which needs one of the two. pip install gnodevae does not install them, because they are published as wheels for each PyTorch and CUDA version on the PyTorch Geometric wheel index rather than on PyPI. Install the build that matches your PyTorch and CUDA versions as described in the PyTorch Geometric installation guide, for example pip install pyg_lib -f https://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html. These wheels appear some time after each PyTorch release; if none exist yet for your PyTorch version, install the newest PyTorch version that has them. GNODEVAE_agent_subgraph samples subgraphs instead and needs neither, and the package imports without them.

Install from PyPI

pip install gnodevae

Install from Source

# Clone the repository
git clone https://github.com/PeterPonyu/GNODEVAE.git
cd GNODEVAE

# Install the package and its dependencies
pip install -e .

Dependencies

The main dependencies include:

  • torch - PyTorch deep learning framework
  • torch-geometric - Geometric deep learning extension for PyTorch
  • scanpy - Single-cell analysis toolkit
  • anndata - Annotated data structures for single-cell data
  • torchdiffeq - Differentiable ODE solvers for PyTorch
  • numpy, pandas - Data manipulation
  • scikit-learn - Machine learning utilities
  • tqdm - Progress bars
  • psutil - System resource monitoring

Quick Start

Basic Usage

import scanpy as sc
from GNODEVAE import agent_r  # GraphVAE with refined architecture
# OR
from GNODEVAE import agent  # Standard GraphVAE
# For full GNODEVAE with ODE support, use:
# from GNODEVAE.GODEVAE_agent import GNODEVAE_agent_r

# Load your single-cell data
adata = sc.read_h5ad('your_data.h5ad')

# Initialize the graph VAE agent (agent_r has no neural ODE component)
model = agent_r(
    adata=adata,
    layer='counts',           # Layer containing count data
    n_var=2000,              # Number of highly variable genes
    tech='PCA',              # Dimensionality reduction technique
    n_neighbors=15,          # Number of neighbors for graph construction
    latent_dim=10,           # Latent space dimension
    hidden_dim=128,          # Hidden layer dimension
    encoder_type='graph',    # Use graph encoder
    graph_type='GAT',        # Graph Attention Network
    lr=1e-4,                 # Learning rate
)

# Train the model
model.fit(epochs=300, update_steps=10, silent=False)

# Extract latent representations
latent = model.get_latent()

# Store latent representation in AnnData object
adata.obsm['X_gnodevae'] = latent

# Perform downstream analysis (e.g., clustering)
import scanpy as sc
sc.pp.neighbors(adata, use_rep='X_gnodevae')
sc.tl.leiden(adata)
sc.tl.umap(adata)

Using Standard GraphVAE (without ODE)

from GNODEVAE import agent

# Initialize standard GraphVAE agent
model = agent(
    adata=adata,
    layer='counts',
    n_var=2000,
    tech='PCA',
    n_neighbors=15,
    latent_dim=10,
    hidden_dim=128,
    encoder_type='GAT',
    lr=1e-4
)

# Train and extract embeddings
model.fit(epochs=300)
latent = model.get_latent()

Key Parameters

Data Preprocessing Parameters

  • layer (str): Layer of AnnData to use (default: 'counts')
  • n_var (int): Number of highly variable genes to select (default: None, uses all)
  • tech (str): Dimensionality reduction method - 'PCA', 'NMF', 'FastICA', 'TruncatedSVD', 'FactorAnalysis', or 'LatentDirichletAllocation' (default: 'PCA')
  • n_neighbors (int): Number of neighbors for graph construction (default: 15)
  • batch_tech (str): Batch correction method - 'harmony' or 'scvi' (default: None)
  • all_feat (bool): Whether to use all features or only highly variable genes (default: True)

Model Architecture Parameters

  • hidden_dim (int): Hidden layer dimension (default: 128)
  • latent_dim (int): Latent space dimension for embeddings (default: 10)
  • encoder_type (str): Encoder type - 'graph' or 'linear' (default: 'graph')
  • graph_type (str): Graph convolution type - 'GAT', 'GCN', 'SAGE', 'Transformer', etc. (default: 'GAT')
  • structure_decoder_type (str): Structure decoder type - 'mlp', 'bilinear', or 'inner_product' (default: 'mlp')
  • feature_decoder_type (str): Feature decoder type - 'linear' or 'graph' (default: 'linear')
  • hidden_layers (int): Number of hidden layers (default: 2)
  • dropout (float): Dropout rate (default: 0.05)
  • use_residual (bool): Whether to use residual connections (default: True)

Training Parameters

  • lr (float): Learning rate for optimizer (default: 1e-4)
  • beta (float): Weight for KL divergence loss term (default: 1.0)
  • graph (float): Weight for graph reconstruction loss (default: 1.0)
  • epochs (int): Number of training epochs (default: 300)
  • device (str or torch.device): Computing device - 'cuda' or 'cpu' (default: auto-detect)
  • num_parts (int): Number of graph partitions for mini-batch training (default: 10)

GNODEVAE-Specific Parameters (GNODEVAE_agent_r)

  • ode_hidden_dim (int): Hidden dimension of the latent ODE function (default: 25)
  • w_recon (float): Weight for reconstruction loss (default: 1.0)
  • w_kl (float): Weight for KL divergence loss, applied on top of beta (default: 1.0)
  • w_adj (float): Weight for adjacency matrix loss, applied on top of graph (default: 1.0)
  • w_recon_ode (float): Weight for the reconstruction loss of expression decoded from the ODE latent states (default: 1.0)
  • w_z_div (float): Weight for the squared error between the encoder latent means and the ODE latent states (default: 1.0)

Model Architecture

GNODEVAE consists of three main components:

  1. Graph Encoder: Encodes cell-cell relationships and gene expression using Graph Attention Networks (GAT) or other graph convolution layers
  2. Neural ODE: Models continuous developmental trajectories in the latent space
  3. Decoder: Reconstructs both graph structure and gene expression from latent representations

The model learns a low-dimensional latent representation that captures:

  • Cell type identity
  • Developmental state
  • Cell-cell relationships
  • Temporal dynamics (with ODE component)

Output

After training, GNODEVAE produces:

  • Latent representations: Low-dimensional embeddings for each cell
  • Clustering metrics: the training scores described under Evaluation Metrics
  • Pseudo-time: Developmental trajectory information (for GNODEVAE_agent_r, which has the ODE component)
  • Graph structure: Learned cell-cell similarity graph

Advanced Usage

Custom Graph Construction

# Use custom graph construction parameters
model = agent_r(
    adata=adata,
    n_neighbors=30,      # Increase neighbors for denser graph
    graph_type='Transformer',  # Use Transformer convolution
    alpha=0.5            # Set alpha for specific layers
)

Interpretable Mode

# Use interpretable GraphVAE
model = agent(
    adata=adata,
    interpretable=True,  # Enable interpretable mode
    idim=2              # Interpretable dimension
)

Extract Pseudo-time

# For GNODEVAE models with ODE component
# Note: Use GNODEVAE_agent_r from GODEVAE_agent module for pseudo-time functionality
from GNODEVAE.GODEVAE_agent import GNODEVAE_agent_r

model = GNODEVAE_agent_r(adata=adata, ...)
model.fit(epochs=300)

# Get pseudo-time for cells
pseudotime_df = model.partition_time()

Evaluation Metrics

At every epoch, agent, agent_r and GNODEVAE_agent_r score the latent representation of all cells without using cell labels. Reference labels come from k-means clustering (latent_dim clusters) of the input feature matrix, computed once when the agent is created; the latent representation is clustered with k-means into the same number of clusters. For GNODEVAE_agent_r, the scored representation is scale1 * latent + scale2 * odelatent, the mix that get_mix_latent() returns (scale1 and scale2 default to 0.5). During fit, the progress bar shows each score averaged over the last update_steps epochs:

  • ARI: computed with adjusted_mutual_info_score, i.e. the adjusted mutual information between the reference labels and the latent clusters (not the adjusted Rand index)
  • NMI: normalized mutual information between the reference labels and the latent clusters
  • ASW: silhouette score of the latent clusters
  • C_H: Calinski-Harabasz score of the latent clusters
  • D_B: Davies-Bouldin score of the latent clusters (lower is better)
  • P_C: mean, over latent dimensions, of the summed absolute Pearson correlation with the other latent dimensions

Citation

If you use GNODEVAE in your research, please cite:

@article{fu2025gnodevae,
  title={GNODEVAE: a graph-based ODE-VAE enhances clustering for single-cell data},
  author={Fu, Zeyu and Chen, Chunlin and Wang, Song and Wang, Junping and Chen, Shilei},
  journal={BMC Genomics},
  volume={26},
  pages={767},
  year={2025},
  doi={10.1186/s12864-025-11946-7}
}

Full Citation: Fu, Z., Chen, C., Wang, S. et al. GNODEVAE: a graph-based ODE-VAE enhances clustering for single-cell data. BMC Genomics 26, 767 (2025). https://doi.org/10.1186/s12864-025-11946-7

License

See LICENSE file for details.

Contact

For questions and feedback, please open an issue on the GitHub repository.

Metadata

Release files for gnodevae 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gnodevae 0.0.6
File Size Uploaded Provenance Actions
gnodevae-0.0.6.tar.gz 57.4 kB With provenance Details for gnodevae-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gnodevae 0.0.6
File Interpreter ABI Platform Actions
gnodevae-0.0.6-py3-none-any.whl Python 3 none any Details for gnodevae-0.0.6-py3-none-any.whl

Total release size: 124.3 kB

Release files / gnodevae-0.0.6.tar.gz

Download URL gnodevae-0.0.6.tar.gz
Size 57.4 kB
Tags Source
SHA-256 checksum
How to use checksums
95dfe509b42b9cfe44222bb1105593d13ad81b407687249767c88a3fb8bf2738
BLAKE2b-256 checksum
How to use checksums
3c250204fc5068fc4305650079e92d48d6f31c78d46ea31a8810aae92521ee0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / gnodevae-0.0.6-py3-none-any.whl

Download URL gnodevae-0.0.6-py3-none-any.whl
Size 66.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a30e04a2e8a428459b4c02ce1b4dcffc7a628f18051f08db9870cde4d9837d5
BLAKE2b-256 checksum
How to use checksums
85b2d18e286f006989182c9d1288213326620b243d36c70d37595fa83ee223f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for gnodevae 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gnodevae-0.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page