Skip to content

Commit 4ba82aa

Browse files
tdayrisfgvieira
andauthored
feat: GATK utils for common IO files (#39)
* GATK utils for common IO files * Black formatting * Default set to False * Typo * inferred with two r * Code format * Code reformat * Code reformat * Rename ref_dict --------- Co-authored-by: tdayris <[email protected]> Co-authored-by: Filipe G. Vieira <[email protected]>
1 parent f329b2b commit 4ba82aa

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

snakemake_wrapper_utils/gatk.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import sys
2+
from snakemake_wrapper_utils.snakemake import is_arg
3+
4+
5+
def get_gatk_opts(
6+
snakemake,
7+
parse_arg_file=False,
8+
parse_bam_index=False,
9+
parse_bam_md5=False,
10+
parse_vcf_index=False,
11+
parse_vcf_md5=False,
12+
parse_ref=False,
13+
parse_ref_dict=False,
14+
param_name="extra",
15+
):
16+
"""Obtain gatk_opts from input, output, params"""
17+
18+
gatk_opts = ""
19+
extra = snakemake.params.get(param_name, "")
20+
21+
##########################
22+
### Configuration file ###
23+
##########################
24+
25+
if parse_arg_file:
26+
if is_arg("--arguments_file", extra):
27+
sys.exit(
28+
"You have specified an argument file (`--argument_file`) in `params.extra`; this is automatically inferred from `input.arg_file`."
29+
)
30+
31+
# Multiple argument files can be provided. Order matters.
32+
arg_file = snakemake.input.get("arg_file", "")
33+
if arg_file:
34+
if isinstance(arg_file, list):
35+
arg_file = " --argument_file ".join(arg_file)
36+
37+
gatk_opts += f"--argument_file {arg_file}"
38+
39+
######################
40+
### Reference file ###
41+
######################
42+
43+
if parse_ref:
44+
if is_arg("-R", extra) or is_arg("--reference", extra):
45+
sys.exit(
46+
"You have specified reference file (`-R,--reference`) in `params.extra`; this is automatically inferred from `input.ref`."
47+
)
48+
ref = snakemake.input.get("ref")
49+
if ref:
50+
gatk_opts += f" --reference {ref}"
51+
52+
if parse_ref_dict:
53+
if is_arg("--sequence-dictionary", extra):
54+
sys.exit(
55+
"You have specified reference sequence dictionary (`--sequence-dictionary`) in `params.extra`; this is automatically inferred from `input.dict`."
56+
)
57+
dict = snakemake.input.get("dict", "")
58+
if dict:
59+
gatk_opts += f" --sequence-dictionary {dict}"
60+
61+
###########################
62+
### Optional BAM output ###
63+
###########################
64+
if parse_bam_index:
65+
if is_arg("--create-output-bam-index", extra) or is_arg("-OBI", extra):
66+
sys.exit(
67+
"You have specified bam index creation (`-OBI,--create-output-bam-index`) in `params.extra`; this is automatically inferred from `output.bam_bai`."
68+
)
69+
if snakemake.output.get("bam_bai"):
70+
gatk_opts += " --create-output-bam-index"
71+
72+
if parse_bam_md5:
73+
if is_arg("--create-output-bam-md5", extra) or is_arg("-OBM", extra):
74+
sys.exit(
75+
"You have specified bam MD5-sum creation (`-OBM,--create-output-bam-md5`) in `params.extra`; this is automatically inferred from `output.bam_md5`."
76+
)
77+
if snakemake.output.get("bam_md5"):
78+
gatk_opts += " --create-output-bam-md5"
79+
80+
###########################
81+
### Optional VCF output ###
82+
###########################
83+
if parse_vcf_index:
84+
if is_arg("--create-output-variant-index", extra) or is_arg("-OVI", extra):
85+
sys.exit(
86+
"You have specified VCF index creation (`--OVI,--create-output-variant-index`) in `params.extra`; this is automatically inferred from `output.vcf_idx`."
87+
)
88+
if snakemake.output.get("vcf_idx"):
89+
gatk_opts += " --create-output-variant-index "
90+
91+
if parse_vcf_md5:
92+
if is_arg("--create-output-variant-md5", extra) or is_arg("-OVM", extra):
93+
sys.exit(
94+
"You have specified VCF MD5-sum creation (`--OVI,--create-output-variant-index`) in `params.extra`; this is automatically inferred from `output.vcf_md5`."
95+
)
96+
if snakemake.output.get("vcf_md5"):
97+
gatk_opts += " --create-output-variant-md5 "
98+
99+
return gatk_opts

0 commit comments

Comments
 (0)