forked from hall-lab/sv-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SV_Tasks.wdl
488 lines (416 loc) · 11.1 KB
/
SV_Tasks.wdl
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# get the sample (SM) field from a CRAM file
task Get_Sample_Name {
File input_cram
Int disk_size
Int preemptible_tries
command {
samtools view -H ${input_cram} \
| grep -m 1 '^@RG' | tr '\t' '\n' \
| grep '^SM:' | sed 's/^SM://g'
}
runtime {
docker: "halllab/extract-sv-reads@sha256:192090f72afaeaaafa104d50890b2fc23935c8dc98988a9b5c80ddf4ec50f70c"
cpu: "1"
memory: "1 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
String sample = read_string(stdout())
}
}
# infer the sex of a sample based on chrom X copy number
task Get_Sex {
File input_cn_hist_root
File ref_fasta_index
Int disk_size
Int preemptible_tries
command <<<
cat ${ref_fasta_index} \
| awk '$1=="chrX" { print $1":0-"$2 } END { print "exit"}' \
| cnvnator -root ${input_cn_hist_root} -genotype 100 \
| grep -v "^Assuming male" \
| awk '{ printf("%.0f\n",$4); }'
>>>
runtime {
docker: "halllab/cnvnator@sha256:c41e9ce51183fc388ef39484cbb218f7ec2351876e5eda18b709d82b7e8af3a2"
cpu: "1"
memory: "1 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
String sex = read_string(stdout())
}
}
# Create pedigree file from samples, with sex inferred from
# CNVnator X chrom copy number
task Make_Pedigree_File {
Array[String] sample_array
Array[String] sex_array
String output_ped_basename
Int disk_size
command <<<
paste ${write_lines(sample_array)} ${write_lines(sex_array)} \
| awk '{ print $1,$1,-9,-9,$2,-9 }' OFS='\t' \
> ${output_ped_basename}.ped
>>>
runtime {
docker: "ubuntu@sha256:edf05697d8ea17028a69726b4b450ad48da8b29884cd640fec950c904bfb50ce"
cpu: "1"
memory: "1 GB"
disks: "local-disk " + disk_size + " HDD"
}
output {
File output_ped = "${output_ped_basename}.ped"
}
}
# extract split/discordant reads
task Extract_Reads {
File input_cram
String basename
File ref_cache
Int disk_size
Int preemptible_tries
command {
ln -s ${input_cram} ${basename}.cram
# build the reference sequence cache
tar -zxf ${ref_cache}
export REF_PATH=./cache/%2s/%2s/%s
export REF_CACHE=./cache/%2s/%2s/%s
# index the CRAM
samtools index ${basename}.cram
extract-sv-reads \
-e \
-r \
-i ${basename}.cram \
-s ${basename}.splitters.bam \
-d ${basename}.discordants.bam
samtools index ${basename}.splitters.bam
samtools index ${basename}.discordants.bam
}
runtime {
docker: "halllab/extract-sv-reads@sha256:192090f72afaeaaafa104d50890b2fc23935c8dc98988a9b5c80ddf4ec50f70c"
cpu: "1"
memory: "1 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_cram_index = "${basename}.cram.crai"
File output_splitters_bam = "${basename}.splitters.bam"
File output_splitters_bam_index = "${basename}.splitters.bam.bai"
File output_discordants_bam = "${basename}.discordants.bam"
File output_discordants_bam_index = "${basename}.discordants.bam.bai"
}
}
# LUMPY SV discovery
task Lumpy {
String basename
File input_cram
File input_cram_index
File input_splitters_bam
File input_splitters_bam_index
File input_discordants_bam
File input_discordants_bam_index
File ref_cache
File exclude_regions
Int disk_size
Int preemptible_tries
command {
ln -s ${input_cram} ${basename}.cram
ln -s ${input_cram_index} ${basename}.cram.crai
# build the reference sequence cache
tar -zxf ${ref_cache}
export REF_PATH=./cache/%2s/%2s/%s
export REF_CACHE=./cache/%2s/%2s/%s
lumpyexpress \
-P \
-T ${basename}.temp \
-o ${basename}.vcf \
-B ${input_cram} \
-S ${input_splitters_bam} \
-D ${input_discordants_bam} \
-x ${exclude_regions} \
-k \
-v
}
runtime {
docker: "halllab/lumpy@sha256:59ce7551307a54087e57d5cec89b17511d910d1fe9fa3651c12357f0594dcb07"
cpu: "1"
memory: "8 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf = "${basename}.vcf"
}
}
task Genotype {
String basename
File input_cram
File input_cram_index
File input_vcf
File ref_cache
Int disk_size
Int preemptible_tries
command {
ln -s ${input_cram} ${basename}.cram
ln -s ${input_cram_index} ${basename}.cram.crai
# build the reference sequence cache
tar -zxf ${ref_cache}
export REF_PATH=./cache/%2s/%2s/%s
export REF_CACHE=./cache/%2s/%2s/%s
rm -f ${basename}.cram.json
zless ${input_vcf} \
| svtyper \
-B ${basename}.cram \
-l ${basename}.cram.json \
> ${basename}.gt.vcf
}
runtime {
docker: "halllab/svtyper@sha256:21d757e77dfc52fddeab94acd66b09a561771a7803f9581b8cca3467ab7ff94a"
cpu: "1"
memory: "6.5 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf = "${basename}.gt.vcf"
File output_lib = "${basename}.cram.json"
}
}
task Copy_Number {
String basename
String sample
File input_vcf
File input_cn_hist_root
File ref_cache
Int disk_size
Int preemptible_tries
command {
create_coordinates \
-i ${input_vcf} \
-o coordinates.txt
svtools copynumber \
-i ${input_vcf} \
-s ${sample} \
--cnvnator cnvnator \
-w 100 \
-r ${input_cn_hist_root} \
-c coordinates.txt \
> ${basename}.cn.vcf
}
runtime {
docker: "halllab/cnvnator@sha256:c41e9ce51183fc388ef39484cbb218f7ec2351876e5eda18b709d82b7e8af3a2"
cpu: "1"
memory: "4 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf = "${basename}.cn.vcf"
}
}
task CNVnator_Histogram {
String basename
File input_cram
File input_cram_index
File ref_fasta
File ref_fasta_index
File ref_cache
String ref_chrom_dir = "cnvnator_chroms"
Int disk_size
Int preemptible_tries
Int threads = 4
command <<<
ln -s ${input_cram} ${basename}.cram
ln -s ${input_cram_index} ${basename}.cram.crai
# build the reference sequence cache
tar -zxf ${ref_cache}
export REF_PATH=./cache/%2s/%2s/%s
export REF_CACHE=./cache/%2s/%2s/%s
# Create directory of chromosome FASTA files for CNVnator
mkdir -p ${ref_chrom_dir}
awk -v CHROM_DIR=${ref_chrom_dir} 'BEGIN { CHROM="" } { if ($1~"^>") CHROM=substr($1,2); print $0 > CHROM_DIR"/"CHROM".fa" }' ${ref_fasta}
cnvnator_wrapper.py \
-T cnvnator.out \
-o ${basename}.cn \
-t ${threads} \
-w 100 \
-b ${basename}.cram \
-c ${ref_chrom_dir} \
-g GRCh38 \
--cnvnator cnvnator
>>>
runtime {
docker: "halllab/cnvnator@sha256:c41e9ce51183fc388ef39484cbb218f7ec2351876e5eda18b709d82b7e8af3a2"
cpu: threads
memory: "26 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_cn_hist_root = "cnvnator.out/${basename}.cram.hist.root"
}
}
task L_Sort_VCF_Variants {
Array[File] input_vcfs
File input_vcfs_file = write_lines(input_vcfs)
String output_vcf_basename
Int disk_size
Int preemptible_tries
command {
# strip the "gs://" prefix from the file paths
cat ${input_vcfs_file} \
| sed 's/^gs:\/\//\.\//g' \
> input_vcfs_file.local_map.txt
svtools lsort \
-b 200 \
-f input_vcfs_file.local_map.txt \
| bgzip -c \
> ${output_vcf_basename}.vcf.gz
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3.75 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_basename}.vcf.gz"
}
}
task L_Merge_VCF_Variants {
File input_vcf_gz
String output_vcf_basename
Int disk_size
Int preemptible_tries
command {
zcat ${input_vcf_gz} \
| svtools lmerge \
-i /dev/stdin \
-f 20 \
| bgzip -c \
> ${output_vcf_basename}.vcf.gz
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3.75 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_basename}.vcf.gz"
}
}
task Paste_VCF {
Array[File] input_vcfs
File input_vcfs_file = write_lines(input_vcfs)
String output_vcf_basename
Int disk_size
Int preemptible_tries
command {
# strip the "gs://" prefix from the file paths
cat ${input_vcfs_file} \
| sed 's/^gs:\/\//\.\//g' \
> input_vcfs_file.local_map.txt
svtools vcfpaste \
-f input_vcfs_file.local_map.txt \
-q \
| bgzip -c \
> ${output_vcf_basename}.vcf.gz
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_basename}.vcf.gz"
}
}
task Prune_VCF {
File input_vcf_gz
String output_vcf_basename
Int disk_size
Int preemptible_tries
command {
zcat ${input_vcf_gz} \
| svtools afreq \
| svtools vcftobedpe \
| svtools bedpesort \
| svtools prune -s -d 100 -e 'AF' \
| svtools bedpetovcf \
| bgzip -c \
> ${output_vcf_basename}.vcf.gz
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_basename}.vcf.gz"
}
}
task Classify {
File input_vcf_gz
File input_ped
String output_vcf_basename
File mei_annotation_bed
Int disk_size
Int preemptible_tries
command {
cat ${input_ped} \
| cut -f 2,5 \
> sex.txt
zcat ${input_vcf_gz} \
| svtools classify \
-g sex.txt \
-a ${mei_annotation_bed} \
-m large_sample \
| bgzip -c \
> ${output_vcf_basename}.vcf.gz
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_basename}.vcf.gz"
}
}
task Sort_Index_VCF {
File input_vcf_gz
String output_vcf_name
Int disk_size
Int preemptible_tries
command {
zcat ${input_vcf_gz} \
| svtools vcfsort \
| bgzip -c \
> ${output_vcf_name}
tabix -p vcf -f ${output_vcf_name}
}
runtime {
docker: "halllab/svtools@sha256:f2f3f9c788beb613bc26c858f897694cd6eaab450880c370bf0ef81d85bf8d45"
cpu: "1"
memory: "3 GB"
disks: "local-disk " + disk_size + " HDD"
preemptible: preemptible_tries
}
output {
File output_vcf_gz = "${output_vcf_name}"
File output_vcf_gz_index = "${output_vcf_name}.tbi"
}
}