-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVarScan_workflow.wdl
431 lines (380 loc) · 9.82 KB
/
VarScan_workflow.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
# test VarScan 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 - > ${LANE}_${file_basename}.bam
}
output {
File aligned_bam = "${LANE}_${file_basename}.bam"
}
}
task SortBam {
File bamFile
File PICARD
File ref_fasta
File ref_dict
File ref_index
String sampleName
command {
java -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 BamFilter {
String BamFile
File SAMTOOLS
File ref_fasta
File ref_dict
File ref_index
String sampleName
command {
${SAMTOOLS} view -F 0x900 ${BamFile} -b -o ${sampleName}.filtered.sorted.bam
}
output {
File bam_filtered = "${sampleName}.filtered.sorted.bam"
}
}
task BamFlagstat {
String BamFile
File SAMTOOLS
File ref_fasta
File ref_dict
File ref_index
command {
${SAMTOOLS} flagstat ${BamFile} > ${BamFile}.flagstat.txt
}
output {
File bam_index = "${BamFile}.flagstat.txt"
}
}
task mpileup_all {
String BamFile
File SAMTOOLS
File ref_fasta
File ref_dict
File ref_index
String sampleName
command {
${SAMTOOLS} mpileup -B -f ${ref_fasta} -q 1 -d 10000000 ${BamFile} | gzip -9 > ${sampleName}.mpileup.gz
}
output {
File mpileup_all_gz = "${sampleName}.mpileup.gz"
}
}
task mpileup_target {
String BamFile
File SAMTOOLS
File ref_fasta
File ref_dict
File ref_index
String sampleName
String panel_bed_path
command {
${SAMTOOLS} mpileup \
-B -f ${ref_fasta} -q 1 \
-l ${panel_bed_path} \
-d 10000000 ${BamFile} | gzip -9 > ${sampleName}.mpileup.gz | parallel
}
output {
File mpileup_target_gz = "${sampleName}.mpileup.gz"
}
}
task Merge_mpileup_info {
Array[File] files
String panel_bed
command <<<
python <<CODE
import os
mpileup_files="${write_lines(files)}"
sampleMpileupMap = {}
with open(mpileup_files, 'r') as vf:
for line in vf:
tmpFile = line.strip()
tmpFileDic = os.path.split(tmpFile)[0]
tmpFileName = os.path.split(tmpFile)[1]
tmpName = tmpFileName.split('.')[0]
sample = tmpName
sampleMpileupMap.setdefault(sample,[]).append("${panel_bed}")
sampleMpileupMap.setdefault(sample,[]).append(tmpFile)
for key in sampleMpileupMap:
fileListStr = '\t'.join(sampleMpileupMap[key])
print (key+'\t'+fileListStr)
CODE
>>>
output {
File mpileupfileStr = stdout()
}
}
task testPrint {
Array[String] s
command <<<
python <<CODE
tmp = "${write_lines(s)}"
f= open(tmp,"r")
for line in f:
print line
f.close()
CODE
>>>
output{
String printScreen = read_string(stdout())
}
}
task CovDep{
File mpileup_info
String CovDep
String panel_dic
command {
${CovDep} <(cat ${mpileup_info}) ${panel_dic} > Allsamples.covdep.summary.txt
}
output {
File covdep_summary = "Allsamples.covdep.summary.txt"
}
}
task VarscanMpileup2snp {
File VarScan
File mpileup
String snp_output
command {
java -Xmx8g -jar ${VarScan} mpileup2snp \
<(zcat ${mpileup}) \
${snp_output} \
--min-coverage 4 \
--min-var-freq 0.01 \
--p-value 0.01 \
--strand-filter 1 \
--output-vcf \
--variants > ${snp_output}.snp.vcf
}
output {
File snp_vcf = "${snp_output}.snp.vcf"
}
}
task VarscanMpileup2indel {
File VarScan
File mpileup
String indel_output
command {
java -Xmx8g -jar ${VarScan} mpileup2indel \
<(zcat ${mpileup}) \
${indel_output} \
--min-coverage 4 \
--min-var-freq 0.01 \
--p-value 0.01 \
--strand-filter 1 \
--output-vcf \
--variants > ${indel_output}.indel.vcf
}
output {
File indel_vcf = "${indel_output}.indel.vcf"
}
}
task VarscanSomatic {
File VarScan
File normal_mpileup
File tumor_mpileup
String somatic_output
command {
java -Xmx8g -jar ${VarScan} somatic \
<(zcat ${normal_mpileup}) \
<(zcat ${tumor_mpileup}) \
${somatic_output} \
--min-coverage-tumor 4 \
--strand-filter 1 \
--output-vcf 1 \
--somatic-p-value 0.05
}
output {
String somatic_calling = "${somatic_output}"
}
}
task MarkDuplicates{
File bamFile
File PICARD
String sampleName
command {
java -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"
}
}
workflow mpileup_varscan {
File sampleMetainfo
Array[Array[String]] input_FASTQ = read_tsv(sampleMetainfo)
File BWA0712
File PICARD
File SAMTOOLS131
File GATK36
File VarScan
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
String panel_bed
String Panel_bed_path = "/work-a/user/yanll/Tools/genecast-workflow/data/regions/medexome.bed.gz"
scatter (pair in input_FASTQ){
call BwaMem {
input:
BWA = BWA0712,
SAMTOOLS = SAMTOOLS131,
input_FASTQ1 = pair[2],
input_FASTQ2 = pair[3],
file_basename = pair[1],
LANE = pair[0],
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
ref_amb = ref_amb,
ref_ann = ref_ann,
ref_bwt = ref_bwt,
ref_pac = ref_pac,
ref_sa = ref_sa,
THREAD_NUM = THREAD_NUM
}
call SortBam as firstSortBam {
input:
bamFile = BwaMem.aligned_bam,
PICARD = PICARD,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = pair[0]+'_'+pair[1]
}
call BamFilter {
input:
BamFile = firstSortBam.sorted_Bam,
SAMTOOLS = SAMTOOLS131,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = pair[0]+'_'+pair[1]
}
call SortBam as secondSortBam {
input:
bamFile = BamFilter.bam_filtered,
PICARD = PICARD,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = pair[0]+'_'+pair[1]
}
call BamFlagstat {
input:
BamFile = secondSortBam.sorted_Bam,
SAMTOOLS = SAMTOOLS131,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index
}
call MarkDuplicates{
input:
bamFile = secondSortBam.sorted_Bam,
PICARD = PICARD,
sampleName = pair[0]+'_'+pair[1]
}
call mpileup_all {
input:
BamFile = MarkDuplicates.deduped_Bam,
SAMTOOLS = SAMTOOLS131,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = pair[0]+'_'+pair[1]
}
call mpileup_target {
input:
SAMTOOLS = SAMTOOLS131,
BamFile = MarkDuplicates.deduped_Bam,
panel_bed_path = Panel_bed_path,
ref_fasta = ref_fasta,
ref_dict = ref_dict,
ref_index = ref_index,
sampleName = pair[0]+'_'+pair[1]
}
call VarscanMpileup2snp {
input:
VarScan = VarScan,
mpileup = mpileup_target.mpileup_target_gz,
snp_output = pair[0]+'_'+pair[1]
}
call VarscanMpileup2indel {
input:
VarScan = VarScan,
mpileup = mpileup_target.mpileup_target_gz,
indel_output = pair[0]+'_'+pair[1]
}
}
#####
# set BamFilePairs to call Varscan somatic command
#####
#
#Array[Array[String]] SomaticBams = [["normal1.mpileup","tumor1.mpileup"],["normal2.mpielup","tumor2.mpileup"]]
#scatter (pair in SomaticBams){
# call VarscanSomatic{
# input:
# VarScan = VarScan,
# normal_mpileup = pair[0],
# tumor_mpileup = pair[1],
# somatic_output = "I1_I2"
# }
# }
call Merge_mpileup_info {
input:
files = mpileup_all.mpileup_all_gz,
panel_bed = panel_bed
}
call CovDep {
input:
CovDep="/work-a/user/yanll/Tools/genecast-workflow/tools/covdepstat",
mpileup_info = Merge_mpileup_info.mpileupfileStr,
panel_dic = "/work-a/user/yanll/Tools/genecast-workflow/data/regions"
}
}