- Overview
- Key Features
- Architecture
- Installation
- Quick Start
- Training
- Inference
- SPEA Fine-Tuning
- Project Structure
- Citation
MPCG-Codon is a deep-learning framework for intelligent codon optimization that goes beyond traditional frequency-based methods. By integrating multi-modal biological priors, physics-constrained attention mechanisms, and neural RNA structure prediction, MPCG-Codon generates codon sequences optimized for heterologous protein expression across multiple host organisms.
The framework currently supports five model organisms:
- ๐ง Homo sapiens (Human)
- ๐ญ Mus musculus (Mouse)
- ๐ฆ Escherichia coli (E. coli)
- ๐ Saccharomyces cerevisiae (Yeast)
- ๐งซ Pichia angusta (Methylotrophic yeast)
MPCG-Codon introduces a novel Physics-Constrained Attention mechanism that injects biological structure directly into the Transformer architecture:
- RNA secondary-structure pairing matrices guide local attention patterns
- Ribosomal pause probabilities modulate positional importance
- Translation-time-aware positional encodings replace naive sequence-position embeddings
An embedded NeuralRNAFolder predicts minimum free energy (MFE) and base-pairing probabilities from nucleotide sequences, enabling structure-aware loss terms during training.
A dedicated submodule estimates tRNA abundanceโmediated elongation rates and ribosomal pause probabilities, allowing the model to optimize for smooth translation kinetics.
The training objective combines eight complementary loss terms:
| Loss Component | Description |
|---|---|
CE |
Cross-entropy against natural coding sequences |
CAI |
Codon Adaptation Index alignment |
RSCU |
Relative Synonymous Codon Usage divergence |
GC |
GC-content regularization |
Structure |
RNA folding energy guidance |
Dynamics |
Ribosomal pause penalty |
Rare Codon |
Conservation of rare-codon clusters |
Manufacturability |
Repeat & homopolymer avoidance |
For E. coli secretion proteins, MPCG provides a specialized fine-tuning stack:
- Signal-peptide-aware adapter with cleavage-site prediction
- Disulfide-bond optimization module with redox-environment modeling
- Solubility optimization with aggregation-prediction and tag recommendations
The architecture consists of three hierarchical levels:
- Base Encoder (
MPCG-BaseCodonFormer.py) โ Sparse-attention Transformer with multi-scale convolutions and biological feature extraction. - Core Model (
MPCG-CoreModel.py) โ Physics-constrained layers, neural RNA folder, translation dynamics, and five-species codon priors. - SPEA Adapter (
MPCG-SPEA-Modules.py) โ Task-specific modules for signal peptides, disulfide bonds, and solubility.
# Clone the repository
git clone https://github.com/firefly-hefeng/MPCG.git
cd MPCG
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtFor exact RNA MFE calculations, install ViennaRNA via Conda:
conda install -c bioconda viennarnaIf ViennaRNA is unavailable, the model falls back to the internal NeuralRNAFolder.
python pridict.py \
--checkpoint checkpoints/best.pt \
--species "Escherichia coli" \
--protein "MKTLLIL*" \
--output optimized.fastapython pridict.py \
--checkpoint checkpoints/best.pt \
--species "Saccharomyces cerevisiae" \
--fasta input_sequences.fasta \
--output_format fasta \
--output predictions.fastapython pridict.py \
--checkpoint checkpoints/best.pt \
--species "Pichia angusta" \
--csv sequences.csv \
--output predictions.csv \
--output_format csvYour CSV should contain at least three columns:
RefSeq_aaโ Amino-acid sequences (include*for stop codons)RefSeq_nnโ Native nucleotide sequences (coding DNA)Organismโ Host organism name (must match one of the five supported species)
python train.py \
--data_csv your_data.csv \
--d_model 512 \
--n_layers 12 \
--n_heads 8 \
--batch_size 8 \
--lr 1e-4 \
--epochs 50 \
--save_dir ./checkpoints \
--wandb| Argument | Default | Description |
|---|---|---|
--d_model |
512 | Transformer embedding dimension |
--n_layers |
12 | Number of Transformer layers |
--n_heads |
8 | Attention heads |
--batch_size |
8 | Batch size |
--lr |
1e-4 | Peak learning rate |
--warmup_steps |
4000 | Linear warmup steps |
--weight_ce |
1.0 | Cross-entropy weight |
--weight_cai |
0.4 | CAI loss weight |
--weight_rscu |
0.3 | RSCU loss weight |
--wandb |
โ | Enable Weights & Biases logging |
Low-level inference via mpcg_inference.py:
python mpcg_inference.py \
--checkpoint checkpoints/best.pt \
--protein "MKTLLIL*" \
--species "Escherichia coli" \
--temperature 1.0 \
--output result.fastaFor programmatic usage:
from pridict import CodonPredictor
predictor = CodonPredictor("checkpoints/best.pt")
result = predictor.predict_single("MKTLLIL*", "Escherichia coli")
print(result['optimized_dna'])The Secretion Protein Expression Adapter (SPEA) is designed for E. coli periplasmic expression of complex proteins (e.g., antibodies, disulfide-rich scaffolds).
python MPCG-SPEA-Finetune.py \
--pretrained_model checkpoints/best.pt \
--data_file secretion_data.csv \
--output_dir ./spea_checkpoints \
--epochs 20 \
--batch_size 4 \
--freeze_base \
--n_augment 50SPEA modules include:
SecretionSignalAdapterโ Optimizes signal-peptide coding regions and predicts cleavage sitesDisulfideBondAwareModuleโ Enhances cysteine-adjacent codons for correct oxidative foldingSolubilityOptimizationModuleโ Predicts aggregation risk and recommends solubility tags (MBP, SUMO, TRX, GST)
MPCG/
โโโ docs/
โ โโโ structure.png # Architecture diagram
โโโ MPCG-BaseCodonFormer.py # Sparse-attention base encoder
โโโ MPCG-BioPriorLoss.py # Biologically informed loss functions
โโโ MPCG-CoreModel.py # Core MPCG model & 5-species priors
โโโ MPCG-SPEA-Modules.py # SPEA adapter modules
โโโ MPCG-SPEA-Finetune.py # SPEA fine-tuning script
โโโ MPCG-SPEA-DataPrep.py # SPEA data preparation (placeholder)
โโโ mpcg_inference.py # Standalone inference script
โโโ pridict.py # One-click prediction CLI
โโโ train.py # Main training pipeline
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
If you use MPCG-Codon in your research, please cite:
@software{mpcg_codon,
author = {firefly-hefeng},
title = {MPCG-Codon: Multi-Modal Physics-Constrained Guided Codon Optimization},
url = {https://github.com/firefly-hefeng/MPCG},
year = {2025}
}Made with โค๏ธ for synthetic biology and protein engineering.
