-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrapper.py
66 lines (57 loc) · 1.66 KB
/
wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__author__ = "Dohoon Lee"
__copyright__ = "Copyright 2018, Dohoon Lee"
__email__ = "dohlee.bioinfo@gmail.com"
__license__ = "MIT"
from snakemake.shell import shell
# Extract log.
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
def optionify_input(parameter, option):
"""Return optionified parameter."""
try:
param = str(snakemake.input[parameter])
if param:
return option + ' ' + str(snakemake.input[parameter])
else:
return ''
except AttributeError:
return ''
def optionify_params(parameter, option):
"""Return optionified parameter."""
try:
param = str(snakemake.params[parameter])
if param:
return option + ' ' + str(snakemake.params[parameter])
else:
return ''
except AttributeError:
return ''
# Extract required inputs.
reference = snakemake.input.reference
if isinstance(reference, str):
reference = [reference]
reference = ','.join(reference)
annotation = snakemake.input.annotation
# Extract required outputs.
output_prefix = snakemake.output[0][:-6]
# Extract parameters.
# Extract optional parameters.
extra = snakemake.params.get('extra', '')
snp = optionify_params('snp', '--mode')
haplotype = optionify_params('haplotype', '--stranded')
splice_site = optionify_params('splice_site', '--ss')
exon = optionify_params('exon', '--exon')
# Execute shell command.
shell(
"("
"hisat2-build "
"-p {snakemake.threads} "
"{extra} "
"{snp} "
"{haplotype} "
"{splice_site} "
"{exon} "
"{reference} "
"{annotation} "
") "
"{log}"
)