GATK FILTERMUTECTCALLS

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

Run gatk FilterMutectCalls to filter variants in a Mutect2 VCF callset.

URL: https://gatk.broadinstitute.org/hc/en-us/articles/9570331605531-FilterMutectCalls

Example

This wrapper can be used in the following way:

rule gatk_filtermutectcalls:
    input:
        vcf="calls/snvs.vcf",
        ref="genome.fasta",
    output:
        vcf="calls/snvs.mutect.filtered.vcf",
    log:
        "logs/gatk/filter/snvs.log",
    params:
        extra="--max-alt-allele-count 3",  # optional arguments, see GATK docs
        java_opts="",  # optional
    resources:
        mem_mb=1024,
    wrapper:
        "v3.7.0-10-g491d5b6/bio/gatk/filtermutectcalls"


rule gatk_filtermutectcalls_complete:
    input:
        vcf="calls/snvs.vcf",
        ref="genome.fasta",
        bam="mapped/a.bam",
        intervals="intervals.bed",
        # contamination="", # from gatk CalculateContamination
        # segmentation="", # from gatk CalculateContamination
        # f1r2="", # from gatk LearnReadOrientationBias
    output:
        vcf="calls/snvs.mutect.filtered.b.vcf",
    log:
        "logs/gatk/filter/snvs.log",
    params:
        extra="--max-alt-allele-count 3",  # optional arguments, see GATK docs
        java_opts="",  # optional
    resources:
        mem_mb=1024,
    wrapper:
        "v3.7.0-10-g491d5b6/bio/gatk/filtermutectcalls"

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

Software dependencies

  • gatk4=4.5.0.0

  • snakemake-wrapper-utils=0.6.2

Input/Output

Input:

  • vcf: Path to vcf file (pbgzipped, indexed)

  • ref: Path to reference genome (with .dict file alongside)

  • aln: Optional path to SAM/BAM/CRAM files

  • contamination: Optional path to

  • segmentation: Optional path to tumor segments

  • f1r2: Optional path to prior artefact (tar.gz2)

  • intervels: Optional file to BED intervals

Output:

  • vcf: filtered vcf file

  • stats: Optional stats from Mutect2

Authors

  • Patrik Smeds

  • Filipe G. Vieira

  • Thibault Dayris

Code

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

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

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

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


aln = snakemake.input.get("aln", "")
if aln:
    aln = f"--input {aln}"

contamination = snakemake.input.get("contemination_table", "")
if contamination:
    contamination = f"--contamination-table {contamination}"

segmentation = snakemake.input.get("segmentation", "")
if segmentation:
    segmentation = f"--tumor-segmentation {segmentation}"

f1r2 = snakemake.input.get("f1r2", "")
if f1r2:
    f1r2 = f"--orientation-bias-artifact-priors {f1r2}"

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

with tempfile.TemporaryDirectory() as tmpdir:
    shell(
        "gatk --java-options '{java_opts}' FilterMutectCalls"
        " --variant {snakemake.input.vcf}"
        " --reference {snakemake.input.ref}"
        " {aln}"  # BAM/SAM/CRAM file containing reads
        " {contamination}"  # Tables containing contamination information
        " {segmentation}"  # Tumor segments' minor allele fractions
        " {f1r2}"  # .tar.gz files containing tables of prior artifact
        " {intervals}"  # Genomic intervals over which to operate
        " {extra}"
        " --tmp-dir {tmpdir}"
        " --output {snakemake.output.vcf}"
        " {log}"
    )