Code for the paper:
DNA augmentations for semi-supervised learning in genomic sequence classification
This repository contains implementations of biologically motivated DNA sequence augmentations and the experimental framework used to evaluate them in semi-supervised learning (SSL) settings on genomic sequence classification tasks.
This repository now provides a user-oriented training and inference pipeline for applying DNA augmentation-based SSL methods to custom genomic datasets.
This repository currently supports:
- biologically motivated DNA sequence augmentations
- semi-supervised learning with FixMatch
- semi-supervised learning with FlexMatch
- experiments on:
- AMR
- Oncovirus
Implemented DNA sequence augmentations include:
- reverse complement
- codon back-translation
- nucleotide masking/substitution (
NN) - high-rate mutation
- length-preserving insertion/deletion (
InDel) - combined
InDel + NN
dna-ssl-augmentations/
├── src/
│ ├── augmentations.py
│ ├── common.py
│ ├── fasta_to_csv.py
│ ├── fixmatch_core.py
│ ├── flexmatch_core.py
│ ├── run_amr_fixmatch.py
│ ├── run_amr_flexmatch.py
│ ├── run_oncovirus_fixmatch.py
│ ├── run_oncovirus_flexmatch.py
│ ├── train.py
│ └── inference.py
├── data/
│ ├── amr/
│ └── oncovirus/
├── outputs/
├── requirements.txt
└── README.md
## Installation
Clone the repository and install dependencies:
```bash
git clone https://github.com/EESI/dna-ssl-augmentations.git
cd dna-ssl-augmentations
pip install -r requirements.txt
This package supports training semi-supervised genomic sequence classifiers using your own labeled and unlabeled datasets.
sequence,label
ACGTACGTACGT,0
TTGCAATGCCAA,1sequence
ACGTACGTACGT
TTGCAATGCCAApython src/train.py \
--labeled_csv data/mytask/labeled.csv \
--unlabeled_csv data/mytask/unlabeled.csv \
--val_csv data/mytask/val.csv \
--test_csv data/mytask/test.csv \
--method fixmatch \
--weak_aug nn \
--strong_aug mutation \
--output_dir outputs/my_fixmatch_runpython src/train.py \
--labeled_csv data/mytask/labeled.csv \
--unlabeled_csv data/mytask/unlabeled.csv \
--val_csv data/mytask/val.csv \
--method flexmatch \
--weak_aug nn \
--strong_aug mutation \
--output_dir outputs/my_flexmatch_run--test_csvis optional--weak_augand--strong_augcan be selected from:bt,nn,mutation,indel,indelnn
After training, the following files will be saved in output_dir:
model_state.ptlabel_map.jsontrain_config.json- tokenizer files
Run prediction on new sequences:
python src/inference.py \
--model_dir outputs/my_flexmatch_run \
--input_csv data/mytask/new_sequences.csv \
--output_csv outputs/my_flexmatch_run/predictions.csvIf your sequence column is not named sequence:
python src/inference.py \
--model_dir outputs/my_flexmatch_run \
--input_csv data/mytask/new_sequences.csv \
--sequence_col "DNA Sequence" \
--output_csv outputs/my_flexmatch_run/predictions.csvsequence
ACGTACGTACGT
TTGCAATGCCAAsequence,pred_id,pred_label,pred_confidence,prob_0,prob_1
ACGTACGTACGT,1,1,0.9321,0.0679,0.9321
TTGCAATGCCAA,0,0,0.8812,0.8812,0.1188Semi-supervised fine-tuned models for AMR and Oncovirus classification are available on Zenodo:
https://doi.org/10.5281/zenodo.19671648
Each model archive contains the files required for inference. After downloading and extracting, use the extracted directory as --model_dir.
This repository does not redistribute the datasets.
Please download or prepare the datasets yourself and place them in the following locations.
Expected files:
data/amr/train_6classes.csv
data/amr/val_6classes.csv
data/amr/test_6classes.csv
Expected files:
data/oncovirus/train.csv
data/oncovirus/val.csv
data/oncovirus/test.csv
The AMR datasets used in this project can be obtained from the following sources:
https://drive.google.com/drive/folders/1GSVMmW-T3E0ua94qxzU-lXU3-Ozxp7op?usp=sharing
Each CSV file should contain at least the following columns:
sequence,label
If your sequence column is named DNA Sequence, it will be automatically renamed internally.
python src/run_amr_fixmatch.pypython src/run_amr_flexmatch.pypython src/run_oncovirus_fixmatch.pypython src/run_oncovirus_flexmatch.pyThis repository expects CSV inputs for training and inference. If your data is in FASTA format, you can convert it to the required CSV format using the provided utility script as shown below:
python src/fasta_to_csv.py \
--input_fasta data/mytask/unlabeled.fasta \
--output_csv data/mytask/unlabeled.csv \
--unlabeledOutput:
sequence
ACGTACGTACGT
TTGCAATGCCAAFASTA:
>class0
ACGTACGTACGT
>class1
TTGCAATGCCAA
Command:
python src/fasta_to_csv.py \
--input_fasta data/mytask/labeled.fasta \
--output_csv data/mytask/labeled.csv \
--label-from-headerOutput:
sequence,label
ACGTACGTACGT,class0
TTGCAATGCCAA,class1FASTA:
>seq001|0
ACGTACGTACGT
>seq002|1
TTGCAATGCCAA
Command:
python src/fasta_to_csv.py \
--input_fasta data/mytask/labeled.fasta \
--output_csv data/mytask/labeled.csv \
--header-split-delim "|" \
--label-index 1FASTA:
>seq001 sample=a label=0
ACGTACGTACGT
>seq002 sample=b label=1
TTGCAATGCCAA
Command:
python src/fasta_to_csv.py \
--input_fasta data/mytask/labeled.fasta \
--output_csv data/mytask/labeled.csv \
--label-key labelpython src/fasta_to_csv.py \
--input_fasta data/mytask/labeled.fasta \
--output_csv data/mytask/labeled.csv \
--header-split-delim "|" \
--label-index 1
python src/fasta_to_csv.py \
--input_fasta data/mytask/unlabeled.fasta \
--output_csv data/mytask/unlabeled.csv \
--unlabeled
python src/fasta_to_csv.py \
--input_fasta data/mytask/val.fasta \
--output_csv data/mytask/val.csv \
--header-split-delim "|" \
--label-index 1
python src/fasta_to_csv.py \
--input_fasta data/mytask/test.fasta \
--output_csv data/mytask/test.csv \
--header-split-delim "|" \
--label-index 1FixMatch:
python src/train.py \
--labeled_csv data/mytask/labeled.csv \
--unlabeled_csv data/mytask/unlabeled.csv \
--val_csv data/mytask/val.csv \
--test_csv data/mytask/test.csv \
--method fixmatch \
--weak_aug nn \
--strong_aug mutation \
--output_dir outputs/my_fixmatch_runFlexMatch:
python src/train.py \
--labeled_csv data/mytask/labeled.csv \
--unlabeled_csv data/mytask/unlabeled.csv \
--val_csv data/mytask/val.csv \
--test_csv data/mytask/test.csv \
--method flexmatch \
--weak_aug nn \
--strong_aug mutation \
--output_dir outputs/my_flexmatch_runpython src/fasta_to_csv.py \
--input_fasta data/mytask/new_sequences.fasta \
--output_csv data/mytask/new_sequences.csv \
--unlabeledinference:
python src/inference.py \
--model_dir outputs/my_flexmatch_run \
--input_csv data/mytask/new_sequences.csv \
--output_csv outputs/my_flexmatch_run/predictions.csvThe Auto FASTA Pipeline allows you to use FASTA files directly for training and inference without manually converting them to CSV.
It automatically converts FASTA → CSV internally and runs the existing pipeline.
For labeled FASTA, the label must be an integer placed after a space at the end of the header:
>seq001 0
ACGTACGTACGT
>seq002 1
TTGCAATGCCAA
- The last whitespace-separated token is used as the label
- Labels must be integers (0, 1, 2, ...)
Unlabeled FASTA:
>seq001
ACGTACGTACGT
python src/fasta_auto_pipeline.py \
--mode train \
--labeled_fasta data/labeled.fasta \
--unlabeled_fasta data/unlabeled.fasta \
--val_fasta data/val.fasta \
--test_fasta data/test.fasta \
--method fixmatch \
--weak_aug nn \
--strong_aug mutation \
--output_dir outputs/runpython src/fasta_auto_pipeline.py \
--mode inference \
--input_fasta data/test.fasta \
--model_dir outputs/run \
--output_csv outputs/run/predictions.csv