A 1D convolutional neural network that classifies DNA sequences as either accessible (positive) or non-accessible (negative). Built on top of preprocessed DNase-seq data from ENCODE.
Project 2 layers experiment automation, TensorBoard tracking, and a frozen-backbone transfer-learning experiment on top of the Project 1 model.
pip install -r requirements.txt
The runner expects two organ datasets:
data/
all_positive.txt # source organ, accessible sequences
all_negative.txt # source organ, non-accessible sequences
brain/
positive.txt # target organ for transfer learning
negative.txt
Every file has one DNA sequence per line. All sequences in a file should be the same length (the runner infers that length from the source file).
If you need to (re)build these from BED files, the original preprocessing scripts are still here:
python preprocess_dnase.py --bed experiment.bed --genome /path/to/GRCh38.fa --outdir data/<organ>
python preprocess_dnase_multi.py --beds f1.bed f2.bed --genome /path/to/GRCh38.fa --outdir data/<organ>
A single command runs all five Project 2 tasks end-to-end:
python run.py
It will:
- Grid-search across learning rates, batch sizes, and dropouts (Tasks 1-4).
- Save the best-by-test-accuracy checkpoint to
results/best_dna_cnn.pth. - Load that checkpoint, freeze the convolutional backbone, replace the classifier head, and fine-tune on the target organ for 5 epochs (Task 5).
All knobs live in the CONFIG dictionary at the top of run.py. Edit the dict, save, and run again — there are no command-line flags to remember.
tensorboard --logdir runs
Each grid run lives under runs/lr_<lr>_bs_<bs>_drop_<drop>/ and the transfer run under runs/transfer/. The HPARAMS tab shows final test accuracy/loss/precision/recall side-by-side across all combinations.
results/
best_dna_cnn.pth # global best state_dict from the grid search (Task 4)
grid_summary.json # final metrics for every grid combination
transfer_model.pth # fine-tuned model from Task 5
transfer_metrics.json # final transfer-learning metrics
runs/
lr_<lr>_bs_<bs>_drop_<drop>/ # per-run TensorBoard logs and checkpoint
transfer/ # transfer-learning TensorBoard logs
| File | Purpose |
|---|---|
run.py |
Single entry point. Runs tasks 1-5 end-to-end based on CONFIG. |
model.py |
DNAAccessibilityCNN - 3 Conv1d layers + 2 FC layers. |
dataset.py |
DNATxtDataset and a helper that builds train/test loaders. |
preprocess_dnase.py / preprocess_dnase_multi.py |
Convert ENCODE BED files into the positive.txt/negative.txt files used here. |
- Task 1 - TensorBoard integration.
run.pylogsLoss/train,Loss/test, andAccuracy/testevery epoch and writes the model graph withwriter.add_graph. - Task 2 - Grid search. Three hyperparameters (learning rate, batch size, dropout) are swept via
itertools.product. Each combination logs to its ownruns/lr_*_bs_*_drop_*/directory and final metrics are written to the HParams tab. - Task 3 - Confusion matrix, precision, recall. Computed at the end of every run, the figure is pushed via
writer.add_figure, and precision/recall are logged as scalars and saved to JSON. - Task 4 - Save best model. Whenever a new epoch beats the running best test accuracy the model
state_dictis written to disk. The best run's checkpoint is promoted toresults/best_dna_cnn.pth. - Task 5 - Frozen backbone.
run_transfer_learningloadsbest_dna_cnn.pth, setsrequires_grad=Falseonmodel.features, replacesmodel.classifierwith a fresh head, and trains for 5 epochs on a different organ. Trainable parameter counts are printed before and after freezing to confirm only the head updates, and everything is logged to TensorBoard.