This notebook shows how to retrain DeepVariant models using Parabricks.
Retraining DeepVariant using Parabricks
In this lab we will use Parabricks and DeepVariant to retrain a DeepVariant model on new data.
What is Parabricks?
NVIDIA Parabricks® is the only GPU-accelerated computational genomics toolkit that delivers fast and accurate analysis for sequencing centers, clinical teams, genomics researchers, and next-generation sequencing instrument developers. Parabricks provides GPU-accelerated versions of tools used every day by computational biologists and bioinformaticians—enabling significantly faster runtimes, workflow scalability, and lower compute costs.
The toolkit includes full compatibility with workflow languages and managers (WDL, NextFlow, Cromwell) to easily intertwine GPU- and CPU-powered tasks, as well as support for easy cloud deployment (AWS, GCP, Terra, and DNAnexus).
What is DeepVariant?
DeepVariant, developed by Google, is a deep learning-based variant caller that takes aligned reads, produces pileup image tensors from them, classifies each tensor using a convolutional neural network, and then outputs the results in a VCF or gVCF file.
Package dependencies
There are a few tools we need to install to successfully run this lab. They can be installed by running the cells below.
To run a cell, you can either click into it and hit Ctrl+Enter or you can hit the Run button on the top toolbar.
DeepVariant baseline performance
DeepVariant comes with a generic, baseline model for WGS data. Let's see the baseline performance on our test data (Chromosome 20 from HG001).
Let's compare the baseline VCF to the groundtruth VCF and see what the accuracy looks like.
Let's look at the accuracy of the baseline WGS model on our dataset. For this, we can cat the baseline_hap.log file to see what hap.py generated.
The performance here is pretty good. The goal of the baseline WGS model is to do well across a wide spectrum of data. However, we can retrain this WGS model to perform better for our specific use case.
Building a dataset to retrain DeepVariant
To retrain the WGS baseline model, we need a dataset to train on.
We will use Chromosome 1 from HG001 to generate a training dataset.
We will use Chromosome 21 from HG001 to generate a validation dataset.
Shuffling the training data
Before we can train the model we will need to shuffle each set of examples and generate a data config file. This has to be done for both the training and validation dataset.
Training the DeepVariant model
Next we want to run the following two code blocks at the same time to train and evaluate the different possible models.
This first cell will constantly check the training_dir folder for new model checkpoints. When a new model checkpoint is generated by the training script, it will evaluate the checkpoint and keep track of which checkpoint performs the best.
This cell kicks off the DeepVariant training.
Choose the best model
We then want to pick the best mdoel. We can determine which model to use by running the line of code below.
Let's cat the file training_dir/best_checkpoint.txt
Re-run DeepVariant using this new model
Now that we know which model checkpoint performed the best, we can use this model to run DeepVariant on Chromosome 20 again, but this time, swap out the BEST_CHECKPOINT variable for your best performing model checkpoint.
Evaluate the performance
Lastly, we can evaluate the performance of our DeepVariant model using hap.py and compare to the performance to the baseline model.
Let's cat the retrained_hap.log to see the accuracy metrics.
Conclusion
Congratulations! You have now successfully retrained DeepVariant on new data and evaluated the performance compared to a baseline. Now you can take this knowledge and try it on your own data to see if you can get better results.