-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
439 lines (326 loc) · 11.4 KB
/
tasks.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
import wolf
class DIG_convert_maf(wolf.Task):
name = "DIG_convert_maf"
inputs = {
"input_maf" : None,
"ref_build" : None, # ref build of input maf
"liftover_chainfile": None,
}
script = """
python3 /build/convert_maf.py --input_maf ${input_maf} --input_build ${ref_build} --output_path $(basename ${input_maf:0:-4}).hg19.dig.maf --liftover_chainfile ${liftover_chainfile}
"""
output_patterns = {
"dig_maf": "*.hg19.dig.maf"
}
resources = { "cpus-per-task": 2, "mem" : "20G" }
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
class DIG_annotate_maf(wolf.Task):
name = "DIG_annotate_maf"
inputs = {
"input_maf": None,
"ref_fasta": None,
"ref_fasta_idx": None,
"cohort_name": None
}
script = """
DigPreprocess.py annotMutationFile ${input_maf} ${ref_fasta} ${cohort_name}.txt
"""
output_patterns = {
"dig_maf": "*.txt"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = {
"cpus-per-task": 4,
"mem" : "20G"
}
class DIG_unzip_h5(wolf.Task):
name = "DIG_unzip_h5"
inputs = {
"zipped_tracks" : None
}
script = """
ln -s ${zipped_tracks} ./$(basename ${zipped_tracks})
DataExtractor.py unzipH5 $(basename ${zipped_tracks})
"""
output_patterns = {
"tracks" : "*.unzipped.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
use_scratch_disk=True
scratch_disk_size=200
scratch_disk_name="tracks"
preemptible=False
resources = {
"cpus-per-task": 4,
"mem" : "20G"
}
class DIG_add_objectives(wolf.Task):
name = "DIG_add_objectives"
inputs = {
"cohort_name": None,
"unzipped_tracks": None,
"maf_file": None # must be in Dig format
}
script = """
cp ${unzipped_tracks} ./${cohort_name}_tracks_with_objectives.h5
DataExtractor.py addObjectives ./${cohort_name}_tracks_with_objectives.h5 ${maf_file}
"""
output_patterns = {
"muts_added": "*tracks_with_objectives.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
use_scratch_disk=True
scratch_disk_size=200
scratch_disk_name="tracks-with-objectives"
preemptible=False
# checkpoint=True # need this to keep from purging the scratch disk
resources = {
"cpus-per-task": 2,
"mem" : "20G"
}
class DIG_run_kfold(wolf.Task):
name = "DIG_run_kfold_training"
inputs = {
"cohort_name":None,
"unzipped_tracks": None,
"autoregressive_size": 10,
"gp_reruns": 3,
"gp_runs" : 5,
"count_quartile_thresh": 0.999,
"mappability_thresh": 0.5,
"epochs": 10,
"num_dataset_workers":16
}
script = """
sudo mkdir -p /ramdisk
sudo mount -t tmpfs -o rw,size=195G tmpfs /ramdisk
echo "copying tracks to memory..."
cp ${unzipped_tracks} /ramdisk/
mkdir -p ${cohort_name}_kfold_res
python3 /build/mutation_density/DIGDriver/region_model/kfold_mutations_main.py -o ${cohort_name}_kfold_res -c ${cohort_name} -d /ramdisk/${cohort_name}_tracks_with_objectives.h5 -as ${autoregressive_size} -gr ${gp_reruns} -gp ${gp_runs} -cq ${count_quartile_thresh} -sm -st -m ${mappability_thresh} -e 10 -u -g all -nw ${num_dataset_workers}
"""
use_gpu=True
output_patterns = {
"kfold_results": "*_kfold_res/"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker_gpu:latest"
resources = {
"cpus-per-task": 32,
"mem" : "190G"
}
class DIG_pretrain_region(wolf.Task):
name = "DIG_pretrain_region"
inputs = {
"unzipped_tracks": None,
"kfold_output_dir":None,
"cohort_name": None,
"maf_file": None
}
# overrides = {"kfold_output_dir" : "string"}
script = """
# Pre-train regional rate parameters from the completed CNN+GP kfold run
echo "Pre-training regional rate parameters..."
DigPretrain.py regionModel "$(ls -td ${kfold_output_dir}/kfold/${cohort_name}/*/ | head -1)" ${unzipped_tracks} ./${cohort_name}.h5 --cohort-name ${cohort_name} --mutation-file ${maf_file}
cp ./${cohort_name}.h5 ${cohort_name}_map.h5
"""
output_patterns = {
"pretrained_model": "*_map.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = {
"cpus-per-task": 4,
"mem" : "12G"
}
class DIG_pretrain_sequence(wolf.Task):
name = "DIG_pretrain_sequence"
inputs = {
"genome_counts": None,
"cohort_name": None,
"pretrained_model":None,
"maf_file": None
}
script = """
cp ${pretrained_model} ./
# Pre-train the sequence context parameters using pre-computed genome counts and annotated mutations
echo "Pre-training the sequence context parameters..."
DigPretrain.py sequenceModel ${maf_file} ${genome_counts} ./$(basename ${pretrained_model})
"""
output_patterns = {
"pretrained_model": "*_map.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = {
"cpus-per-task": 4,
"mem" : "12G"
}
class DIG_pretrain_genic(wolf.Task):
name = "DIG_pretrain_genic"
inputs = {
"pretrained_model": None,
"gene_data": None
}
script = """
cp ${pretrained_model} ./
DigPretrain.py genicModel ./$(basename ${pretrained_model}) ${gene_data}
"""
output_patterns = {
"pretrained_model": "*_map.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = {
"cpus-per-task": 4,
"mem" : "12G"
}
class DIG_test_coding(wolf.Task):
name = 'DIG_test_coding'
inputs = {
"input_annot_maf" : None,
"input_mut_map" : None,
"cohort": None
}
script="""
DigDriver.py geneDriver ${input_annot_maf} ${input_mut_map} --outdir . --outpfx ${cohort}.coding.dig
"""
output_patterns = {
"dig_results": "*.results.txt"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_report_coding(wolf.Task):
name = 'DIG_report_coding'
inputs = {
"input_results" : None,
"cgc_list": None,
"pancan_list": None,
"cohort": None
}
script="""
python3 /build/generate_dig_report_coding.py ${input_results} . ${cgc_list} ${pancan_list} --prefix_output ${cohort}
"""
output_patterns = {
"dig_report" : "*.html"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_preprocess_element_model(wolf.Task):
name = 'DIG_preprocess_element_model'
input = {
"input_bed" : None,
"input_element_data" : None,
"input_mut_map" : None,
"ref_fasta" : None,
"annot_name" : None
}
script="""
cp ${input_mut_map} ./mutation_map.h5
cp ${input_element_data} ./element_data.h5
DigPreprocess.py preprocess_element_model ./element_data.h5 ./mutation_map.h5 ${ref_fasta} ${annot_name} --f-bed ${input_bed}
"""
output_patterns = {
"output_element_data" : "element_data.h5",
"output_mut_map": "mutation_map.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_element_model(wolf.Task):
name = 'DIG_element_model'
input = {
"input_element_data" : None,
"input_mut_map" : None,
"annot_name" : None
}
script="""
cp ${input_mut_map} ./mutation_map.h5
cp ${input_element_data} ./element_data.h5
DigPretrain.py elementModel ./mutation_map.h5 ./element_data.h5 ${annot_name}
"""
output_patterns = {
"output_element_data" : "element_data.h5",
"output_mut_map": "mutation_map.h5"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_test_noncoding(wolf.Task):
name = 'DIG_test_noncoding'
inputs = {
"input_annot_maf" : None,
"input_mut_map" : None,
"input_bed" : None,
"annot_name" : None,
"cohort" : None
}
script="""
DigDriver.py elementDriver ${input_annot_maf} ${input_mut_map} ${annot_name} --f-bed ${input_bed} --outdir . --outpfx ${cohort}.${annot_name}.dig
"""
output_patterns = {
"dig_results": "*.results.txt"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_report_noncoding(wolf.Task):
name = 'DIG_report_noncoding'
inputs = {
"input_results" : None,
"cgc_list": None,
"pancan_list": None,
"annot_name" : None,
"cohort" : None
}
script="""
python3 /build/generate_dig_report_noncoding.py ${input_results} . ${cgc_list} ${pancan_list} ${annot_name} --prefix_output ${cohort}
"""
output_patterns = {
"dig_report" : "*.html"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_results(wolf.Task):
name = 'DIG_results'
inputs = {
"noncoding_htmls": None,
"noncoding_results": None,
"coding_html": None,
"coding_result": None,
"cgc_list": None,
"pancan_list": None,
"cohort" : None
}
script="""
# Read all lines from .txt files
noncoding_html_paths=$(cat ${noncoding_htmls})
noncoding_result_paths=$(cat ${noncoding_results})
# Convert the file paths into arrays
noncoding_html_arr=($noncoding_html_paths)
noncoding_result_arr=($noncoding_result_paths)
# Copy each file to the current working directory
echo "Copying results and reports to working directory..."
for path in "${noncoding_html_arr[@]}"; do
cp "$path" ./
done
for path in "${noncoding_result_arr[@]}"; do
cp "$path" ./
done
cp ${coding_html} ./
cp ${coding_result} ./
# Generate combined p-values and report
echo "Generating combined p-values and the associated report..."
python3 /build/generate_dig_report_combined.py $(basename ${coding_result}) $(basename ${noncoding_result_arr[0]}) $(basename ${noncoding_result_arr[1]}) $(basename ${noncoding_result_arr[2]}) . ${cgc_list} ${pancan_list} --prefix_output ${cohort}
# Generate final report
echo "Generating final report..."
python3 /build/generate_dig_report_main.py $(basename ${coding_html}) $(basename ${noncoding_html_arr[0]}) $(basename ${noncoding_html_arr[1]}) $(basename ${noncoding_html_arr[2]}) ./${cohort}_dig_report_combined.html . --prefix_output ${cohort}
ls
# Zip results
echo "Zipping all results and reports..."
zip dig_results.zip *.txt *.html
"""
output_patterns = {
"dig_results" : "*.zip"
}
docker = "gcr.io/broad-getzlab-workflows/dig_docker:latest"
resources = { "cpus-per-task": 2, "mem" : "20G" }
class DIG_gather_noncoding(wolf.Task):
name = "Gather_noncoding"
inputs = {"gather_parameter"}
script = """cat ${gather_parameter} > output.txt
"""
outputs = { "output" : "output.txt" }