GATK3 BASERECALIBRATOR

https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/gatk3/baserecalibrator?label=version%20update%20pull%20requests

Run gatk3 BaseRecalibrator.

Example

This wrapper can be used in the following way:

rule baserecalibrator:
    input:
        bam="{sample}.bam",
        bai="{sample}.bai",
        ref="genome.fasta",
        fai="genome.fasta.fai",
        dict="genome.dict",
        known="dbsnp.vcf.gz",
        known_idx="dbsnp.vcf.gz.tbi",
    output:
        recal_table="{sample}.recal_data_table",
    log:
        "logs/gatk3/bqsr/{sample}.log",
    params:
        extra="--defaultBaseQualities 20 --filter_reads_with_N_cigar",  # optional
    resources:
        mem_mb=1024,
    threads: 16
    wrapper:
        "v1.21.4-1-g701abe08/bio/gatk3/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.

Notes

  • The java_opts param allows for additional arguments to be passed to the java compiler, e.g. “-Xmx4G” for one, and “-Xmx4G -XX:ParallelGCThreads=10” for two options.
  • The extra param allows for additional program arguments.
  • For more information see, https://software.broadinstitute.org/gatk/documentation/article?id=11050
  • Gatk3.jar is not included in the bioconda package, i.e it need to be added to the conda environment manually.

Software dependencies

  • gatk=3.8
  • python>=3.10
  • snakemake-wrapper-utils=0.5

Input/Output

Input:

  • bam file
  • vcf files
  • reference genome

Output:

  • recalibration table

Authors

  • Patrik Smeds

Code

__author__ = "Patrik Smeds"
__copyright__ = "Copyright 2019, Patrik Smeds"
__email__ = "patrik.smeds@gmail.com.com"
__license__ = "MIT"

import os

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

extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
java_opts = get_java_opts(snakemake)


bed = snakemake.params.get("bed", "")
if bed:
    bed = f"--intervals {bed}"


input_known = snakemake.input.get("known", "")
if input_known:
    if isinstance(input_known, str):
        input_known = [input_known]
    input_known = list(map("--knownSites {}".format, input_known))


shell(
    "gatk3 {java_opts}"
    " --analysis_type BaseRecalibrator"
    " --num_cpu_threads_per_data_thread {snakemake.threads}"
    " --input_file {snakemake.input.bam}"
    " {input_known}"
    " --reference_sequence {snakemake.input.ref}"
    " {bed}"
    " {extra}"
    " --out {snakemake.output}"
    " {log}"
)