Skip to content

Repository files navigation

CAMP-RL

CAMP-RL is a deep learning project for antimicrobial peptide (AMP) sequence generation and optimization. The main model is a conditional Transformer-VAE that learns latent representations of peptide sequences, then applies reinforcement learning with AMP/MIC classifier rewards to bias generated sequences toward desired antimicrobial and MIC-related properties.

Features

  • Train a Transformer-VAE on amino acid sequences.
  • Use amp_label and mic_label as conditional controls during reconstruction and generation.
  • Use pretrained AMP/MIC classifiers as reward models during RL fine-tuning.
  • Evaluate reconstruction quality with token accuracy and average Levenshtein distance.
  • Generate candidate antimicrobial peptide sequences from random latent vectors.

Project Structure

CAMP-RL/
├── main.py                         # Main entry: VAE pretraining + RL fine-tuning + evaluation
├── model.py                        # Transformer-VAE, VAE loss, RL loss
├── data_loader.py                  # CSV dataset loading and peptide tokenization
├── evaluate_vae.py                 # Reconstruction evaluation and sequence generation
├── utils.py                        # Batch utilities, loss plotting, helper functions
├── discriminator.py                # Discriminator-related model code
├── data/
│   ├── train_dataset.csv           # Training set
│   ├── test_dataset.csv            # Test set
│   ├── val_dataset.csv             # Validation set
│   └── mic_data.csv                # MIC classifier training data
├── classifier_utils/
│   ├── classifiers.py              # AMP/MIC classifier model and training script
│   ├── AMP_Classifier.pt           # AMP classifier weights
│   └── MIC_Classifier.pt           # MIC classifier weights
├── attribute_util/                 # Post-generation attribute evaluation utilities
├── checkpoints/                    # Training logs and model checkpoints
├── cd-hit/                         # Sequence clustering/deduplication utilities
└── plddt/                          # pLDDT results and visualization files

Environment

Python 3.8/3.9 with a CUDA-enabled PyTorch environment is recommended for training. Core dependencies:

pip install torch pandas numpy matplotlib scikit-learn python-Levenshtein

If you need to run the post-generation attribute evaluation tools under attribute_util/, you may also need:

pip install tensorflow keras keras-preprocessing tensorflow-probability biopython modlamp seaborn tqdm joblib

Note: some code under attribute_util/ imports modules using amp as the package name. Run those scripts from the attribute_util/ directory, or add that directory to PYTHONPATH.

Data Format

data_loader.py expects the training/test CSV files to contain at least the following columns:

Column Description
sequence Amino acid sequence. Supported alphabet: ACDEFGHIKLMNPQRSTVWY
amp_label AMP activity label. Usually 1 for positive samples and 0 for negative samples
mic_label MIC-related binary label. Usually 1 if the MIC threshold condition is satisfied, otherwise 0

Example:

sequence,amp_label,mic_label
VTSWSLCTPGCTSPGGGSNCSFCC,1,0
MQIFVKTLTGKTITLEVEA,0,0

Quick Start

Enter the project directory:

cd ./CAMP-RL

Run the full training pipeline:

python main.py

main.py performs the following steps:

  1. Load ./data/train_dataset.csv and ./data/test_dataset.csv.
  2. Train the conditional Transformer-VAE.
  3. Save pretrained weights to ./checkpoints/<timestamp>/Pretrain_VAE.pt.
  4. Evaluate reconstruction on the test set.
  5. Fine-tune the model with AMP/MIC classifier rewards.
  6. Save RL-fine-tuned weights to ./checkpoints/<timestamp>/RL_VAE.pt.

Training logs are written to:

checkpoints/<timestamp>/training.log

If your machine uses a different GPU index, or if you want to run on CPU or another GPU, update this line before training.

Model Overview

Transformer-VAE

Transformer_VAE in model.py contains:

  • token embedding and sinusoidal positional encoding;
  • a Transformer encoder for input sequence encoding;
  • latent mean/log variance layers for sampling latent vector z;
  • conditional control by concatenating z, amp_label, and mic_label;
  • a Transformer decoder for autoregressive reconstruction/generation.

Sequence Generation

evaluate_vae.py provides a generate function that samples candidate sequences from random latent vectors and scores them with AMP/MIC models from attribute_util.

The script currently calls:

generate("generated", "./checkpoints/RL_VAE.pt")

However, main.py saves checkpoints under a timestamped directory:

./checkpoints/<timestamp>/RL_VAE.pt

Before running generation separately, update the path to the actual trained checkpoint, or copy the checkpoint to ./checkpoints/RL_VAE.pt.

Generated sequences are appended to:

CAMP_RL_positive.csv

Classifier Training

classifier_utils/classifiers.py can train the AMP and MIC classifiers:

cd classifier_utils
python classifiers.py

This script:

  • trains the AMP classifier from Classifier_train.csv;
  • builds MIC classifier data from ../data/mic_data.csv plus AMP negative samples;
  • saves AMP_Classifier.pt and MIC_Classifier.pt.

The main training pipeline depends on these two weight files. If they are missing, main.py will fail when loading the classifiers.

Notes

  • Run main.py from the CAMP-RL/ directory because many paths are relative.
  • The current code does not use command-line arguments. Data paths, epochs, and model hyperparameters are edited directly in source files.
  • Each main.py run creates a new checkpoints/<timestamp>/ directory.
  • The default checkpoint path in evaluate_vae.py does not exactly match the timestamped path used by main.py; adjust it manually when running generation or standalone evaluation.
  • plt.show() may block or fail on headless servers. If this happens, set the matplotlib backend to Agg at the beginning of the script.
  • The repository contains __pycache__, training logs, model weights, and notebook outputs. Clean them as needed before packaging or releasing the project.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages