-
Notifications
You must be signed in to change notification settings - Fork 5
/
htsinfer.smk
105 lines (85 loc) · 2.73 KB
/
htsinfer.smk
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Independent Snakefile for inferring sample specific parameters with HTSinfer."""
import os
import pandas as pd
# set config defaults if not given
config.setdefault("records", 100000)
# global variables
samples = pd.read_csv(
config["samples"], header=0, index_col=0, sep="\t", keep_default_na=False
)
OUT_DIR = config["outdir"]
LOG_DIR = config["log_dir"]
CLUSTER_LOG = config["cluster_log_dir"]
# Write inferred params into new sample table.
SAMPLES_OUT = os.path.join(OUT_DIR, config["samples_out"])
localrules:
all,
htsinfer_to_tsv,
rule all:
input:
SAMPLES_OUT,
current_rule = "run_htsinfer"
rule run_htsinfer:
""" Run htsinfer on fastq samples
"""
input:
fq1_path=lambda wildcards: samples.loc[wildcards.sample, "fq1"],
output:
htsinfer_json=os.path.join(OUT_DIR, "htsinfer_{sample}.json"),
params:
fq2_path=lambda wildcards: (
samples.loc[wildcards.sample, "fq2"]
if samples.loc[wildcards.sample, "fq2"]
else ""
),
records=config["records"],
outdir=OUT_DIR,
cluster_log_path=CLUSTER_LOG,
threads: 4
singularity:
"docker://quay.io/biocontainers/htsinfer:0.11.0--pyhdfd78af_1"
conda:
os.path.join(workflow.basedir, "..", "envs", "htsinfer.yaml")
log:
stderr=os.path.join(LOG_DIR, "{sample}", current_rule + ".stderr.log"),
shell:
"""
set +e
htsinfer --records={params.records} --output-directory={params.outdir} --temporary-directory={resources.tmpdir} --cleanup-regime=KEEP_ALL --threads={threads} {input.fq1_path} {params.fq2_path} > {output.htsinfer_json} 2> {log.stderr}
exitcode=$?
if [ $exitcode -eq 1 ]
then
exit 0
fi
"""
current_rule = "htsinfer_to_tsv"
rule htsinfer_to_tsv:
"""Write inferred params for all samples to samples.tsv"""
input:
jlist=expand(
os.path.join(OUT_DIR, "htsinfer_{sample}.json"),
sample=samples.index.tolist(),
),
samples_in=config["samples"],
script=os.path.join(workflow.basedir, "..", "scripts", "htsinfer_to_tsv.py"),
output:
SAMPLES_OUT,
threads: 4
singularity:
"docker://quay.io/biocontainers/htsinfer:0.11.0--pyhdfd78af_1"
conda:
os.path.join(workflow.basedir, "..", "envs", "htsinfer.yaml")
log:
stderr=os.path.join(LOG_DIR, current_rule + ".stderr.log"),
shell:
"""
python {input.script} \
-f {input.jlist} \
-s {input.samples_in} \
-o {output} \
2> {log.stderr}
"""
onsuccess:
print("Workflow finished, no error.")
onerror:
print("Ooops... something went wrong")