Skip to main content

celldisect-logo

PyPI version Documentation Status License Stars Downloads bioRxiv

ℹ️ Beta Version Available: A beta version with compatibility for Google Colab and newer versions of torch and scvi-tools is available on the beta-colab branch. Install it with pip install celldisect==0.2.0b1.

🧬 Overview

CellDISECT (Cell DISentangled Experts for Covariate counTerfactuals) is a powerful causal generative model that enhances single-cell analysis by:

  • 🔍 Disentangling Variations: Separates covariate variations at test time
  • 🧪 Counterfactual Predictions: Learns to make accurate counterfactual predictions
  • 🎯 Flexible Fairness: Achieves flexible fairness through expert models for each latent space
  • 🔬 Enhanced Discovery: Captures both covariate-specific information and novel biological insights

📚 Documentation

Visit our comprehensive documentation for:

  • Detailed API reference
  • Step-by-step tutorials
  • Best practices and examples
  • Advanced usage guides

🚀 Quick Start

Prerequisites

We recommend using Anaconda/Miniconda. Create and activate a new environment:

conda create -n CellDISECT python=3.9
conda activate CellDISECT

Installation

  1. Install PyTorch (tested with pytorch 2.1.2 and cuda 12):
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia
  1. Install CellDISECT:
# Via pip (stable version)
pip install celldisect

# Or via GitHub (latest development version)
pip install git+https://github.com/Lotfollahi-lab/CellDISECT

Optional Dependencies

Click to expand optional installations

RAPIDS/rapids-singlecell:

pip install \
    --extra-index-url=https://pypi.nvidia.com \
    cudf-cu12==24.4.* dask-cudf-cu12==24.4.* cuml-cu12==24.4.* \
    cugraph-cu12==24.4.* cuspatial-cu12==24.4.* cuproj-cu12==24.4.* \
    cuxfilter-cu12==24.4.* cucim-cu12==24.4.* pylibraft-cu12==24.4.* \
    raft-dask-cu12==24.4.* cuvs-cu12==24.4.*

pip install rapids-singlecell

CUDA-enabled JAX:

pip install -U "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

📖 Tutorials & Examples

Basic Tutorials

Tutorial Description Links
Basic Training Learn how to train CellDISECT and make counterfactual predictions using the Kang dataset Open In Colab Documentation

Perturbation Prediction

Tutorial Description Links
Perturbation Prediction Predict gene expression under seen, unseen, and combinatorial perturbations using predefined embeddings (GenePT, ESM) Documentation

Advanced Applications

Tutorial Description Links
Latent Space Analysis Explore combinations of CellDISECT latent spaces for erythroid subset inference Documentation
Double Counterfactual Advanced tutorial recreating Scenario 2 counterfactual on the Eraslan dataset Documentation

🧪 Perturbation Prediction

CellDISECT supports perturbation prediction using predefined gene embeddings (e.g. GenePT, ESM). This enables prediction for unseen perturbations and combinatorial perturbations.

import numpy as np
from celldisect import CellDISECT, perturbation_metrics

# Store predefined embeddings in adata.uns
adata.uns['pert_embeddings'] = gene_embeddings  # dict: gene_name -> np.ndarray

# Setup with perturbation support
CellDISECT.setup_anndata(
    adata,
    layer='counts',
    categorical_covariate_keys=['cell_type', 'perturbation'],
    perturbation_key='perturbation',
    perturbation_embedding_key='pert_embeddings',
)

# Train the model
model = CellDISECT(adata, n_latent_shared=32, n_latent_attribute=32)
model.train(max_epochs=200)

# Predict seen, unseen, or combinatorial perturbations
x_ctrl, x_true, x_pred = model.predict_perturbation(
    adata,
    perturbation='GeneA+GeneB',
    source_perturbation='ctrl',
    cats=['cell_type', 'perturbation'],
    perturbation_key='perturbation',
)

# Evaluate
metrics = perturbation_metrics(x_pred.numpy(), x_true.numpy(), x_ctrl.numpy())

See the perturbation prediction tutorial for a full walkthrough.

🤝 Contributing

We welcome contributions! Please see our contributing guidelines for details on how to:

  • Report issues
  • Submit bug fixes
  • Propose new features
  • Submit pull requests

📜 License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

📫 Contact

For questions and support:

📝 Citation

If you use CellDISECT in your research, please cite our paper:

Megas, S., Amani, A., Rose, A., Dufva, O., Shamsaie, K., Asadollahzadeh, H., Polanski, K., Haniffa, M., Teichmann, S. A., & Lotfollahi, M. (2025). Integrating multi-covariate disentanglement with counterfactual analysis on synthetic data enables cell type discovery and counterfactual predictions. bioRxiv. https://doi.org/10.1101/2025.06.03.657578

@article{Megas2025CellDISECT,
    title={Integrating multi-covariate disentanglement with counterfactual analysis on synthetic data enables cell type discovery and counterfactual predictions},
    author={Megas, Stathis and Amani, Arian and Rose, Antony and Dufva, Olli and Shamsaie, Kian and Asadollahzadeh, Hesam and Polanski, Krzysztof and Haniffa, Muzlifah and Teichmann, Sarah Amalia and Lotfollahi, Mohammad},
    journal={bioRxiv},
    year={2025},
    doi={10.1101/2025.06.03.657578},
    elocation-id={2025.06.03.657578},
    publisher={Cold Spring Harbor Laboratory},
    URL={https://www.biorxiv.org/content/10.1101/2025.06.03.657578v1}
}

Metadata

Release files for celldisect 0.1.7

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

Source distribution (sdist)

Source distribution for celldisect 0.1.7
File Size Uploaded Provenance Actions
celldisect-0.1.7.tar.gz 42.8 kB Without provenance Details for celldisect-0.1.7.tar.gz

Built distribution (wheel)

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

Total release size: 86.2 kB

Release files / celldisect-0.1.7.tar.gz

Download URL celldisect-0.1.7.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cef0b0dc84f673b3db073006c2d27b3d439441aa6baa2a9f114c0f6e894e11ed
BLAKE2b-256 checksum
How to use checksums
486499c34b33b392174b88a1ea32771c671d218dfcf22a036715b5e3bbda8f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.10.12 Darwin/27.0.0

Release files / celldisect-0.1.7-py3-none-any.whl

Download URL celldisect-0.1.7-py3-none-any.whl
Size 43.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20d056dc0a405f80b03c3d4551dc3d60d01a5d394881919f80cf9b2bcf0ac2b7
BLAKE2b-256 checksum
How to use checksums
1419d0ff3e0a43ca14c1a627b5a2f296a93c9cab08913f978f31d006dcb951d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.10.12 Darwin/27.0.0

Security for celldisect 0.1.7

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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