https://github.com/bowang-lab/morphodiff
MorphoDiff is a diffusion based generative pipeline to predict high-resolution cell morphological responses under different conditions based on perturbation encoding.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.3%) to scientific vocabulary
Repository
MorphoDiff is a diffusion based generative pipeline to predict high-resolution cell morphological responses under different conditions based on perturbation encoding.
Basic Info
Statistics
- Stars: 21
- Watchers: 3
- Forks: 4
- Open Issues: 0
- Releases: 0
Metadata Files
README.md

This is the official repository of MorphoDiff, a diffusion based generative pipeline to predict high-resolution cell morphological responses under different conditions based on perturbation encoding. MorphoDiff is capable of producing guided, high-resolution predictions of cell morphology that generalize across both chemical and genetic interventions.
Link to the ICLR published paper: https://openreview.net/pdf?id=PstM8YfhvI
Environmental Setting
Create a new virtual environment (python 3.10.12 was used in our experiments), and install the diffusers package provided in this repository using the following commands:
```bash
clone github repository
git clone git@github.com:bowang-lab/MorphoDiff.git
install diffusers
cd MorphoDiff/morphodiff/diffusers
pip install .
cd examples/texttoimage
pip install -r requirements.txt
configure accelerator
accelerate config ```
The xformers and wandb (if needed) packages are also required for training and need to be installed in the morphodiff environment. The requirements.txt provides a list of packages and their versions used to run the scripts.
Training/fine-tuning
The scripts/train.sh provides commands for defining parameters required for training MorphoDiff and Stable Diffusion, with description of each parameter provided in the bash script. After defining the parameters of the training script, run the following for submitting the training job using Slurm.
bash
sbatch scripts/train.sh
You should provide a path to a pretrained Stable Diffusion model to the script. It can either be the pretrained Stable Diffusion (such as stable-diffusion-v1-4 originally used for training MorphoDiff), or one of the pretrained checkpoints.
After the training is completed for the specified number of steps, the scripts/train.sh automatically resubmits the job and resumes training from the last checkpoint. You can set the totalsteps parameter to not train more than a specific number of steps, or comment the `scontrol requeue $SLURMJOB_ID` line that resubmits the job once it is finished.
Data Preparation
Data folder contents must follow the structure described in https://huggingface.co/docs/datasets/image_dataset#imagefolder. In particular, a metadata.jsonl file must exist to provide the perturbation id for the images. The perturbation ids used in MorphoDiff analysis are provided in the required_file/ folder.
Download Dataset
The raw datasets used in the MorphoDiff paper can be downloaded from the following websites.
| Dataset | Link | | ------------- | ---------------------------------------------------------------------------------- | | RxRx1 | https://www.rxrx.ai/rxrx1 | | BBBC021 | https://bbbc.broadinstitute.org/BBBC021 | | Rohban et al. | https://github.com/broadinstitute/cellpainting-gallery - (cpg0017-rohban-pathways) |
Perturbation Encoding
For each dataset, there should be a separate csv file in the required_file/ directory that contains the perturbation id (in the first column, perturbation id must be in the same format as what is provided in the metadata.jsonl), and perturbation embedding with numerical values of the pertubration encoding provided in the following columns. Please look at sample csv files provided.
We used scGPT single-cell foundation model for encoding genetic perturbations (follow installation instruction from https://github.com/bowang-lab/scGPT), and RDKit tool (https://github.com/rdkit/rdkit) for encoding chemical compounds. The code for converting gene ids and SMILES representation of compounds to pertubration embedding is provided in the preprocessing/ folder.
Image Generation
The scripts/generate_img.sh script is a Slurm based bash script that takes the path to the pretrained checkpoint, a file of perturbation list, the number of images to generate per perturbation, and an address to save the images of each perturbation in a separate folder. You should set the parameters described and documented in the scripts/generate_img.sh and run it as follow
bash
sh scripts/generate_img.sh
CellProfiler Analysis
The CellProfiler pipeline used for extracting CellProfiler features is provided in cellprofiler/pipeline/ folder. All scripts for CellProfiler feature preprocessing, and validation are provided in the cellprofiler/ folder.
Citation
If our work assists your research, pls use the following to cite our work:
bash
@inproceedings{
navidi2025morphodiff,
title={MorphoDiff: Cellular Morphology Painting with Diffusion Models},
author={Zeinab Navidi and Jun Ma and Esteban Miglietta and Le Liu and Anne E Carpenter and Beth A Cimini and Benjamin Haibe-Kains and BO WANG},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=PstM8YfhvI}
}
Owner
- Name: WangLab @ U of T
- Login: bowang-lab
- Kind: organization
- Location: 190 Elizabeth St, Toronto, ON M5G 2C4 Canada
- Website: https://wanglab.ml
- Repositories: 11
- Profile: https://github.com/bowang-lab
BoWang's Lab at University of Toronto
GitHub Events
Total
- Issues event: 12
- Watch event: 22
- Issue comment event: 20
- Push event: 31
- Public event: 1
- Fork event: 4
Last Year
- Issues event: 12
- Watch event: 22
- Issue comment event: 20
- Push event: 31
- Public event: 1
- Fork event: 4
Committers
Last synced: over 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| znavidi | z****i@v****l | 10 |
| znavidi | z****i@v****l | 2 |
| Zeinab Navidi | 4****i | 1 |
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 6
- Total pull requests: 0
- Average time to close issues: 4 days
- Average time to close pull requests: N/A
- Total issue authors: 3
- Total pull request authors: 0
- Average comments per issue: 2.83
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 6
- Pull requests: 0
- Average time to close issues: 4 days
- Average time to close pull requests: N/A
- Issue authors: 3
- Pull request authors: 0
- Average comments per issue: 2.83
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- prsigma (4)
- Bozolzr (1)
- amelie-iska (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- GitPython ==3.1.42
- Jinja2 ==3.1.3
- Markdown ==3.5.2
- MarkupSafe ==2.1.5
- PyYAML ==6.0.1
- Pygments ==2.17.2
- SQLAlchemy ==1.4.53
- Werkzeug ==3.0.1
- XlsxWriter ==3.2.0
- absl-py ==2.1.0
- accelerate ==0.27.2
- aiohttp ==3.9.3
- aiosignal ==1.3.1
- annotated-types ==0.6.0
- appdirs ==1.4.4
- asttokens ==2.4.1
- async-timeout ==4.0.3
- attrs ==23.2.0
- awscli ==1.33.16
- botocore ==1.34.134
- certifi ==2024.2.2
- charset-normalizer ==3.3.2
- chex ==0.1.85
- cjm-pandas-utils ==0.0.3
- cjm-pil-utils ==0.0.9
- cjm-psl-utils ==0.0.4
- cjm-pytorch-utils ==0.0.6
- cjm-torchvision-tfms ==0.0.11
- click ==8.1.7
- colorama ==0.4.6
- comm ==0.2.2
- contourpy ==1.2.0
- cycler ==0.12.1
- datasets ==2.18.0
- debugpy ==1.8.1
- decorator ==5.1.1
- deepspeed ==0.13.5
- descriptastorus ==2.6.1
- dill ==0.3.8
- docker-pycreds ==0.4.0
- docutils ==0.16
- dominate ==2.9.1
- et-xmlfile ==1.1.0
- etils ==1.7.0
- exceptiongroup ==1.2.0
- executing ==2.0.1
- filelock ==3.13.1
- flax ==0.8.1
- fonttools ==4.50.0
- frozenlist ==1.4.1
- fsspec ==2023.10.0
- ftfy ==6.1.3
- gitdb ==4.0.11
- greenlet ==3.0.3
- grpcio ==1.60.1
- h5py ==3.10.0
- hjson ==3.1.0
- huggingface-hub ==0.20.3
- idna ==3.6
- imageio ==2.34.0
- imageio-ffmpeg ==0.4.3
- importlib-metadata ==7.0.1
- importlib_resources ==6.1.3
- ipykernel ==6.29.4
- ipython ==8.23.0
- ipywidgets ==8.1.2
- jax ==0.4.25
- jaxlib ==0.4.25
- jedi ==0.19.1
- jmespath ==1.0.1
- joblib ==1.4.0
- jsonpatch ==1.33
- jsonpointer ==3.0.0
- jupyter_client ==8.6.1
- jupyter_core ==5.7.2
- jupyterlab_widgets ==3.0.10
- kaleido ==0.2.1
- kiwisolver ==1.4.5
- lazy_loader ==0.3
- llvmlite ==0.43.0
- markdown-it-py ==3.0.0
- matplotlib ==3.8.3
- matplotlib-inline ==0.1.6
- mdurl ==0.1.2
- ml-dtypes ==0.3.2
- mpmath ==1.3.0
- msgpack ==1.0.8
- multidict ==6.0.5
- multipledispatch ==1.0.0
- multiprocess ==0.70.16
- mypy-extensions ==1.0.0
- natsort ==8.4.0
- nest-asyncio ==1.6.0
- networkx ==3.2.1
- ninja ==1.11.1.1
- numba ==0.60.0
- numpy ==1.26.4
- nvidia-cublas-cu12 ==12.1.3.1
- nvidia-cuda-cupti-cu12 ==12.1.105
- nvidia-cuda-nvrtc-cu12 ==12.1.105
- nvidia-cuda-runtime-cu12 ==12.1.105
- nvidia-cudnn-cu12 ==8.9.2.26
- nvidia-cufft-cu12 ==11.0.2.54
- nvidia-curand-cu12 ==10.3.2.106
- nvidia-cusolver-cu12 ==11.4.5.107
- nvidia-cusparse-cu12 ==12.1.0.106
- nvidia-nccl-cu12 ==2.19.3
- nvidia-nvjitlink-cu12 ==12.3.101
- nvidia-nvtx-cu12 ==12.1.105
- opencv-python ==4.9.0.80
- openpyxl ==3.1.5
- opt-einsum ==3.3.0
- optax ==0.2.0
- orbax-checkpoint ==0.5.3
- packaging ==23.2
- pandas ==2.2.0
- pandas-flavor ==0.6.0
- parso ==0.8.4
- peft ==0.7.0
- pexpect ==4.9.0
- pillow ==10.2.0
- platformdirs ==4.2.0
- plotly ==5.24.1
- prompt-toolkit ==3.0.43
- protobuf ==4.25.3
- psutil ==5.9.8
- ptyprocess ==0.7.0
- pure-eval ==0.2.2
- py-cpuinfo ==9.0.0
- pyarrow ==15.0.0
- pyarrow-hotfix ==0.6
- pyasn1 ==0.6.0
- pycytominer ==1.1.0
- pydantic ==2.6.3
- pydantic_core ==2.16.3
- pyjanitor ==0.27.0
- pynndescent ==0.5.13
- pynvml ==11.5.0
- pyparsing ==3.1.2
- pyre-extensions ==0.0.30
- pyspng ==0.1.2
- python-dateutil ==2.8.2
- pytz ==2024.1
- pyzmq ==25.1.2
- rdkit ==2023.9.5
- regex ==2023.12.25
- requests ==2.31.0
- rich ==13.7.1
- rsa ==4.7.2
- s3transfer ==0.10.2
- safetensors ==0.4.2
- scikit-image ==0.22.0
- scikit-learn ==1.4.2
- scipy ==1.11.1
- seaborn ==0.13.2
- sentry-sdk ==1.44.0
- setproctitle ==1.3.3
- six ==1.16.0
- smmap ==5.0.1
- stack-data ==0.6.3
- swd ==1.0.0
- sympy ==1.12
- tabulate ==0.9.0
- tenacity ==9.0.0
- tensorboard ==2.16.2
- tensorboard-data-server ==0.7.2
- tensorstore ==0.1.54
- thop ==0.1.1.post2209072238
- threadpoolctl ==3.5.0
- tifffile ==2024.2.12
- timm ==1.0.8
- tokenizers ==0.15.2
- toolz ==0.12.1
- torch ==2.2.1
- torch-fidelity ==0.3.0
- torcheval ==0.0.7
- torchtnt ==0.2.4
- torchvision ==0.17.1
- tornado ==6.4
- tqdm ==4.66.2
- traitlets ==5.14.2
- transformers ==4.38.2
- triton ==2.2.0
- typing-inspect ==0.9.0
- typing_extensions ==4.9.0
- tzdata ==2024.1
- ultralytics ==8.1.38
- umap-learn ==0.5.6
- urllib3 ==2.2.1
- visdom ==0.2.4
- wandb ==0.16.5
- wcwidth ==0.2.13
- websocket-client ==1.8.0
- widgetsnbextension ==4.0.10
- xarray ==2024.3.0
- xformers ==0.0.24
- xxhash ==3.4.1
- yarl ==1.9.4
- zipp ==3.17.0
- ubuntu 20.04 build
- ubuntu 20.04 build
- ubuntu 20.04 build
- nvidia/cuda 11.6.2-cudnn8-devel-ubuntu20.04 build
- nvidia/cuda 12.1.0-runtime-ubuntu20.04 build
- ubuntu 20.04 build
- nvidia/cuda 12.1.0-runtime-ubuntu20.04 build
- nvidia/cuda 12.1.0-runtime-ubuntu20.04 build
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- peft ==0.7.0
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- webdataset *
- accelerate >=0.16.0
- datasets *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- datasets *
- flax *
- ftfy *
- optax *
- tensorboard *
- torch *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- datasets *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- wandb *
- Jinja2 *
- accelerate *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- peft ==0.7.0
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- flax *
- ftfy *
- optax *
- tensorboard *
- torch *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- peft ==0.7.0
- tensorboard *
- torchvision *
- transformers >=4.25.1
- accelerate >=0.16.0
- datasets *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- datasets *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- diffusers *
- ftfy *
- tensorboard *
- torch *
- torchvision *
- transformers *
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- peft *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- wandb *
- Jinja2 *
- accelerate >=0.16.0
- diffusers ==0.9.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.21.0
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- intel_extension_for_pytorch >=1.13
- tensorboard *
- torchvision *
- transformers >=4.21.0
- accelerate *
- ftfy *
- modelcards *
- neural-compressor *
- tensorboard *
- torchvision *
- transformers >=4.25.0
- Jinja2 *
- accelerate >=0.16.0
- datasets *
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- datasets >=2.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- wandb >=0.16.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- flax *
- ftfy *
- optax *
- tensorboard *
- torch *
- torchvision *
- transformers >=4.25.1
- accelerate >=0.16.0
- datasets *
- ftfy *
- modelcards *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- accelerate >=0.16.0
- ftfy *
- modelcards *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- accelerate >=0.16.0
- datasets *
- tensorboard *
- torchvision *
- Jinja2 ==3.1.3
- accelerate ==0.23.0
- diffusers ==0.20.1
- ftfy ==6.1.1
- peft ==0.5.0
- tensorboard ==2.14.0
- torch ==2.0.1
- torchvision >=0.16
- transformers ==4.36.0
- accelerate >=0.16.0
- datasets *
- ftfy *
- safetensors *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- wandb *
- Jinja2 *
- accelerate >=0.16.0
- datasets *
- ftfy *
- peft ==0.7.0
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- datasets *
- flax *
- ftfy *
- optax *
- tensorboard *
- torch *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.22.0
- datasets *
- ftfy *
- peft ==0.7.0
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- accelerate >=0.16.0
- ftfy *
- tensorboard *
- torchvision *
- transformers >=4.25.1
- Jinja2 *
- flax *
- ftfy *
- optax *
- tensorboard *
- torch *
- torchvision *
- transformers >=4.25.1
- accelerate >=0.16.0
- datasets *
- torchvision *
- accelerate >=0.16.0
- bitsandbytes *
- deepspeed *
- huggingface-cli *
- peft >=0.6.0
- torchvision *
- transformers >=4.25.1
- wandb *
- deps *