-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutation_calling.wdl
431 lines (365 loc) · 11.6 KB
/
mutation_calling.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
version 1.0
## WDL 101 example workflow
##
## This WDL workflow is intended to be used along with the WDL 101 docs.
## This workflow should be used for inspiration purposes only.
##
## We use three samples
## Samples:
## MOLM13: Normal sample
## CALU1: KRAS G12C mutant
## HCC4006: EGFR Ex19 deletion mutant
##
## Input requirements:
## - combined fastq files for chromosome 12 and 7 +/- 200bp around the sites of mutation only
##
## Output Files:
## - An aligned bam for all 3 samples (with duplicates marked and base quality recalibrated)
##
## Workflow developed by Sitapriya Moorthi, Chris Lo and Taylor Firman @ Fred Hutch and Ash (Aisling) O'Farrell @ UCSC LMD: 02/28/24 for use @ Fred Hutch.
struct referenceGenome {
File ref_fasta
File ref_fasta_index
File ref_dict
File ref_amb
File ref_ann
File ref_bwt
File ref_pac
File ref_sa
String ref_name
}
workflow mutation_calling {
input {
Array[File] tumorFastq
File normalFastq
referenceGenome refGenome
File dbSNP_vcf
File dbSNP_vcf_index
File known_indels_sites_VCFs
File known_indels_sites_indices
File af_only_gnomad
File af_only_gnomad_index
String annovar_protocols
String annovar_operation
}
# Scatter for "tumor" samples
scatter (tumorSamples in tumorFastq) {
call BwaMem as tumorBwaMem {
input:
input_fastq = tumorSamples,
refGenome = refGenome
}
call MarkDuplicates as tumorMarkDuplicates {
input:
input_bam = tumorBwaMem.analysisReadySorted
}
call ApplyBaseRecalibrator as tumorApplyBaseRecalibrator{
input:
input_bam = tumorMarkDuplicates.markDuplicates_bam,
input_bam_index = tumorMarkDuplicates.markDuplicates_bai,
dbSNP_vcf = dbSNP_vcf,
dbSNP_vcf_index = dbSNP_vcf_index,
known_indels_sites_VCFs = known_indels_sites_VCFs,
known_indels_sites_indices = known_indels_sites_indices,
refGenome = refGenome
}
call Mutect2Paired {
input:
tumor_bam = tumorApplyBaseRecalibrator.recalibrated_bam,
tumor_bam_index = tumorApplyBaseRecalibrator.recalibrated_bai,
normal_bam = normalApplyBaseRecalibrator.recalibrated_bam,
normal_bam_index = normalApplyBaseRecalibrator.recalibrated_bai,
refGenome = refGenome,
genomeReference = af_only_gnomad,
genomeReferenceIndex = af_only_gnomad_index
}
call annovar {
input:
input_vcf = Mutect2Paired.output_vcf,
ref_name = refGenome.ref_name,
annovar_operation = annovar_operation,
annovar_protocols = annovar_protocols
}
}
# Do for normal sample
call BwaMem as normalBwaMem {
input:
input_fastq = normalFastq,
refGenome = refGenome
}
call MarkDuplicates as normalMarkDuplicates {
input:
input_bam = normalBwaMem.analysisReadySorted
}
call ApplyBaseRecalibrator as normalApplyBaseRecalibrator {
input:
input_bam = normalMarkDuplicates.markDuplicates_bam,
input_bam_index = normalMarkDuplicates.markDuplicates_bai,
dbSNP_vcf = dbSNP_vcf,
dbSNP_vcf_index = dbSNP_vcf_index,
known_indels_sites_VCFs = known_indels_sites_VCFs,
known_indels_sites_indices = known_indels_sites_indices,
refGenome = refGenome
}
output {
Array[File] tumoralignedBamSorted = tumorBwaMem.analysisReadySorted
Array[File] tumorMarkDuplicates_bam = tumorMarkDuplicates.markDuplicates_bam
Array[File] tumorMarkDuplicates_bai = tumorMarkDuplicates.markDuplicates_bai
Array[File] tumoranalysisReadyBam = tumorApplyBaseRecalibrator.recalibrated_bam
Array[File] tumoranalysisReadyIndex = tumorApplyBaseRecalibrator.recalibrated_bai
File normalalignedBamSorted = normalBwaMem.analysisReadySorted
File normalmarkDuplicates_bam = normalMarkDuplicates.markDuplicates_bam
File normalmarkDuplicates_bai = normalMarkDuplicates.markDuplicates_bai
File normalanalysisReadyBam = normalApplyBaseRecalibrator.recalibrated_bam
File normalanalysisReadyIndex = normalApplyBaseRecalibrator.recalibrated_bai
Array[File] Mutect2Paired_Vcf = Mutect2Paired.output_vcf
Array[File] Mutect2Paired_VcfIndex = Mutect2Paired.output_vcf_index
Array[File] Mutect2Paired_AnnotatedVcf = annovar.output_annotated_vcf
Array[File] Mutect2Paired_AnnotatedTable = annovar.output_annotated_table
}
}
# TASK DEFINITIONS
# Align fastq file to the reference genome
task BwaMem {
input {
File input_fastq
referenceGenome refGenome
Int threads = 16
}
String base_file_name = basename(input_fastq, ".fastq")
String ref_fasta_local = basename(refGenome.ref_fasta)
String read_group_id = "ID:" + base_file_name
String sample_name = "SM:" + base_file_name
String platform = "illumina"
String platform_info = "PL:" + platform # Create the platform information
command <<<
set -eo pipefail
#can we iterate through a struct??
mv ~{refGenome.ref_fasta} .
mv ~{refGenome.ref_fasta_index} .
mv ~{refGenome.ref_dict} .
mv ~{refGenome.ref_amb} .
mv ~{refGenome.ref_ann} .
mv ~{refGenome.ref_bwt} .
mv ~{refGenome.ref_pac} .
mv ~{refGenome.ref_sa} .
bwa mem \
-p -v 3 -t ~{threads} -M -R '@RG\t~{read_group_id}\t~{sample_name}\t~{platform_info}' \
~{ref_fasta_local} ~{input_fastq} > ~{base_file_name}.sam
samtools view -1bS -@ 15 -o ~{base_file_name}.aligned.bam ~{base_file_name}.sam
samtools sort -@ 15 -o ~{base_file_name}.sorted_query_aligned.bam ~{base_file_name}.aligned.bam
>>>
output {
File analysisReadySorted = "~{base_file_name}.sorted_query_aligned.bam"
}
runtime {
memory: "48 GB"
cpu: 16
docker: "ghcr.io/getwilds/bwa:0.7.17"
}
}
# Mark duplicates (not SPARK, for some reason that does something weird)
task MarkDuplicates {
input {
File input_bam
}
String base_file_name = basename(input_bam, ".sorted_query_aligned.bam")
String output_bam = "~{base_file_name}.duplicates_marked.bam"
String output_bai = "~{base_file_name}.duplicates_marked.bai"
String metrics_file = "~{base_file_name}.duplicate_metrics"
command <<<
gatk MarkDuplicates \
--INPUT ~{input_bam} \
--OUTPUT ~{output_bam} \
--METRICS_FILE ~{metrics_file} \
--CREATE_INDEX true \
--OPTICAL_DUPLICATE_PIXEL_DISTANCE 100 \
--VALIDATION_STRINGENCY SILENT
>>>
runtime {
docker: "ghcr.io/getwilds/gatk:4.3.0.0"
memory: "48 GB"
cpu: 4
}
output {
File markDuplicates_bam = "~{output_bam}"
File markDuplicates_bai = "~{output_bai}"
File duplicate_metrics = "~{metrics_file}"
}
}
# Base quality recalibration
task ApplyBaseRecalibrator {
input {
File input_bam
File input_bam_index
File dbSNP_vcf
File dbSNP_vcf_index
File known_indels_sites_VCFs
File known_indels_sites_indices
referenceGenome refGenome
}
String base_file_name = basename(input_bam, ".duplicates_marked.bam")
String ref_fasta_local = basename(refGenome.ref_fasta)
String dbSNP_vcf_local = basename(dbSNP_vcf)
String known_indels_sites_VCFs_local = basename(known_indels_sites_VCFs)
command <<<
set -eo pipefail
mv ~{refGenome.ref_fasta} .
mv ~{refGenome.ref_fasta_index} .
mv ~{refGenome.ref_dict} .
mv ~{dbSNP_vcf} .
mv ~{dbSNP_vcf_index} .
mv ~{known_indels_sites_VCFs} .
mv ~{known_indels_sites_indices} .
samtools index ~{input_bam} #redundant? markduplicates already does this?
gatk --java-options "-Xms8g" \
BaseRecalibrator \
-R ~{ref_fasta_local} \
-I ~{input_bam} \
-O ~{base_file_name}.recal_data.csv \
--known-sites ~{dbSNP_vcf_local} \
--known-sites ~{known_indels_sites_VCFs_local} \
gatk --java-options "-Xms8g" \
ApplyBQSR \
-bqsr ~{base_file_name}.recal_data.csv \
-I ~{input_bam} \
-O ~{base_file_name}.recal.bam \
-R ~{ref_fasta_local} \
#finds the current sort order of this bam file
samtools view -H ~{base_file_name}.recal.bam | grep @SQ | sed 's/@SQ\tSN:\|LN://g' > ~{base_file_name}.sortOrder.txt
>>>
output {
File recalibrated_bam = "~{base_file_name}.recal.bam"
File recalibrated_bai = "~{base_file_name}.recal.bai"
File sortOrder = "~{base_file_name}.sortOrder.txt"
}
runtime {
memory: "36 GB"
cpu: 2
docker: "ghcr.io/getwilds/gatk:4.3.0.0"
}
}
# Mutect 2 calling tumor-normal
task Mutect2Paired {
input {
File tumor_bam
File tumor_bam_index
File normal_bam
File normal_bam_index
referenceGenome refGenome
File genomeReference
File genomeReferenceIndex
}
String base_file_name_tumor = basename(tumor_bam, ".recal.bam")
String base_file_name_normal = basename(normal_bam, ".recal.bam")
String ref_fasta_local = basename(refGenome.ref_fasta)
String genomeReference_local = basename(genomeReference)
command <<<
set -eo pipefail
mv ~{refGenome.ref_fasta} .
mv ~{refGenome.ref_fasta_index} .
mv ~{refGenome.ref_dict} .
mv ~{genomeReference} .
mv ~{genomeReferenceIndex} .
gatk --java-options "-Xms16g" Mutect2 \
-R ~{ref_fasta_local} \
-I ~{tumor_bam} \
-I ~{normal_bam} \
-O preliminary.vcf.gz \
--germline-resource ~{genomeReference_local} \
gatk --java-options "-Xms16g" FilterMutectCalls \
-V preliminary.vcf.gz \
-O ~{base_file_name_tumor}.mutect2.vcf.gz \
-R ~{ref_fasta_local} \
--stats preliminary.vcf.gz.stats \
>>>
runtime {
docker: "ghcr.io/getwilds/gatk:4.3.0.0"
memory: "24 GB"
cpu: 1
}
output {
File output_vcf = "${base_file_name_tumor}.mutect2.vcf.gz"
File output_vcf_index = "${base_file_name_tumor}.mutect2.vcf.gz.tbi"
}
}
# annotate with annovar mutation calling outputs
task annovar {
input {
File input_vcf
String ref_name
String annovar_protocols
String annovar_operation
}
String base_vcf_name = basename(input_vcf, ".vcf.gz")
command <<<
set -eo pipefail
perl /annovar/table_annovar.pl ~{input_vcf} /annovar/humandb/ \
-buildver ~{ref_name} \
-outfile ~{base_vcf_name} \
-remove \
-protocol ~{annovar_protocols} \
-operation ~{annovar_operation} \
-nastring . -vcfinput
>>>
runtime {
docker : "ghcr.io/getwilds/annovar:${ref_name}"
cpu: 1
memory: "2GB"
}
output {
File output_annotated_vcf = "${base_vcf_name}.${ref_name}_multianno.vcf"
File output_annotated_table = "${base_vcf_name}.${ref_name}_multianno.txt"
}
}
# Mutect 2 calling tumor only
#task Mutect2TumorOnly {
# input {
# File input_bam
# File input_bam_index
# File ref_dict
# File ref_fasta
# File ref_fasta_index
# File genomeReference
# File genomeReferenceIndex
# }
#
# String base_file_name = basename(input_bam, ".recal.bam")
# String ref_fasta_local = basename(ref_fasta)
# String genomeReference_local = basename(genomeReference)
#
#command <<<
# set -eo pipefail
#
# mv ~{ref_fasta} .
# mv ~{ref_fasta_index} .
# mv ~{ref_dict} .
# mv ~{genomeReference} .
# mv ~{genomeReferenceIndex} .
#
# gatk --java-options "-Xms16g" Mutect2 \
# -R ~{ref_fasta_local} \
# -I ~{input_bam} \
# -O preliminary.vcf.gz \
# --germline-resource ~{genomeReference_local} \
#
# gatk --java-options "-Xms16g" FilterMutectCalls \
# -V preliminary.vcf.gz \
# -O ~{base_file_name}.mutect2.vcf.gz \
# -R ~{ref_fasta_local} \
# --stats preliminary.vcf.gz.stats \
#
#>>>
#
#runtime {
# docker: "ghcr.io/getwilds/gatk:4.3.0.0"
# memory: "24 GB"
# cpu: 1
# }
#
#output {
# File output_vcf = "${base_file_name}.mutect2.vcf.gz"
# File output_vcf_index = "${base_file_name}.mutect2.vcf.gz.tbi"
# }
#
#}