Code accompanying the paper "Predicting CYP2D6 variant–drug metabolic activity through experimental profiling and contrastive protein language modelling"
This repository provides the fine-tuning pipeline for the CYP2D6-adapted ESM3 encoder (FT-ESM) and the downstream variant–drug regression pipeline (XGBoost) used in the paper. The CYP2 subfamily fine-tuning corpus, the in-house CYP2D6 variant–drug measurement dataset, the pre-trained FT-ESM checkpoint, and the pre-extracted FT-ESM and MoleBERT embedding pickles are distributed separately through the accompanying Google Drive (see data/README.md).
CYP2D6-FTESM/
├── ftesm/ # Fine-tuning of the ESM3 protein language model
│ ├── model_ftesm.py # LoRA + FiLM + CWCL model definition
│ └── train_3task_cwcl.py # Main training entry point (3-target regression + CWCL)
│
├── downstream/ # Variant–drug regression pipeline (XGBoost)
│ ├── train_nestedCV.py # Nested-CV training driver (10-fold stratified nested CV)
│ └── bayesopt_xgb_v4.py # XGBoost hyperparameter Bayesian optimization
│
├── configs/
│ └── run_reg_long.sh # Reference training launcher (multi-GPU torchrun)
│
├── data/ # (Not tracked in git) — see data/README.md
│
├── requirements.txt
├── LICENSE
└── README.md
The following are hosted on Google Drive because of size:
- CYP2 subfamily fine-tuning corpus — 3,708 missense variants across CYP2B6, CYP2C8, CYP2E1, CYP2S1, and CYP2D6, with AlphaMissense, ESM-1v log-likelihood, and FoldX ΔΔG labels.
- In-house CYP2D6 variant–drug dataset — nine haplotypes × 35 drugs (291 pairs) with intrinsic clearance labels.
- Pre-trained FT-ESM checkpoint — SWA-averaged encoder used throughout the paper.
- FT-ESM variant embedding pickle — pre-extracted per-allele embeddings.
- MoleBERT drug embedding pickle — pre-extracted per-substrate embeddings.
Download link and folder layout are described in data/README.md.
Tested with Python 3.11 on Linux (CUDA 11.8, 4 × NVIDIA A100-40GB).
git clone https://github.com/sunset222/cypvar-esm.git
cd cypvar-esm
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txttorchrun --nproc_per_node=4 ftesm/train_3task_cwcl.py \
--epochs 200 --lora_lr 2e-5 --other_lr 2e-5 \
--temperature 0.05 --batch_size 8 \
--cwcl_v2l_weight 0.7 --lambda_cls 1.0 --lambda_cwcl 1.0 \
--regression --cwcl_use_diff \
--data_file data/cyp2_family_45pct_cutoff.pkl \
--output_dir runs/ftesm_reg_cwclThe exact hyperparameters used in the paper are wrapped in configs/run_reg_long.sh.
# 10-fold stratified nested CV using pre-extracted FT-ESM + MoleBERT features
python downstream/train_nestedCV.py \
--features data/CYP2D6_variant_FAM_reg_ep200_SWA5_KIT.pkl \
--drug_features data/MoleBERT_Substrate.pkl \
--regressor xgb \
--output runs/downstream_ft_xgbXGBoost hyperparameters are optimized by Bayesian optimization inside the inner CV loop (see downstream/bayesopt_xgb_v4.py).
Please cite the accompanying paper if you use this code:
Released under the MIT License. See LICENSE.