How lab-of-biochemai/deepsems works
1. Repository purpose
DeepSeMS is an offline inference-and-training repository for a Transformer model that predicts SMILES chemical structures from biosynthetic gene cluster (BGC) annotations. The core architectural split is between data preparation, sequence-to-sequence model inference, and optional chemistry post-processing.
2. Primary user-facing entry points
The main executable paths are:
- predict.py for single-BGC prediction
- train.py for model training
- calculate_molecular_properties.py for post-processing predicted molecules
These scripts are the orchestration layer; most of the logic beneath them is shared across preprocessing, tokenization, and model code.
3. Input boundary: annotated BGC files, not raw genomes
The model does not take raw genome FASTA directly. It expects BGC annotations from:
- antiSMASH in GenBank format
- DeepBGC in FASTA format
This is an important architecture boundary: external annotation tools sit upstream of DeepSeMS.
4. Preprocessing and feature extraction layer
data_processing.py likely handles conversion of BGC annotations into model-ready features. The README also requires a Pfam database and hmmer, which implies the preprocessing layer maps BGC elements to Pfam/domain features before inference. That makes Pfam/HMMER an external bioinformatics dependency in the input pipeline.
5. Tokenization and vocabularies
tokenizer/tokenizer.py and the vocabs/ directory define the symbolic interface used by the model:
- vocabs/bgc_features_vocab.csv for BGC-side features
- vocabs/smiles-vocab.pt for SMILES tokenization
This is the translation boundary between biological annotations and the Transformer’s discrete token space.
6. Core model subsystem
models/Transformer.py contains the neural architecture. Based on the repo description, this is a PyTorch Transformer-based sequence model that maps BGC-derived token sequences to SMILES token sequences. The model is the central computational boundary between biological input features and chemical output strings.
7. Ensemble inference and checkpointing
checkpoints/ stores pretrained weights, and the README describes top-10 submodels whose predictions are combined. So inference is not a single model pass; it is an ensemble/ranking pipeline over multiple checkpoints, producing a consensus score and confidence-like score for each candidate SMILES.
8. Prediction flow
predict.py is the runtime orchestrator:
- reads one annotated BGC file
- preprocesses and tokenizes it
- loads the model checkpoint ensemble
- generates candidate SMILES
- ranks them by model score and consensus
- writes a result CSV under test/outputs/
This script is the main diagram node for end-to-end inference.
9. Output artifacts
The primary output is a CSV result file containing ranked predictions with:
- predicted SMILES
- predicted score
- consensus count
The output directory is structured per input file, so prediction results are file-scoped rather than stored in a centralized database or service.
10. Optional chemistry post-processing
calculate_molecular_properties.py is a downstream analysis step that operates on DeepSeMS result CSVs. It depends on RDKit and the separately downloaded SA score resources (sascorer.py, fpscores.pkl.gz) to compute molecular properties after prediction, not during model inference.
11. Training data and offline model development
train.py and data/data_set.csv support the training path. This is a separate subsystem from inference, using the same tokenization/vocabulary assets but reading from a curated dataset rather than user-supplied BGC files. The presence of checkpoints indicates trained models are serialized back into checkpoints/.
12. Environment and reproducibility
environment.yml captures the local Conda environment, while the README also recommends Docker for reproducible execution. The repo is therefore designed around a portable offline scientific ML workflow rather than a long-running service architecture.
13. External dependencies that matter architecturally
The major runtime dependencies are:
- PyTorch/TorchText for the Transformer and decoding
- HMMER + Pfam for annotation/domain feature mapping
- Biopython for parsing biological file formats
- RDKit for chemical property calculations
These libraries define the boundaries between biological parsing, ML inference, and chemical analysis.
14. High-level data flow
The end-to-end flow is:
annotated BGC file → preprocessing/Pfam feature extraction → tokenization → Transformer ensemble inference → ranked SMILES output → optional molecular property calculation.
For an architecture diagram, the main subsystems to show are: input annotations, preprocessing/tokenization, model ensemble, result ranking/output, and optional post-processing.
Main entry points: train.py train.py · data_processing.py Prep · predict.py predict.py · tokenizer.py Tokenizer
Components 17
Inference Pipeline
Single-BGC prediction flow from annotated input to ranked SMILES output.
- predict.py · Entry point for end-to-end single-BGC inference.
predict.py - Prep · Converts annotated BGC files into model-ready features.
data_processing.py - Tokenizer · Maps biological features and SMILES symbols into discrete token sequences.
tokenizer/tokenizer.py - Transformer · PyTorch model that generates SMILES tokens from BGC tokens.
models/Transformer.py - Checkpoint · Pretrained model weights used during inference.
checkpoints/checkpoint.ckpt - Ranked CSV · Final prediction file with SMILES, scores, and consensus counts.
- Ensemble · Top-k checkpoint scoring and consensus-based ranking during inference.
Training
Offline model development and checkpoint generation.
Post-processing
Optional chemical property calculation on prediction outputs.
- Props · Post-processing script that computes molecular properties from prediction CSVs.
calculate_molecular_properties.py - RDKit/SA · Chemical analysis dependencies including RDKit and SA score resources.
Assets
Vocabulary, dataset, and checkpoint artifacts used by the model.
- BGC vocab · Vocabulary of BGC-side features used by preprocessing and tokenization.
vocabs/bgc_features_vocab.csv - SMILES vocab · Token vocabulary for SMILES decoding and generation.
vocabs/smiles-vocab.pt
External Tools
Upstream annotation and runtime dependencies outside the repository.
- BGC files · Accepted annotated inputs from antiSMASH GenBank or DeepBGC FASTA files.
test/antiSMASH_example.gbk - antiSMASH · External tool producing annotated GenBank BGC input.
- DeepBGC · External tool producing annotated FASTA BGC input.
test/DeepBGC_example.fa - HMMER/Pfam · External feature-mapping layer for domain and Pfam-based preprocessing.
Connections 18
- antiSMASH → BGC files: produces · Generates annotated GenBank BGC files.
- DeepBGC → BGC files: produces · Generates annotated FASTA BGC files.
- BGC files → predict.py: input · Single annotated BGC file is passed to inference.
- predict.py → Prep: calls · Runs preprocessing on the annotated input.
- Prep → HMMER/Pfam: uses · Maps BGC elements to Pfam/domain features.
- Prep → BGC vocab: encodes · Looks up biological feature symbols.
- Prep → Tokenizer: passes · Hands preprocessed features to tokenization.
- Tokenizer → SMILES vocab: uses · Consumes SMILES token vocabulary for decoding space.
- predict.py → Ensemble: orchestrates · Coordinates multi-checkpoint candidate generation and ranking.
- Ensemble → Checkpoint: loads · Uses pretrained weights for scoring.
- Ensemble → Transformer: runs · Executes the seq2seq Transformer for candidate generation.
- Transformer → Ranked CSV: writes · Produces ranked SMILES predictions and scores.
- train.py → Dataset: reads · Consumes curated training pairs.
- train.py → Tokenizer: reuses · Shares tokenization logic with inference.
- train.py → Transformer: fits · Trains the Transformer architecture.
- train.py → Checkpoint: saves · Serializes trained weights to checkpoint storage.
- Props → Ranked CSV: reads · Consumes prediction CSVs for analysis.
- Props → RDKit/SA: uses · Computes molecular properties and synthetic accessibility metrics.