Skip to content

JacobMitchell088/Deep-Learning-DNA-Accessibility

Repository files navigation

CS490 - Deep Learning for DNA Accessibility Prediction (Project 2)

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.

Install

pip install -r requirements.txt

Data layout

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>

Running everything

A single command runs all five Project 2 tasks end-to-end:

python run.py

It will:

  1. Grid-search across learning rates, batch sizes, and dropouts (Tasks 1-4).
  2. Save the best-by-test-accuracy checkpoint to results/best_dna_cnn.pth.
  3. 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

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.

What gets saved

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

Files

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.

Mapping to the project rubric

  • Task 1 - TensorBoard integration. run.py logs Loss/train, Loss/test, and Accuracy/test every epoch and writes the model graph with writer.add_graph.
  • Task 2 - Grid search. Three hyperparameters (learning rate, batch size, dropout) are swept via itertools.product. Each combination logs to its own runs/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_dict is written to disk. The best run's checkpoint is promoted to results/best_dna_cnn.pth.
  • Task 5 - Frozen backbone. run_transfer_learning loads best_dna_cnn.pth, sets requires_grad=False on model.features, replaces model.classifier with 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.

About

To build and train/evaluate a 5-layer 1D CNN to classify DNA sequences as either accessible (positive) or non-accessible (negative). Built off of preprocessed data created with: https://github.com/JacobMitchell088/CS490_Assignment1

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages