GATK GENOMICSDBIMPORT
Run gatk GenomicsDBImport.
URL: https://gatk.broadinstitute.org/hc/en-us/articles/9570326648475-GenomicsDBImport
Example
This wrapper can be used in the following way:
rule genomics_db_import:
input:
gvcfs=["calls/a.g.vcf.gz", "calls/b.g.vcf.gz"],
output:
db=directory("db"),
log:
"logs/gatk/genomicsdbimport.log",
params:
intervals="ref",
db_action="create", # optional
extra="", # optional
java_opts="", # optional
threads: 2
resources:
mem_mb=lambda wildcards, input: max([input.size_mb * 1.6, 200]),
wrapper:
"v3.7.0/bio/gatk/genomicsdbimport"
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. -XX:ParallelGCThreads=10 (not for -XmX or -Djava.io.tmpdir, since they are handled automatically).
The intervals param is mandatory
By default, the wrapper will create a new database (output directory must be empty or non-existent). If you want to update an existing DB, set db_action param to update.
The extra param allows for additional program arguments.
Software dependencies
gatk4=4.5.0.0
snakemake-wrapper-utils=0.6.2
Input/Output
Input:
GVCF files of multiple samples
Output:
A GenomicsDB workspace
Code
__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2021, Filipe G. Vieira"
__license__ = "MIT"
import os
import tempfile
from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts
extra = snakemake.params.get("extra", "")
# uses Java native library TileDB, which requires a lot of memory outside
# of the `-Xmx` memory, so we reserve 40% instead of the default 20%. See:
# https://gatk.broadinstitute.org/hc/en-us/articles/9570326648475-GenomicsDBImportGenomicsDBImport
java_opts = get_java_opts(snakemake, java_mem_overhead_factor=0.4)
gvcfs = list(map("--variant {}".format, snakemake.input.gvcfs))
db_action = snakemake.params.get("db_action", "create")
if db_action == "create":
db_action = "--genomicsdb-workspace-path"
elif db_action == "update":
db_action = "--genomicsdb-update-workspace-path"
else:
raise ValueError(
"invalid option provided to 'params.db_action'; please choose either 'create' or 'update'."
)
intervals = snakemake.input.get("intervals")
if not intervals:
intervals = snakemake.params.get("intervals")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
with tempfile.TemporaryDirectory() as tmpdir:
shell(
"gatk --java-options '{java_opts}' GenomicsDBImport"
" --reader-threads {snakemake.threads}"
" {gvcfs}"
" --intervals {intervals}"
" {extra}"
" --tmp-dir {tmpdir}"
" {db_action} {snakemake.output.db}"
" {log}"
)