GATK PRINTREADSSPARK

Write reads from SAM format file (SAM/BAM/CRAM) that pass specified criteria to a new file. This is the version that can be run on Spark.

URL:

Example

This wrapper can be used in the following way:

rule gatk_printreadsspark:
    input:
        bam="mapped/{sample}.bam",
        ref="genome.fasta",
        dict="genome.dict",
    output:
        bam="{sample}.bam",
    log:
        "logs/{sample}.log",
    params:
        extra="",  # optional
        java_opts="",  # optional
        #spark_runner="",  # optional, local by default
        #spark_v1.2.0="",  # optional
        #spark_extra="", # optional
    resources:
        mem_mb=1024,
    threads: 8
    wrapper:
        "v1.2.0/bio/gatk/printreadsspark"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • gatk4=4.2
  • openjdk=8
  • snakemake-wrapper-utils=0.2

Input/Output

Input:

  • bam file
  • reference file
  • reference dict

Output:

  • filtered bam file

Notes

  • The java_opts param allows for additional arguments to be passed to the java compiler, e.g. “-XX:ParallelGCThreads=10” (not for -XmX or -Djava.io.tmpdir, since they are handled automatically).
  • The extra param allows for additional program arguments for printreadsspark.
  • The spark_runner param = “LOCAL”|”SPARK”|”GCS” allows to set the spark_runner. Set the parameter to “LOCAL” or don’t set it at all to run on local machine.
  • The spark_master param allows to set the URL of the Spark Master to submit the job. Set to “local[number_of_cores]” for local execution. Don’t set it at all for local execution with number of cores determined by snakemake.
  • The spark_extra param allows for additional spark arguments.
  • For more information see, https://gatk.broadinstitute.org/hc/en-us/articles/360057441531-PrintReadsSpark

Authors

  • Filipe G. Vieira

Code

__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2021, Filipe G. Vieira"
__license__ = "MIT"

import tempfile
from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts

log = snakemake.log_fmt_shell(stdout=True, stderr=True)

extra = snakemake.params.get("extra", "")
spark_runner = snakemake.params.get("spark_runner", "LOCAL")
spark_master = snakemake.params.get(
    "spark_master", "local[{}]".format(snakemake.threads)
)
spark_extra = snakemake.params.get("spark_extra", "")
java_opts = get_java_opts(snakemake)


with tempfile.TemporaryDirectory() as tmpdir:
    shell(
        "gatk --java-options '{java_opts}' PrintReadsSpark"
        " --input {snakemake.input.bam}"
        " --reference {snakemake.input.ref}"
        " {extra}"
        " --tmp-dir {tmpdir}"
        " --output {snakemake.output.bam}"
        " -- --spark-runner {spark_runner} --spark-master {spark_master} {spark_extra}"
        " {log}"
    )