GATK BASERECALIBRATOR

Run gatk BaseRecalibrator and ApplyBQSR in one step.

Software dependencies

  • gatk4 ==4.0.5.1

Example

This wrapper can be used in the following way:

rule gatk_bqsr:
    input:
        bam="mapped/{sample}.bam",
        ref="genome.fasta",
        known="dbsnp.vcf.gz"
    output:
        bam="recal/{sample}.bam"
    log:
        "logs/gatk/bqsr/{sample}.log"
    params:
        extra="",  # optional
    wrapper:
        "0.27.1/bio/gatk/baserecalibrator"

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.

Authors

  • Johannes Köster

Code

__author__ = "Johannes Köster"
__copyright__ = "Copyright 2018, Johannes Köster"
__email__ = "johannes.koester@protonmail.com"
__license__ = "MIT"


from tempfile import TemporaryDirectory
import os

from snakemake.shell import shell

extra = snakemake.params.get("extra", "")

with TemporaryDirectory() as tmpdir:
    recal_table = os.path.join(tmpdir, "recal_table.grp")
    log = snakemake.log_fmt_shell(stdout=True, stderr=True)
    shell("gatk BaseRecalibrator {extra} "
          "-R {snakemake.input.ref} -I {snakemake.input.bam} "
          "-O {recal_table} --known-sites {snakemake.input.known} {log}")

    log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True)
    shell("gatk ApplyBQSR -R {snakemake.input.ref} -I {snakemake.input.bam} "
          "--bqsr-recal-file {recal_table} "
          "-O {snakemake.output.bam} {log}")