SNPEFF

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

Annotate predicted effect of nucleotide changes with SnpEff.

URL: https://pcingola.github.io/SnpEff/se_introduction/

Example

This wrapper can be used in the following way:

rule snpeff:
    input:
        calls="{sample}.vcf", # (vcf, bcf, or vcf.gz)
        db="resources/snpeff/ebola_zaire" # path to reference db downloaded with the snpeff download wrapper
    output:
        calls="snpeff/{sample}.vcf",   # annotated calls (vcf, bcf, or vcf.gz)
        stats="snpeff/{sample}.html",  # summary statistics (in HTML), optional
        csvstats="snpeff/{sample}.csv" # summary statistics in CSV, optional
    log:
        "logs/snpeff/{sample}.log"
    resources:
        java_opts="-XX:ParallelGCThreads=10",
        mem_mb=4096
    wrapper:
        "v3.10.2-32-gf4e5b66/bio/snpeff/annotate"

rule snpeff_nostats:
    input:
        calls="{sample}.vcf",
        db="resources/snpeff/ebola_zaire"
    output:
        calls="snpeff_nostats/{sample}.vcf",    # the main output file
        # if either "genes" or "stats" outputs are provided, both are created
    log:
        "logs/snpeff_nostats/{sample}.log"
    params:
        java_opts="-XX:ParallelGCThreads=10",
        extra=""                 # optional parameters
    resources:
        mem_mb=1024
    wrapper:
        "v3.10.2-32-gf4e5b66/bio/snpeff/annotate"

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

  • snpeff=5.2

  • bcftools=1.20

  • snakemake-wrapper-utils=0.6.2

Input/Output

Input:

  • calls: input VCF/BCF file

  • db: SnpEff database

Output:

  • calls: trimmed fastq file with R1 reads, trimmed fastq file with R2 reads (PE only, optional)

  • genes: genes output file (optional)

  • stats: stats file (optional)

  • csvstats: stats CSV file (optional)

Params

  • java_opts: 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).

  • extra: additional program arguments.

Authors

  • Bradford Powell

Code

__author__ = "Bradford Powell"
__copyright__ = "Copyright 2018, Bradford Powell"
__email__ = "bpow@unc.edu"
__license__ = "BSD"


from snakemake.shell import shell
from os import path
import shutil
import tempfile
from pathlib import Path
from snakemake_wrapper_utils.java import get_java_opts


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

outcalls = snakemake.output.calls
if outcalls.endswith(".vcf.gz"):
    outprefix = "| bcftools view -Oz"
elif outcalls.endswith(".bcf"):
    outprefix = "| bcftools view -Ob"
else:
    outprefix = ""

incalls = snakemake.input[0]
if incalls.endswith(".bcf"):
    incalls = "< <(bcftools view {})".format(incalls)

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

data_dir = Path(snakemake.input.db).parent.resolve()

stats = snakemake.output.get("stats", "")
csvstats = snakemake.output.get("csvstats", "")
csvstats_opt = "" if not csvstats else "-csvStats {}".format(csvstats)
stats_opt = "-noStats" if not stats else "-stats {}".format(stats)

reference = path.basename(snakemake.input.db)

shell(
    "snpEff {java_opts} -dataDir {data_dir} "
    "{stats_opt} {csvstats_opt} {extra} "
    "{reference} {incalls} "
    "{outprefix} > {outcalls} {log}"
)