-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGATK_workflow2.wdl
executable file
·543 lines (502 loc) · 13.5 KB
/
GATK_workflow2.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# test GATK workflow
#
# TASK DEFINITIONS
#
## Align FASTQ reads with BWA-MEM
task BwaMem {
File BWA
File input_FASTQ1
File input_FASTQ2
String file_basename
File ref_fasta
File ref_dict
File ref_index
File ref_amb
File ref_ann
File ref_bwt
File ref_pac
File ref_sa
String THREAD_NUM
File SAMTOOLS
String LANE
command {
${BWA} mem -t ${THREAD_NUM} -M ${ref_fasta} ${input_FASTQ1} ${input_FASTQ2} -R '@RG\tID:${file_basename}_${LANE}-\tLB:${file_basename}_${LANE}\tSM:${file_basename}\tPL:ILLUMINA\tPU:flowcell-barcode.lane' | ${SAMTOOLS} view -Sb - > ${file_basename}_${LANE}.bam
}
output {
File aligned_bam = "${file_basename}_${LANE}.bam"
}
}
task SortBam {
File bamFile
File PICARD
File ref_fasta
File ref_dict
File ref_index
String sampleName
command {
java -Xmx32g -XX:ParallelGCThreads=10 -Djava.io.tmpdir=/work-z/tmp/ -jar ${PICARD} SortSam \
INPUT=${bamFile} \
OUTPUT=${sampleName}.sorted.bam \
CREATE_INDEX=true \
SORT_ORDER=coordinate
}
output {
File sorted_Bam = "${sampleName}.sorted.bam"
File sorted_Bam_index = "${sampleName}.sorted.bai"
}
}
task MarkDuplicates{
File bamFile
File PICARD
String sampleName
command {
java -Xmx12g -XX:ParallelGCThreads=10 -Djava.io.tmpdir=/work-z/tmp/ -jar ${PICARD} MarkDuplicates \
INPUT=${bamFile} \
OUTPUT=${sampleName}.dedup.sorted.bam \
METRICS_FILE=${sampleName}.dedup.sorted.bam.metrics.txt
}
output {
File deduped_Bam = "${sampleName}.dedup.sorted.bam"
File dedup_metrics = "${sampleName}.dedup.sorted.bam.metrics.txt"
}
}
task BuildBamIndex {
String bamFile
File SAMTOOLS
File ref_fasta
File ref_dict
File ref_index
command {
${SAMTOOLS} index ${bamFile}
}
output {
File bam_index = "${bamFile}.bai"
}
}
# Generate Base Quality Score Recalibration (BQSR) model
task BaseRecalibrator {
File GATK
File input_bam
File input_bam_index
String recal_table_name
File dbSNP_vcf
File dbSNP_vcf_index
File gold_indels
File gold_indels_index
File ref_dict
File ref_fasta
File ref_index
Array[File]? BQSR_table
String nct
Array[String]? BQSR_cmd
command {
java -Xmx40g -XX:ParallelGCThreads=10 -Djava.io.tmpdir=/work-z/tmp/ \
-jar ${GATK} \
-T BaseRecalibrator \
-R ${ref_fasta} \
-I ${input_bam} \
-o ${recal_table_name} \
-knownSites ${dbSNP_vcf} \
-knownSites ${gold_indels} \
-nct ${nct} ${BQSR_cmd[0]}${BQSR_table[0]}
}
output {
Array[File] recal_table_file = ["${recal_table_name}"]
}
}
task AnalyzeCovariates {
File GATK
File ref_fasta
File ref_index
File ref_dict
String plots_name
Array[File] before_recal_table
Array[File] post_recal_table
command{
java -Xmx12g -Djava.io.tmpdir=/work-z/tmp/ \
-jar ${GATK} \
-T AnalyzeCovariates \
-R ${ref_fasta} \
-before ${before_recal_table[0]} \
-after ${post_recal_table[0]} \
-plots ${plots_name}
}
output{
File plots_file = "${plots_name}"
}
}
task PrintReads {
File GATK
File ref_fasta
File ref_index
File ref_dict
String sampleName
File bamfile
File bamfile_index
Array[String] recal_table_file
String nct
command{
java -Xmx40g -XX:ParallelGCThreads=10 -Djava.io.tmpdir=/work-z/tmp/ \
-jar ${GATK} \
-T PrintReads \
-R ${ref_fasta} \
-I ${bamfile} \
-BQSR ${recal_table_file[0]} \
-nct ${nct} \
-o ${sampleName}.recal_reads.bam
}
output{
File recal_bam= "${sampleName}.recal_reads.bam"
File recal_bam_index= "${sampleName}.recal_reads.bai"
}
}
task HaplotypeCaller {
File GATK
String sampleName
File bamFile
File bamFile_index
File ref_fasta
File ref_index
File ref_dict
File interval_list
String nct
command {
java -Xmx40g -XX:ParallelGCThreads=10 -Djava.io.tmpdir=/work-z/tmp/ \
-jar ${GATK} \
-T HaplotypeCaller \
-R ${ref_fasta} \
-I ${bamFile} \
-o ${sampleName}.raw.vcf \
-L ${interval_list} \
-nct ${nct} \
--max_alternate_alleles 5 \
-stand_emit_conf 10 \
--read_filter OverclippedRead
}
output {
File sample_gvcfs = "${sampleName}.raw.vcf"
File sample_gvcf_indices = "${sampleName}.raw.vcf.idx"
}
}
task select {
File GATK
File ref_fasta
File ref_dict
File ref_index
String sampleName
String type
File rawVCF
command {
java -Xmx8g -jar ${GATK} \
-T SelectVariants \
-R ${ref_fasta} \
-V ${rawVCF} \
-selectType ${type} \
-o ${sampleName}_raw.${type}.vcf
}
output {
File rawSubset = "${sampleName}_raw.${type}.vcf"
}
}
task hardFilterSNP {
File GATK
File ref_fasta
File ref_dict
File ref_index
String sampleName
File rawSNPs
command {
java -Xmx8g -jar ${GATK} \
-T VariantFiltration \
-R ${ref_fasta} \
-V ${rawSNPs} \
--filterExpression "QD < 2.0 || FS > 60.0 || MQ < 40.0 || MQRankSum < -12.5 || ReadPosRankSum < -8.0" \
--filterName "snp_filter" \
-o ${sampleName}.filtered.snps.vcf
}
output {
File filteredSNPs = "${sampleName}.filtered.snps.vcf"
}
}
task hardFilterIndel {
File GATK
File ref_fasta
File ref_dict
File ref_index
String sampleName
File rawIndels
command {
java -Xmx8g -jar ${GATK} \
-T VariantFiltration \
-R ${ref_fasta} \
-V ${rawIndels} \
--filterExpression "D < 2.0 || FS > 200.0 || SOR > 10.0 || InbreedingCoeff < -0.8 || ReadPosRankSum < -20.0" \
--filterName "indel_filter" \
-o ${sampleName}.filtered.indels.vcf
}
output {
File filteredIndels = "${sampleName}.filtered.indels.vcf"
}
}
task combine {
File GATK
File ref_fasta
File ref_dict
File ref_index
String sampleName
File filteredSNPs
File filteredIndels
command {
java -Xmx8g -jar ${GATK} \
-T CombineVariants \
-R ${ref_fasta} \
-V ${filteredSNPs} \
-V ${filteredIndels} \
--genotypemergeoption UNSORTED \
-o ${sampleName}.filtered.snps.indels.vcf
}
output {
File filteredVCF = "${sampleName}.filtered.snps.indels.vcf"
}
}
task MergeBamStr {
Array[File] files
command <<<
python <<CODE
import os
uMbamlist="${write_lines(files)}"
sampleBamMap = {}
with open(uMbamlist, 'r') as vf:
for line in vf:
tmpBam = line.strip()
tmpBamDic = os.path.split(tmpBam)[0]
tmpBamName = os.path.split(tmpBam)[1]
tmpName = tmpBamName.split('.')[0]
sample = tmpName.split('_')[0]
#lane = tmpName.split('_')[0]
sampleBamMap.setdefault(sample,[]).append(tmpBam)
for key in sampleBamMap:
fileListStr = '\t'.join(sampleBamMap[key])
print (key+'\t'+fileListStr)
CODE
>>>
output {
Array[Array[String]] bamfileStr = read_tsv(stdout())
}
}
task MergeBams {
Array[String]+ bamfileList
String sampleName
File PICARD
command {
java -Xmx8g -jar ${PICARD} MergeSamFiles \
I= ${sep=" INPUT= " bamfileList} \
O= ${sampleName}.merged.bam
}
output {
File mergedBam = "${sampleName}.merged.bam"
}
}
task readSampleName {
Array[String] ll
command { echo '${ll[0]}'}
output {String sample = read_string(stdout())}
}
task readMergeBamList {
Array[String] ll
command <<<
python <<CODE
f= open("${write_lines(ll)}","r")
lines = [i.strip() for i in f.readlines()]
f.close()
for line in lines[1:]:
print line
CODE
>>>
output {
Array[String] list = read_lines(stdout())
}
}
# WORKFLOW DEFINITIONS
workflow GATK_test {
File sampleMetainfo
Array[Array[String]] input_FASTQ = read_tsv(sampleMetainfo)
File BWA0712
File PICARD
File SAMTOOLS131
File GATK36
File ref_fasta
File ref_dict
File ref_index
File ref_amb
File ref_ann
File ref_bwt
File ref_pac
File ref_sa
String THREAD_NUM
File dbSNP_vcf
File dbSNP_vcf_index
File gold_indels
File gold_indels_index
String panel_bed = "/work-a/user/guoh/Data/MedExome_design_files/MedExome_hg19_capture_targets.bed"
# using filtered Bam files to call GATK workflow
# Filtered Bams could be generated from VarScan workflow first.
Array[Array[File]] FinalBams
scatter (BamPair in FinalBams) {
call MarkDuplicates {
input:
bamFile = BamPair[1],
PICARD = PICARD,
sampleName = BamPair[0]
}
call BuildBamIndex {
input:
bamFile = MarkDuplicates.deduped_Bam,
SAMTOOLS = SAMTOOLS131,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index
}
call BaseRecalibrator as firstBR {
input:
GATK = GATK36,
input_bam= MarkDuplicates.deduped_Bam,
input_bam_index = BuildBamIndex.bam_index,
recal_table_name="recal_data.table",
dbSNP_vcf = dbSNP_vcf ,
dbSNP_vcf_index = dbSNP_vcf_index,
gold_indels = gold_indels,
gold_indels_index = gold_indels_index,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
nct = "6"
}
#call BaseRecalibrator as secondBR {
# input:
# GATK = GATK36,
# input_bam= MarkDuplicates.deduped_Bam,
# input_bam_index = BuildBamIndex.bam_index,
# recal_table_name="post_recal_data.table",
# dbSNP_vcf = dbSNP_vcf,
# dbSNP_vcf_index = dbSNP_vcf_index,
# gold_indels = gold_indels,
# gold_indels_index = gold_indels_index,
# ref_fasta = ref_fasta,
# ref_dict = ref_dict,
# ref_index = ref_index,
# nct = "6",
# BQSR_cmd = ["-BQSR "],
# BQSR_table= firstBR.recal_table_file
# }
#call AnalyzeCovariates {
# input:
# GATK = GATK36,
# ref_fasta = ref_fasta,
# ref_dict = ref_dict,
# ref_index = ref_index,
# before_recal_table = firstBR.recal_table_file,
# post_recal_table = secondBR.recal_table_file,
# plots_name = "recalibration_plots.pdf"
#}
call PrintReads {
input:
GATK = GATK36,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = BamPair[0],
bamfile= MarkDuplicates.deduped_Bam,
bamfile_index = BuildBamIndex.bam_index,
recal_table_file = firstBR.recal_table_file,
nct = "6"
}
call HaplotypeCaller {
input:
GATK = GATK36,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = BamPair[0],
nct = "6",
bamFile = PrintReads.recal_bam,
bamFile_index = PrintReads.recal_bam_index,
interval_list = panel_bed
}
call select as selectSNPs {
input:
sampleName = BamPair[0],
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
GATK=GATK36,
type="SNP",
rawVCF=HaplotypeCaller.sample_gvcfs
}
call select as selectIndels {
input:
sampleName = BamPair[0],
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
GATK=GATK36,
type="INDEL",
rawVCF=HaplotypeCaller.sample_gvcfs
}
call hardFilterSNP {
input:
sampleName = BamPair[0],
GATK=GATK36,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
rawSNPs=selectSNPs.rawSubset
}
call hardFilterIndel {
input:
sampleName = BamPair[0],
GATK=GATK36,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
rawIndels=selectIndels.rawSubset
}
call combine {
input:
sampleName = BamPair[0],
GATK=GATK36,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
filteredSNPs=hardFilterSNP.filteredSNPs,
filteredIndels=hardFilterIndel.filteredIndels
}
}
}
#####
#Merge bam files of same sample from two lanes
#
#####
#
#scatter (pair in input_FASTQ){
# call BwaMem {}
# call SortBam as firstSortBam {}
#}
#
#call MergeBamStr {
# input: files = firstSortBam.sorted_Bam
# }
# scatter (line in MergeBamStr.bamfileStr){
# call readSampleName{
# input: ll = line
# }
# call readMergeBamList{
# input: ll = line
# }
# call MergeBams{
# input:
# bamfileList = readMergeBamList.list,
# sampleName = readSampleName.sample,
# PICARD = PICARD
# }
# }