Metadata-Version: 2.4
Name: clop-dit
Version: 1.1.1
Summary: CLOP-DiT: Structured-metadata-conditioned single-cell latent generation via contrastive language-omics pretraining and diffusion transformers.
Home-page: https://github.com/PeterPonyu/CLOP-DiT
Author: Zeyu Fu
Author-email: fuzeyu09@gmail.com
Maintainer: Zeyu Fu
Maintainer-email: fuzeyu09@gmail.com
License: MIT
Project-URL: Source, https://github.com/PeterPonyu/CLOP-DiT
Project-URL: Paper, https://doi.org/10.1016/j.array.2026.100934
Project-URL: Issue Tracker, https://github.com/PeterPonyu/CLOP-DiT/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: scipy>=1.10.0
Requires-Dist: scikit-learn>=1.2.0
Requires-Dist: scanpy>=1.9.0
Requires-Dist: anndata>=0.9.0
Requires-Dist: scib>=1.0.0
Requires-Dist: transformers>=4.35.0
Requires-Dist: tokenizers>=0.15.0
Requires-Dist: matplotlib>=3.7.0
Requires-Dist: seaborn>=0.12.0
Requires-Dist: umap-learn>=0.5.0
Requires-Dist: Pillow>=9.0.0
Requires-Dist: torchdiffeq>=0.2.3
Requires-Dist: pyyaml>=6.0
Requires-Dist: tqdm>=4.65.0
Requires-Dist: GEOparse>=2.0.3
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# CLOP-DiT

> Structured-metadata-conditioned single-cell latent generation via contrastive language–omics pretraining and diffusion transformers.

[![PyPI](https://img.shields.io/pypi/v/clop-dit.svg)](https://pypi.org/project/clop-dit/)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.19584068.svg)](https://doi.org/10.5281/zenodo.19584068)

CLOP-DiT is a three-stage pipeline that samples single-cell expression embeddings conditioned on a structured five-field text prompt (cell type, tissue, organism, marker genes, disease context). The first stage is a prototype-aware contrastive aligner that maps frozen BiomedBERT text embeddings and frozen scGPT cell embeddings into a shared 512-dimensional latent space. The second stage is a 1-D Diffusion Transformer trained with conditional flow matching and classifier-free guidance, which samples a latent vector from a Gaussian prior toward the conditioned region of that space. The third stage is the frozen scGPT decoder, used to map the generated latent back to per-gene expression for downstream inspection.

The training corpus is 220,304 cells from 80 publicly available Gene Expression Omnibus (GEO) datasets, deduplicated to 69 evaluation cell types covering human and mouse tumour-microenvironment and developmental contexts.

## Reported results

The headline metrics, evaluated on 69 deduplicated cell types:

| Method | KNN-1 | Steering | DivR | LinAcc |
|---|---|---|---|---|
| Real data | 0.890 | – | 1.000 | 0.942 |
| CLOP-DiT, high-fidelity setting (CFG = 2.0) | 0.369 | 0.810 | 0.513 | 0.511 |
| CLOP-DiT, high-diversity setting (CFG = 1.0) | 0.288 | 0.807 | 0.929 | 0.357 |
| Embedding-VAE baseline | 0.112 | 0.547 | 0.744 | 0.189 |
| Gaussian baseline | 0.011 | 0.466 | 2.277 | 0.009 |

KNN-1 is reported over the 69-class problem with random chance ≈ 0.0145; CLOP-DiT at CFG = 2.0 is therefore about 25× above random. DivR ideal = 1.0.

The reported strength of CLOP-DiT is controllable structured-metadata-conditioned generation. The reported limitations are that within-type variance and gene–gene correlation are only weakly preserved, and that a Gaussian mean-matching baseline outperforms CLOP-DiT on the nine shared distributional metrics.

## Installation

The model code is published on PyPI as `clop-dit`; the import name is `clop_dit`.

```bash
pip install clop-dit
```

The training, inference and figure scripts live in this repository. To run them, install from a clone; the code targets Python 3.10 and the full dependency list is in `requirements.txt`.

```bash
conda create -n clopdit python=3.10
conda activate clopdit
pip install -e .
```

The training and evaluation experiments were carried out with PyTorch 2.1, CUDA 12.0, scGPT v0.2.1, and Hugging Face Transformers 4.36 on a single NVIDIA RTX 5090 Laptop GPU.

## Generating cells from a text prompt

Once the trained checkpoints are placed under `models/`, a single text prompt can be sampled and decoded with the inference entry point:

```bash
python scripts/inference/05_inference.py \
    --prompt "CD8+ cytotoxic T cells from human lung adenocarcinoma" \
    --num_cells 500 --cfg_scale 2.0 --decode_expression \
    --output generated_cells.h5ad
```

Training the contrastive aligner and the diffusion transformer from cached embeddings:

```bash
python scripts/training/04a_train_clop.py --config configs/clop.yaml
python scripts/training/04b_train_dit.py --config configs/dit.yaml
```

## Data

The training and validation data are derived entirely from public Gene Expression Omnibus (GEO) records. Each accession is resolvable at `https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSExxxxxx`.

The deterministic preprocessing pipeline included in this repository (quality control, highly-variable-gene selection, scGPT encoding, study-level stratified split, and deduplication) can rebuild the analysis cache from those GEO records.

The trained model checkpoints (the CLOP aligner and the DiT generator) and the preprocessed embedding cache are not redistributed in this repository because of single-cell data licensing and file-size constraints. Both are available from the co-corresponding authors on reasonable request.

## Citation

If you use CLOP-DiT, please cite the article:

> Fu Z, Liu Y, Wang J, Wang S. CLOP-DiT: Structured-metadata-conditioned single-cell latent generation via contrastive language-omics pretraining and Diffusion Transformers. *Array*. 2026;30:100934. https://doi.org/10.1016/j.array.2026.100934

```bibtex
@article{fu2026clopdit,
  author  = {Fu, Zeyu and Liu, Yiyao and Wang, Junping and Wang, Song},
  title   = {CLOP-DiT: Structured-metadata-conditioned single-cell latent generation via contrastive language-omics pretraining and Diffusion Transformers},
  journal = {Array},
  volume  = {30},
  pages   = {100934},
  year    = {2026},
  doi     = {10.1016/j.array.2026.100934}
}
```

GitHub's "Cite this repository" button reads the same record from `CITATION.cff`.

## License

Released under the MIT License — see `LICENSE`.

## Contact

Zeyu Fu — fuzeyu09@gmail.com
