-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsub-dax.py
executable file
·231 lines (198 loc) · 9.22 KB
/
sub-dax.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/python
'''
USAGE: # ./sub-dax.py $RUN_DIR > sub-pipeline.dax
'''
'''
NOTE:
- Comment out SISTR dependency line at the end if non-Salmonella organism is used.
'''
import sys
import os
# Import the Python DAX library
os.sys.path.insert(0, "/util/opt/pegasus-wms/5.0/lib64/pegasus/externals/python/")
from Pegasus.DAX3 import *
dax = ADAG("pipeline")
base_dir = os.getcwd()
run_dir = sys.argv[1]
prokka_run = []
plasmidfinder_run = []
sistr_run = []
list_of_gff_files = []
list_of_contig_files = []
list_of_filtererd_sra_ids = []
list_of_sistr_files = []
# Get list of contigs after filtering
for file_name in os.listdir(run_dir):
filee = File(file_name)
filee.addPFN(PFN("file://{0}/".format(run_dir) + str(file_name), "local-hcc"))
dax.addFile(filee)
list_of_contig_files.append(filee)
i = 0
for output_filtering_contigs in list_of_contig_files:
srr_id = output_filtering_contigs.name.split("_")[0]
# add job for Prokka
prokka_run.append(Job("ex_prokka_run"))
prokka_run[i].addArguments(srr_id, str(srr_id) + "_prokka_output", output_filtering_contigs)
prokka_run[i].uses(output_filtering_contigs, link=Link.INPUT)
prokka_run[i].uses(str(srr_id) + "_prokka_output/" + str(srr_id) + ".gff", link=Link.OUTPUT, transfer=True)
prokka_run[i].uses(str(srr_id) + "_prokka_output.tar.gz", link=Link.OUTPUT, transfer=True)
# prokka_run[i].addProfile(Profile("pegasus", "label", str(srr_id)))
prokka_run[i].addProfile(Profile("pegasus", "runtime", "14400"))
prokka_run[i].addProfile(Profile("globus", "maxwalltime", "240"))
dax.addJob(prokka_run[i])
# add files
f = File(str(srr_id) + "_prokka_output/" + str(srr_id) + ".gff")
list_of_gff_files.append(f)
# add job for plasmidfinder
plasmidfinder_run.append(Job("ex_plasmidfinder_run"))
plasmidfinder_run[i].addArguments(output_filtering_contigs, str(srr_id) + "_plasmidfinder_output")
plasmidfinder_run[i].uses(output_filtering_contigs, link=Link.INPUT)
plasmidfinder_run[i].uses(str(srr_id) + "_plasmidfinder_output.tar.gz", link=Link.OUTPUT, transfer=True)
# plasmidfinder_run[i].addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(plasmidfinder_run[i])
# add job for sistr
sistr_run.append(Job("ex_sistr_run"))
sistr_run[i].addArguments(str(srr_id) + "_allele_results.json", str(srr_id) + "_novel_alleles.fasta", str(srr_id) + "_cgmlst_profiles.csv", str(srr_id) + "_sistr_output.csv", output_filtering_contigs)
sistr_run[i].uses(output_filtering_contigs, link=Link.INPUT)
sistr_run[i].uses(str(srr_id) + "_sistr_output.csv", link=Link.OUTPUT, transfer=False)
dax.addJob(sistr_run[i])
list_of_sistr_files.append(str(srr_id) + "_sistr_output.csv")
i = i + 1
# add job for mlst
mlst_run = Job("ex_mlst_run")
mlst_run.addArguments(*list_of_contig_files)
for l in list_of_contig_files:
mlst_run.uses(l, link=Link.INPUT)
o = File("mlst_output.csv")
mlst_run.setStdout(o)
mlst_run.uses(o, link=Link.OUTPUT, transfer=True)
mlst_run.addProfile(Profile("pegasus", "runtime", "108000"))
mlst_run.addProfile(Profile("globus", "maxwalltime", "1800"))
# mlst_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(mlst_run)
# add job for abricate vfdb
abricate_vfdb_run = Job("ex_abricate_run")
abricate_vfdb_run.addArguments("vfdb", *list_of_contig_files)
for l in list_of_contig_files:
abricate_vfdb_run.uses(l, link=Link.INPUT)
o = File("sabricate_vfdb_output.csv")
abricate_vfdb_run.setStdout(o)
abricate_vfdb_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_vfdb_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_vfdb_run)
# add job for abricate argannot
abricate_argannot_run = Job("ex_abricate_run")
abricate_argannot_run.addArguments("argannot", *list_of_contig_files)
for l in list_of_contig_files:
abricate_argannot_run.uses(l, link=Link.INPUT)
o = File("sabricate_argannot_output.csv")
abricate_argannot_run.setStdout(o)
abricate_argannot_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_argannot_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_argannot_run)
# add job for abricate card
abricate_card_run = Job("ex_abricate_run")
abricate_card_run.addArguments("card", *list_of_contig_files)
for l in list_of_contig_files:
abricate_card_run.uses(l, link=Link.INPUT)
o = File("sabricate_card_output.csv")
abricate_card_run.setStdout(o)
abricate_card_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_card_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_card_run)
# add job for abricate ncbi
abricate_ncbi_run = Job("ex_abricate_run")
abricate_ncbi_run.addArguments("ncbi", *list_of_contig_files)
for l in list_of_contig_files:
abricate_ncbi_run.uses(l, link=Link.INPUT)
o = File("sabricate_ncbi_output.csv")
abricate_ncbi_run.setStdout(o)
abricate_ncbi_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_ncbi_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_ncbi_run)
# add job for abricate plasmidfinder
abricate_plasmidfinder_run = Job("ex_abricate_run")
abricate_plasmidfinder_run.addArguments("plasmidfinder", *list_of_contig_files)
for l in list_of_contig_files:
abricate_plasmidfinder_run.uses(l, link=Link.INPUT)
o = File("sabricate_plasmidfinder_output.csv")
abricate_plasmidfinder_run.setStdout(o)
abricate_plasmidfinder_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_plasmidfinder_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_plasmidfinder_run)
# add job for abricate resfinder
abricate_resfinder_run = Job("ex_abricate_run")
abricate_resfinder_run.addArguments("resfinder", *list_of_contig_files)
for l in list_of_contig_files:
abricate_resfinder_run.uses(l, link=Link.INPUT)
o = File("sabricate_resfinder_output.csv")
abricate_resfinder_run.setStdout(o)
abricate_resfinder_run.uses(o, link=Link.OUTPUT, transfer=True)
# abricate_resfinder_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(abricate_resfinder_run)
# add job for Roary
roary_run = Job("ex_roary_run")
roary_run.addArguments("roary_output", *list_of_gff_files)
for l in list_of_gff_files:
roary_run.uses(l, link=Link.INPUT)
roary_run.uses("roary_output/core_gene_alignment.aln", link=Link.OUTPUT, transfer=True)
roary_run.uses("roary_output.tar.gz", link=Link.OUTPUT, transfer=True)
roary_run.addProfile(Profile("pegasus", "runtime", "604800"))
roary_run.addProfile(Profile("globus", "maxwalltime", "10080"))
roary_run.addProfile(Profile("condor", "request_memory", "970000"))
roary_run.addProfile(Profile("condor", "memory", "970000"))
# roary_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(roary_run)
# add job for baps_run
# R script, wrapper
fastbaps_run = Job("ex_fastbaps_run")
fastbaps_output = File("fastbaps_baps.csv")
fastbaps_run.addArguments("roary_output/core_gene_alignment.aln", fastbaps_output)
fastbaps_run.uses("roary_output/core_gene_alignment.aln", link=Link.INPUT)
fastbaps_run.uses(fastbaps_output, link=Link.OUTPUT, transfer=True)
fastbaps_run.addProfile(Profile("condor", "request_memory", "30000"))
fastbaps_run.addProfile(Profile("globus", "maxmemory", "30000"))
fastbaps_run.addProfile(Profile("pegasus", "memory", "30000"))
# fastbaps_run.addProfile(Profile("pegasus", "label", str(srr_id)))
dax.addJob(fastbaps_run)
# ls
ls_run = Job("ex_ls")
ls_run.addArguments(run_dir)
dax.addJob(ls_run)
# add job for cat sistr files
ex_cat = Executable(namespace="dax", name="cat", version="4.0", os="linux", arch="x86_64", installed=True)
ex_cat.addPFN(PFN("/bin/cat", "local-hcc"))
dax.addExecutable(ex_cat)
output_sistr_cat = File("sistr_all.csv")
cat = Job(namespace="dax", name=ex_cat)
cat.addArguments(*list_of_sistr_files)
for l in list_of_sistr_files:
cat.uses(l, link=Link.INPUT)
cat.setStdout(output_sistr_cat)
cat.uses(output_sistr_cat, link=Link.OUTPUT, transfer=True, register=False)
dax.addJob(cat)
# add job for sistr output filtering
output_sistr_merge_cat = File("sistr_all_merge.csv")
merge_sistr_run = Job("ex_merge_sistr")
merge_sistr_run.addArguments(output_sistr_cat, output_sistr_merge_cat)
merge_sistr_run.uses(output_sistr_cat, link=Link.INPUT)
merge_sistr_run.uses(output_sistr_merge_cat, link=Link.OUTPUT, transfer=True)
dax.addJob(merge_sistr_run)
length = len(list_of_contig_files)
for i in range(0,length):
# Add control-flow dependencies
dax.addDependency(Dependency(parent=plasmidfinder_run[i], child=ls_run))
dax.addDependency(Dependency(parent=prokka_run[i], child=roary_run))
# COMMENT OUT THE LINE BELOW TO SKIP SISTR IF NON SALMONELLA ORGANISM IS USED!!!
dax.addDependency(Dependency(parent=sistr_run[i], child=cat))
dax.addDependency(Dependency(parent=mlst_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_argannot_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_card_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_ncbi_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_plasmidfinder_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_resfinder_run, child=ls_run))
dax.addDependency(Dependency(parent=abricate_vfdb_run, child=ls_run))
dax.addDependency(Dependency(parent=roary_run, child=fastbaps_run))
dax.addDependency(Dependency(parent=cat, child=merge_sistr_run))
# Write the DAX to stdout
dax.writeXML(sys.stdout)