-
Notifications
You must be signed in to change notification settings - Fork 1
/
dna.nf
executable file
·436 lines (396 loc) · 13.5 KB
/
dna.nf
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
#!/usr/bin/env nextflow
params.input = './fastq'
params.output = './analysis'
params.snpeff_vers = 'GRCh38.86';
params.genome="/project/shared/bicf_workflow_ref/human/grch38_cloud/dnaref"
params.virus_genome="/project/shared/bicf_workflow_ref/human_virus_genome/clinlab_idt_genomes"
params.markdups='fgbio_umi'
params.version = 'v4'
params.seqrunid = 'runtest'
somatic = false
fpalgo = ['fb']
ssalgo = ['strelka2']
svalgo = ['delly', 'svaba']
ncmconf = file("$params.genome/ncm.conf")
reffa=file("$params.genome/genome.fa")
dbsnp="$params.genome/dbSnp.vcf.gz"
indel="$params.genome/GoldIndels.vcf.gz"
dbsnp=file(dbsnp)
knownindel=file(indel)
index_path=file(params.genome)
capturebed = file("$params.capture")
capturedir = file("$params.capturedir")
virus_index_path=file(params.virus_genome)
skipCNV = false
if(capturedir.isEmpty()) {
skipCNV = true
}
alignopts = ''
if (params.markdups == 'fgbio_umi') {
alignopts='-u'
}
repoDir=workflow.projectDir
if (params.repoDir) {
repoDir=params.repoDir
}
ponopt=''
if (params.pon) {
ponopt="-q $params.pon"
}
def somatic = [:]
def ids = []
def reads = []
if (params.caseid) {
params.tumorid = 'Tumor'
somatic[params.caseid] = false
params.tfq = "${params.input}/${params.tumorid}.R{1,2}.fastq.gz"
reads << tuple(params.caseid,params.tumorid,file(params.tfq))
if( params.normalid ) {
somatic[params.caseid] = true
params.nfq = "${params.input}/${params.normalid}.R{1,2}.fastq.gz"
ids << tuple(params.caseid,params.tumorid,params.normalid)
ids << tuple(params.caseid,params.tumorid,params.normalid)
reads << tuple(params.caseid,params.normalid,file(params.nfq))
} else {
ids << tuple(params.caseid,params.tumorid,'')
}
} else {
params.design="$params.input/design.txt"
params.fastqs="$params.input/*.fastq.gz"
fastqs=file(params.fastqs)
design_file=file(params.design)
def fileMap = [:]
fastqs.each {
final fileName = it.getFileName().toString()
prefix = fileName.lastIndexOf('/')
fileMap[fileName] = it
}
new File(params.design).withReader { reader ->
def hline = reader.readLine()
def header = hline.split("\t")
cidx = header.findIndexOf{it == 'CaseID'};
tidx = header.findIndexOf{it == 'TumorID'};
nidx = header.findIndexOf{it == 'NormalID'};
fidx = header.findIndexOf{it == 'SampleID'};
oneidx = header.findIndexOf{it == 'FqR1'};
twoidx = header.findIndexOf{it == 'FqR2'};
while (line = reader.readLine()) {
def row = line.split("\t")
if (fileMap.get(row[oneidx]) != null) {
somatic[row[cidx]] = true
if (row[nidx] == '') {
somatic[row[cidx]] = false
}
reads << tuple(row[cidx],row[fidx],[fileMap.get(row[oneidx]),fileMap.get(row[twoidx])])
ids << tuple(row[cidx],row[tidx],row[nidx])
}
}
}
}
if( ! reads) { error "Didn't match any input files with entries in the design file" }
process dtrim {
queue '32GB,super'
label 'trim'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
input:
set caseid,sampleid, file(fqs) from reads
set caseid,tid,nid from ids
output:
set caseid,tid,nid,sampleid,file("${sampleid}.trim.R1.fastq.gz"),file("${sampleid}.trim.R2.fastq.gz"),file("${sampleid}.trimreport.txt") into treads
script:
"""
bash ${repoDir}/process_scripts/preproc_fastq/trimgalore.sh -f -p ${sampleid} ${fqs}
"""
}
process dalign {
queue '32GB,super'
label 'dnaalign'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
input:
set caseid,tid,nid,sampleid,file(fq1),file(fq2),file(trimout) from treads
output:
set caseid,tid,nid,sampleid, file("${sampleid}.bam") into mdupbam
set caseid,sampleid, file("${sampleid}.bam"),file("${sampleid}.bam.bai"),file(trimout) into qcbam
set caseid,sampleid,file("${sampleid}.bam") into virusalign
set caseid,sampleid,file("${sampleid}.bam"),file("${sampleid}.bam.bai") into cnvbam
set caseid,sampleid,file("${sampleid}.bam"),file("${sampleid}.bam.bai") into itdbam
set caseid,tid,nid,file("${sampleid}.bam"), file("${sampleid}.bam.bai") into oribam
script:
"""
bash ${repoDir}/process_scripts/alignment/dnaseqalign.sh -r $index_path -p $sampleid -x ${fq1} -y ${fq2} $alignopts
"""
}
process valign {
queue '32GB,super'
label 'dnaalign'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
input:
set caseid,sampleid, file(sbam) from virusalign
output:
file("${sampleid}.viral.seqstats.txt") into viralseqstats
script:
"""
bash ${repoDir}/process_scripts/alignment/virusalign.sh -b ${sampleid}.bam -p ${sampleid} -r $virus_index_path -f
"""
}
process markdups {
errorStrategy 'ignore'
label 'dnaalign'
queue '32GB,super'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
input:
set caseid,tid,nid,sampleid, file(sbam) from mdupbam
output:
set caseid,tid,nid,sampleid, file("${sampleid}.consensus.bam"),file("${sampleid}.consensus.bam.bai") into togatkbam
set caseid,tid,nid,file("${sampleid}.consensus.bam"),file("${sampleid}.consensus.bam.bai") into consbam
script:
"""
bash ${repoDir}/process_scripts/alignment/markdups.sh -a $params.markdups -b $sbam -p $sampleid -r $index_path
mv ${sampleid}.dedup.bam ${sampleid}.consensus.bam
mv ${sampleid}.dedup.bam.bai ${sampleid}.consensus.bam.bai
"""
}
process dna_bamqc {
errorStrategy 'ignore'
label 'profiling_qc'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
queue '128GB,256GB,256GBv1'
input:
set caseid,sampleid, file(gbam),file(idx),file(trimreport) from qcbam
output:
file("*fastqc*") into fastqc
file("${sampleid}*txt") into dalignstats
script:
"""
bash ${repoDir}/process_scripts/alignment/bamqc.sh -c $capturebed -n dna -r $index_path -b ${gbam} -p $sampleid -e ${params.version}
"""
}
process cnv {
queue '32GB,super'
label 'structuralvariant'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,sampleid,file(sbam),file(sidx) from cnvbam
output:
file("${sampleid}.call.cns") into cns
file("${sampleid}.cns") into cnsori
file("${sampleid}.cnr") into cnr
file("${sampleid}.answerplot*") into cnvansplot
file("${sampleid}.*txt") into cnvtxt
file("${sampleid}.cnv*pdf") into cnvpdf
when:
skipCNV == false
script:
"""
bash ${repoDir}/process_scripts/variants/cnvkit.sh -r $index_path -b $sbam -p $sampleid -d $capturedir
"""
}
process itdseek {
queue '32GB,super'
label 'structuralvariant'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,sampleid,file(sbam),file(sidx) from itdbam
output:
file("${sampleid}.itdseek_tandemdup.vcf.gz") into itdseekvcf
script:
"""
bash ${repoDir}/process_scripts/variants/svcalling.sh -b $sbam -r $index_path -p $sampleid -l ${index_path}/itd_genes.bed -a itdseek -g $params.snpeff_vers -f
"""
}
process gatkbam {
queue '32GB,super'
label 'variantcalling'
publishDir "$params.output/$caseid/dnaout", mode: 'copy'
input:
set caseid,tid,nid,sampleid, file(sbam),file(idx) from togatkbam
output:
set caseid,tid,nid,file("${sampleid}.final.bam"),file("${sampleid}.final.bam.bai") into gtxbam
script:
"""
bash ${repoDir}/process_scripts/variants/gatkrunner.sh -a gatkbam -b $sbam -r $index_path -p $sampleid
"""
}
oribam
.groupTuple(by:[0,1,2])
.into { svbam; msibam; }
consbam
.groupTuple(by:[0,1,2])
.into { checkbams; sombam; germbam; pindelbam; strelkabam; }
gtxbam
.groupTuple(by:[0,1,2])
.set { mutectbam }
process msi {
queue '32GB,super'
label 'profiling_qc'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
errorStrategy 'ignore'
input:
set caseid,tid,nid,file(ssbam),file(ssidx) from msibam
output:
file("${caseid}*") into msiout
script:
if ( somatic[caseid] == true )
"""
bash ${repoDir}/process_scripts/variants/msisensor.sh -r ${index_path} -p $caseid -b ${tid}.bam -n ${nid}.bam -c $capturebed
"""
else
"""
bash ${repoDir}/process_scripts/variants/msisensor.sh -r ${index_path} -p $caseid -b ${tid}.bam -c $capturebed
"""
}
process checkmates {
queue '32GB,super'
label 'profiling_qc'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
errorStrategy 'ignore'
input:
set caseid,tid,nid,file(bam),file(bidx) from checkbams
output:
file("${caseid}*") into checkmateout
when: somatic[caseid] == true
script:
"""
bash ${repoDir}/process_scripts/variants/checkmate.sh -r ${index_path} -p ${caseid} -c ${index_path}/NGSCheckMate.bed -f
"""
}
process pindel {
errorStrategy 'ignore'
label 'structuralvariant'
queue '128GB,256GB,256GBv1'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,tid,nid,file(ssbam),file(ssidx) from pindelbam
output:
file("${caseid}.pindel_tandemdup.vcf.gz") into tdvcf
set caseid,file("${caseid}.pindel.vcf.gz") into pindelvcf
file("${caseid}.pindel.genefusion.txt") into pindelgf
script:
"""
bash ${repoDir}/process_scripts/variants/svcalling.sh -r $index_path -p $caseid -l ${index_path}/itd_genes.bed -a pindel -c ${index_path}/cancer_gene_list.bed -g $params.snpeff_vers -f
"""
}
process sv {
queue '32GB,super'
label 'structuralvariant'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,tid,nid,file(ssbam),file(ssidx) from svbam
each algo from svalgo
output:
set caseid,file("${caseid}.${algo}.vcf.gz") into svvcf
set caseid,file("${caseid}.${algo}.sv.vcf.gz") optional true into svsv
file("${caseid}.${algo}.genefusion.txt") into svgf
script:
if ( somatic[caseid] == true )
"""
bash ${repoDir}/process_scripts/variants/svcalling.sh -r $index_path -x ${tid} -y ${nid} -b ${tid}.bam -n ${nid}.bam -p $caseid -a ${algo} -g $params.snpeff_vers -f
"""
else
"""
bash ${repoDir}/process_scripts/variants/svcalling.sh -r $index_path -b ${tid}.bam -p $caseid -a ${algo} -g $params.snpeff_vers -f
"""
}
process mutect {
queue '128GB,256GB,256GBv1'
label 'variantcalling'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,tid,nid,file(ssbam),file(ssidx) from mutectbam
output:
set caseid,file("${caseid}.mutect.vcf.gz") into mutectvcf
set caseid,file("${caseid}.mutect.ori.vcf.gz") into mutectori
script:
if ( somatic[caseid] == true )
"""
bash ${repoDir}/process_scripts/variants/somatic_vc.sh $ponopt -r $index_path -p $caseid -x $tid -y $nid -t ${tid}.final.bam -n ${nid}.final.bam -b $capturebed -a mutect
bash ${repoDir}/process_scripts/variants/uni_norm_annot.sh -g $params.snpeff_vers -r $index_path -p ${caseid}.mutect -v ${caseid}.mutect.vcf.gz
"""
else
"""
bash ${repoDir}/process_scripts/variants/germline_vc.sh $ponopt -r $index_path -p $caseid -b $capturebed -a mutect
bash ${repoDir}/process_scripts/variants/uni_norm_annot.sh -g $params.snpeff_vers -r $index_path -p ${caseid}.mutect -v ${caseid}.mutect.vcf.gz
"""
}
process somvc {
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
label 'variantcalling'
errorStrategy { sleep(Math.pow(2, task.attempt) * 200 as long); return 'retry' }
maxErrors 20
queue '32GB,super'
input:
set caseid,tid,nid,file(ssbam),file(ssidx) from sombam
each algo from ssalgo
output:
set caseid,file("${caseid}.${algo}.vcf.gz") into ssvcf
set caseid,file("${caseid}.${algo}.ori.vcf.gz") into ssori
when:
somatic[caseid] == true
script:
"""
bash ${repoDir}/process_scripts/variants/somatic_vc.sh -r $index_path -p $caseid -x $tid -y $nid -n ${nid}.consensus.bam -t ${tid}.consensus.bam -a ${algo} -b $capturebed
bash ${repoDir}/process_scripts/variants/uni_norm_annot.sh -g $params.snpeff_vers -r $index_path -p ${caseid}.${algo} -v ${caseid}.${algo}.vcf.gz
"""
}
process germvc {
queue '32GB,super'
label 'variantcalling'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,tid,nid,file(gbam),file(gidx) from germbam
each algo from fpalgo
output:
set caseid,file("${caseid}.${algo}.vcf.gz") into germvcf
set caseid,file("${caseid}.${algo}.ori.vcf.gz") into germori
script:
"""
bash ${repoDir}/process_scripts/variants/germline_vc.sh -r $index_path -p $caseid -a ${algo} -b $capturebed
bash ${repoDir}/process_scripts/variants/uni_norm_annot.sh -g $params.snpeff_vers -r $index_path -p ${caseid}.${algo} -v ${caseid}.${algo}.vcf.gz
"""
}
process germstrelka {
queue '32GB,super'
label 'variantcalling'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnacallset", mode: 'copy'
input:
set caseid,tid,nid,file(gbam),file(gidx) from strelkabam
output:
set caseid,file("${caseid}.strelka2.vcf.gz") into strelkavcf
set caseid,file("${caseid}.strelka2.ori.vcf.gz") into strelkaori
when:
somatic[caseid] == false
script:
"""
bash ${repoDir}/process_scripts/variants/germline_vc.sh -r $index_path -p $caseid -a strelka2 -b $capturebed
bash ${repoDir}/process_scripts/variants/uni_norm_annot.sh -g $params.snpeff_vers -r $index_path -p ${caseid}.strelka2 -v ${caseid}.strelka2.vcf.gz
"""
}
Channel
.empty()
.mix(mutectvcf,ssvcf,pindelvcf,germvcf,strelkavcf)
.groupTuple(by:0)
.set { vcflist}
process integrate {
executor 'local'
label 'variantcalling'
errorStrategy 'ignore'
publishDir "$params.output/$caseid/dnavcf", mode: 'copy'
input:
set caseid,file(vcf) from vcflist
output:
file("${caseid}.union.vcf.gz") into unionvcf
script:
"""
bash ${repoDir}/process_scripts/variants/union.sh -r $index_path -p $caseid
#cp ${caseid}.union.vcf.gz ${caseid}.dna.vcf.gz
"""
}