Execute gatk-workflows locally

The Broad Institute have shared their GATK workflows on GitHub, however they are configured to be used with Google Cloud. I was not able to find a lot of information on executing the workflows locally and I only found this tutorial. I ran into problems while trying to follow the tutorial but eventually got it working. This post contains the set of steps I used to run seq-format-validation locally with Docker.

First download and install Docker; if you are new to Docker, I prepared a tutorial. Once you have successfully installed Docker, pull the latest GATK image. I wanted to pull a specific version but noticed that in the WDL file, broadinstitute/gatk:latest is specified. Let’s pull the image and quickly check out the GATK image.

docker pull broadinstitute/gatk:latest

docker run --rm -it broadinstitute/gatk:latest /bin/bash

# which OS is used
cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

# where is GATK installed
which gatk
/gatk/gatk

# Conda is installed too
which conda
/opt/miniconda/envs/gatk/bin/conda

# R is also installed
R --version
R version 3.2.5 (2016-04-14) -- "Very, Very Secure Dishes"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.

I’ll use the same directory structure as the tutorial.

mkdir gatk-workflows
cd gatk-workflows
mkdir inputs

Download this example BAM file (wgs_bam_NA12878_24RG_hg38_NA12878_24RG_small.hg38.bam) from Google Cloud and save it in the inputs folder we just created. You will have to log into your Google account (or make one if you don’t already have an account).

Download Cromwell and store it in the gatk-workflows folder.

wget https://github.com/broadinstitute/cromwell/releases/download/47/cromwell-47.jar

The next step requires Git, so make sure you have that installed. Clone the seq-format-validation workflow into the gatk-workflows folder.

git clone https://github.com/gatk-workflows/seq-format-validation.git

Lastly, modify seq-format-validation/validate-bam.inputs.json so that it looks like the block below (but change the location of wgs_bam_NA12878_24RG_hg38_NA12878_24RG_small.hg38.bam to where you downloaded it on your computer):

{
  "##Comment1":"Input",
  "ValidateBamsWf.bam_array": [ 
    "/Users/dtang/github/gatk-workflows/inputs/wgs_bam_NA12878_24RG_hg38_NA12878_24RG_small.hg38.bam"
  ],
  "##Comment2":"Parameter",
  "ValidateBamsWf.ValidateBAM.validation_mode": "SUMMARY",

  "##Comment3":"Runtime - uncomment the lines below and supply a valid docker container to override the default",
  "ValidateBamsWf.ValidateBAM.machine_mem_gb": "1",  
  "ValidateBamsWf.ValidateBAM.disk_space_gb": "100",
  "#ValidateBamsWf.ValidateBAM.gatk_path_override": "String (optional)",
  "#ValidateBamsWf.gatk_docker_override": "String (optional)"
}

Your directory structure should look something like this:

|-- cromwell-47.jar
|-- inputs
|   `-- wgs_bam_NA12878_24RG_hg38_NA12878_24RG_small.hg38.bam
|-- seq-format-validation
|   |-- LICENSE
|   |-- README.md
|   |-- generic.google-papi.options.json
|   |-- validate-bam.inputs.json
|   `-- validate-bam.wdl

Lastly, make sure you have Java installed (use version 8).

java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Run the following command in the directory gatk-workflows.

java -jar cromwell-47.jar run ./seq-format-validation/validate-bam.wdl --inputs ./seq-format-validation/validate-bam.inputs.json

You should see two new folders: cromwell-executions and cromwell-workflow-logs. Inside cromwell-executions are the outputs generated by the workflow.

cat cromwell-executions/ValidateBamsWf/810afc1e-5b06-4a71-a6e5-65b64a72462d/call-ValidateBAM/shard-0/execution/wgs_bam_NA12878_24RG_hg38_NA12878_24RG_small.hg38.validation_SUMMARY.txt 
No errors found

The directory structure follows the format below.

validate-bam.wdl

This part looks at some specifics of the WDL script. I have written a basic introduction to WDL that may be helpful.

# WORKFLOW DEFINITION
workflow ValidateBamsWf {
  Array[File] bam_array 
  String? gatk_docker_override
  String gatk_docker = select_first([gatk_docker_override, "broadinstitute/gatk:latest"])
  String? gatk_path_override
  String gatk_path = select_first([gatk_path_override, "/gatk/gatk"])

  # Process the input files in parallel
  scatter (input_bam in bam_array) {

    # Get the basename, i.e. strip the filepath and the extension
    String bam_basename = basename(input_bam, ".bam")

    # Run the validation 
    call ValidateBAM {
      input:
        input_bam = input_bam,
        output_basename = bam_basename + ".validation",
        docker = gatk_docker,
        gatk_path = gatk_path
    }
  }

  # Outputs that will be retained when execution is complete
  output {
    Array[File] validation_reports = ValidateBAM.validation_report
  }
}

You can process more than one BAM file at a time by specifying the list of files in the JSON input. These list of files are stored as an array called bam_array.

"ValidateBamsWf.bam_array": [
   # input bam goes here
]

You can also specify a different Docker image that may have GATK installed somewhere else besides /gatk/gatk by setting the override variables in the JSON input. The select_first function will select the first defined value. I have the following two inputs commented out because I was using the Docker image provided by the GATK team.

 "#ValidateBamsWf.ValidateBAM.gatk_path_override": "String (optional)",
  "#ValidateBamsWf.gatk_docker_override": "String (optional)"

Next in the WDL is the scatter call to the ValidateBAM task, which will validate the BAMs in parallel. This tutorial explains how to use scatter-gather to joint call genotypes. The command that is run:

command {
   ${gatk_path} \
      ValidateSamFile \
      --INPUT ${input_bam} \
      --OUTPUT ${output_name} \
      --MODE ${default="SUMMARY" validation_mode}
   }

If you are wondering what the actual Docker command that was run, you can check script.submit in the execution folder.

#!/bin/bash
# make sure there is no preexisting Docker CID file
rm -f /Users/dtang/github/gatk-workflows/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0/execution/docker_cid
# run as in the original configuration without --rm flag (will remove later)
docker run \
  --cidfile /Users/dtang/github/gatk-workflows/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0/execution/docker_cid \
  -i \
   \
  --entrypoint /bin/bash \
  -v /Users/dtang/github/gatk-workflows/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0:/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0:delegated \
  broadinstitute/gatk@sha256:2c0e2ba20c9beb58842ba2149efc29059bc52a5178ce05debf0f38238c0bde86 /cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0/execution/script

# get the return code (working even if the container was detached)
rc=$(docker wait `cat /Users/dtang/github/gatk-workflows/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0/execution/docker_cid`)

# remove the container after waiting
docker rm `cat /Users/dtang/github/gatk-workflows/cromwell-executions/ValidateBamsWf/15000b39-6a1e-4091-8069-3a48305eeb73/call-ValidateBAM/shard-0/execution/docker_cid`

# return exit code
exit $rc

The call-ValidateBAM folder is mounted to the Docker container and the a shell script called script is run.

You can alter the docker run command by specifying a configuration file to Cromwell. I used the following conf file to mount an extra volume to the container (/data/).

# include the application.conf at the top
include required(classpath("application"))

backend {
   default = "Docker"
   providers {
      Docker {
         actor-factory = "cromwell.backend.impl.sfs.config.ConfigBackendLifecycleActorFactory"
         config {

            concurrent-job-limit = 1
            run-in-background = true

            runtime-attributes = """
            String? docker
            String? docker_user
            """
            submit = "/bin/bash ${script}"

            submit-docker = """
            docker run \
               --rm -i \
               ${"--user " + docker_user} \
               --entrypoint /bin/bash \
               -v ${cwd}:${docker_cwd} \
               -v /data/:/data/ \
               ${docker} < ${script}
            """

         }
      }
   }
}
Print Friendly, PDF & Email



Creative Commons License
This work is licensed under a Creative Commons
Attribution 4.0 International License
.
15 comments Add yours
  1. Hello Dave,

    I tried to follow your instructions but am not able to execute the script, could you please help me?

    I did install Docker. Do I have to run docker image – broadinstitute/gatk:latest, before executing the follwing command: java -jar cromwell-47.jar run ./seq-format-validation/validate-bam.wdl –inputs ./seq-format-validation/validate-bam.inputs.json

    Thanks a lot.

    1. Hi Akhil,

      what error did you receive? Do you have the same directory setup as the post? And did you edit the JSON file so that it points to where you downloaded the example BAM file?

      Cheers,
      Dave

      1. Thanks Dave for the reply.

        I did all that you suggested: I did set up the same directory as the post, and I did edit he JSON file as well.

        What I am not able to get is what command in your post is pointing to the Docker image? Do I have to run the Docker image before executing the script. What code in the script is ensuring that Docker image is utilized?

        Thanks

        1. The WDL script specifies that the latest Docker GATK image should be used and Cromwell takes care of the execution; I didn’t have to modify anything.

          Can you ensure that you have successfully pulled the latest GATK image and can run it as a container? Other than that I am not sure what could be the problem.

              1. I get the following output:

                Usage template for all tools (uses –spark-runner LOCAL when used with a Spark tool)
                gatk AnyTool toolArgs

                Usage template for Spark tools (will NOT work on non-Spark tools)
                gatk SparkTool toolArgs [ — –spark-runner sparkArgs ]

                Getting help
                gatk –list Print the list of available tools

                gatk Tool –help Print help on a particular tool

                Configuration File Specification
                –gatk-config-file PATH/TO/GATK/PROPERTIES/FILE

                gatk forwards commands to GATK and adds some sugar for submitting spark jobs

                –spark-runner controls how spark tools are run
                valid targets are:
                LOCAL: run using the in-memory spark runner
                SPARK: run using spark-submit on an existing cluster
                –spark-master must be specified
                –spark-submit-command may be specified to control the Spark submit command
                arguments to spark-submit may optionally be specified after —
                GCS: run using Google cloud dataproc
                commands after the — will be passed to dataproc
                –cluster must be specified after the —
                spark properties and some common spark-submit parameters will be translated
                to dataproc equivalents

                –dry-run may be specified to output the generated command line without running it
                –java-options ‘OPTION1[ OPTION2=Y … ]’ optional – pass the given string of options to the
                java JVM at runtime.
                Java options MUST be passed inside a single string with space-separated values.

  2. Hello Dave,

    I gave your instructions another try and it worked like a charm. Thanks a lot for all the wonderful help you are giving to the bioinformatics community, I really appreciate it.

    Now, coud you please direct me to few good use cases of runnung GATK locally.

    Thanks a lot.

  3. Hi Dave

    I am a newbie in the NGS downstream analysis field. You have very nicely explained each and every step for GATK WDL use. But I have a question: what if I want to run GATK WDL scripts on a remote server without docker being installed. Additionally, I want to use python script to submit my jobs on that server, so how can we use these GATK WDL scripts in python.
    Your help will be highly appreciated!
    AR

    1. Hi AR,

      you don’t have to use Docker but you will have to set up all the programs you need on the server and modify the WDL scripts accordingly. Go through these sets of tutorials https://support.terra.bio/hc/en-us/articles/360037117492-Getting-Started-with-WDL so that you can learn how to modify the WDL scripts.

      You can use Cromwell to submit your jobs on your server; have a look at https://cromwell.readthedocs.io/en/stable/tutorials/HPCIntro/.

      There is a lot to learn and it can become frustrating. You can try to build a simple pipeline first and build up your knowledge. For example, take a look at https://github.com/ecerami/wdl_sandbox.

      Good luck!

      Dave

      1. Thanks a ton Dave!

        Thanks for your quick reply and I am pretty sure these resources will be of great help to me.
        You are doing a great job.

        Cheers!
        AR

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.