forked from jasteen/nextflow-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgbio_somatic_pipeline_split_vardict_cross_extras_stats_LONG.nf
734 lines (547 loc) · 23.6 KB
/
fgbio_somatic_pipeline_split_vardict_cross_extras_stats_LONG.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
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/usr/bin/env nextflow
// Required Inputs
refFolder = file("/projects/vh83/reference/genomes/b37/bwa_0.7.12_index/")
inputDirectory = file('./fastqs')
panel_int = file('/projects/vh83/reference/sureselect/medha_exome_panel/S30409818_Regions_b37.interval_list')
padded_int = file('/projects/vh83/reference/sureselect/medha_exome_panel/S30409818_Padded_b37.interval_list')
panel_bed = file('/projects/vh83/reference/sureselect/medha_exome_panel/S30409818_Regions_b37.bed')
padded_bed = file('/projects/vh83/reference/sureselect/medha_exome_panel/S30409818_Padded_b37.bed')
tmp_dir = file('/scratch/vh83/tmp/')
// Getting Reference Files
refBase = "$refFolder/human_g1k_v37_decoy"
ref = file("${refBase}.fasta")
refDict = file("${refBase}.dict")
refFai = file("${refBase}.fasta.fai")
millsIndels = file("${refFolder}/accessory_files/Mills_and_1000G_gold_standard.indels.b37.vcf")
dbSNP = file("${refFolder}/accessory_files/dbsnp_138.b37.vcf")
header = file("/home/jste0021/vh83/reference/genomes/b37/vcf_contig_header_lines.txt")
af_thr = 0.1
rheader = file("/projects/vh83/pipelines/code/Rheader.txt")
//VEP
//Annotation resources
dbsnp_b37 = file("/projects/vh83/reference/genomes/b37/accessory_files/dbsnp_138.b37.vcf")
other_vep = file("/usr/local/vep/90/ensembl-vep/cache")
vep_brcaex = file("/projects/vh83/reference/annotation_databases/BRCA-Exchange/BRCA-exchange_accessed-180118/BRCA-exchange_accessed-180118.sort.vcf.gz")
vep_gnomad = file("/projects/vh83/reference/annotation_databases/gnomAD/gnomad.exomes.r2.0.2.sites/gnomad.exomes.r2.0.2.sites.vcf.gz")
vep_revel = file("/projects/vh83/reference/annotation_databases/REVEL/REVEL-030616/revel_all_chromosomes.vcf.gz")
vep_maxentscan = file("/projects/vh83/reference/annotation_databases/MaxEntScan/MaxEntScan_accessed-240118")
vep_exac = file("/projects/vh83/reference/annotation_databases/ExAC/ExAC_nonTCGA.r0.3.1/ExAC_nonTCGA.r0.3.1.sites.vep.vcf.gz")
vep_dbnsfp = file("/projects/vh83/reference/annotation_databases/dbNSFP/dbNSFPv2.9.3-VEP/dbNSFP-2.9.3.gz")
vep_dbscsnv = file("/projects/vh83/reference/annotation_databases/dbscSNV/dbscSNV1.0-VEP/dbscSNV.txt.gz")
vep_cadd = file("/projects/vh83/reference/annotation_databases/CADD/CADD-v1.3/1000G_phase3.tsv.gz")
// Tools
picardJar = '~/picard.jar'
bwaModule = 'bwa/0.7.17-gcc5'
samtoolsModule = 'samtools/1.9'
gatkModule = 'gatk/4.0.11.0'
rModule = 'R/3.5.1'
fgbioJar = '/usr/local/fgbio/0.9.0/target/fgbio-0.9.0-17cb5fb-SNAPSHOT.jar'
condaModule = 'miniconda3/4.1.11-python3.5'
// Creating channel from input directory
Channel.fromFilePairs("$inputDirectory/*_{R1,R2,I2}.fastq.gz", size: 3, flat: true).into{ch_inputFiles;ch_forFastqc}
process runFASTQC {
label 'small_2'
input:
set baseName, file(R1), file(R2), file(I2) from ch_forFastqc
output:
file("*.{html,zip}") into ch_fastqcReports
publishDir path: './output/metrics/fastqc', mode: 'copy'
module 'fastqc'
script:
"""
fastqc -t ${task.cpus} -q $R1 $R2 $I2
"""
}
process createUnmappedUMIBam {
label 'medium_6h'
publishDir path: './output/intermediate', mode: 'copy'
input:
set baseName, file(I2), file(R1), file(R2) from ch_inputFiles
output:
set baseName, file("${baseName}.unmapped.umi.bam") into ch_unmappedUMIbams
//publishDir path: './output/intermediate', mode: 'copy'
module 'fgbio'
module 'java'
script:
"""
java -Xmx${task.memory.toGiga() - 2}g -Djava.io.tmpdir=$tmp_dir \
-jar $fgbioJar FastqToBam --input $R1 $R2 $I2 --output "${baseName}.unmapped.umi.bam" --read-structures +T +T +M \
--sample "${baseName}" --read-group-id "${baseName}" --library A --platform illumina --sort true
"""
}
process markAdaptors {
label 'medium_6h'
publishDir path: './output/metrics/adaptor_marking', mode: 'copy', pattern: '*.tsv'
input:
set baseName, file(bam) from ch_unmappedUMIbams
output:
set baseName, file("${baseName}.unmapped.umi.marked.bam"),
file("${baseName}.unmapped.umi.marked_metrics.tsv") into ch_markedUMIbams, ch_adaptorQC
module 'java'
script:
"""
java -Dpicard.useLegacyParser=false -Xmx${task.memory.toGiga() - 2}g -jar $picardJar MarkIlluminaAdapters \
-INPUT $bam \
-OUTPUT "${baseName}.unmapped.umi.marked.bam" \
-METRICS "${baseName}.unmapped.umi.marked_metrics.tsv"
"""
}
process alignBwa {
label 'bwa'
input:
set baseName, file(bam), file(metrics) from ch_markedUMIbams
output:
set baseName, file("${baseName}.aligned.bam") into ch_pipedBams, ch_mappedNoUMI, ch_forMetrics1
publishDir path: './output/bams', mode: 'copy'
module bwaModule
module 'samtools'
module 'picard'
script:
"""
set -o pipefail
java -Dpicard.useLegacyParser=false -Xmx${ (task.memory.toGiga() / 6).toInteger() }g -jar $picardJar SamToFastq \
-I "$bam" \
-FASTQ '/dev/stdout' -CLIPPING_ATTRIBUTE XT -CLIPPING_ACTION 2 \
-INTERLEAVE true -NON_PF true -TMP_DIR "$tmp_dir" | \
bwa mem -M -t ${task.cpus} -p $ref /dev/stdin | \
java -Dpicard.useLegacyParser=false -Xmx${(task.memory.toGiga() / 6).toInteger() }g -jar $picardJar MergeBamAlignment \
-ALIGNED_BAM '/dev/stdin' -UNMAPPED_BAM "$bam" \
-OUTPUT "${baseName}.aligned.bam" -R "$ref" -ADD_MATE_CIGAR true \
-CLIP_ADAPTERS false -MAX_INSERTIONS_OR_DELETIONS '-1' \
-PRIMARY_ALIGNMENT_STRATEGY MostDistant -ATTRIBUTES_TO_RETAIN XS -TMP_DIR "$tmp_dir"
"""
}
process indexPreUmiBam {
label 'small_1'
input:
set baseName, file(bam) from ch_mappedNoUMI
output:
set baseName, file(bam), file("${baseName}.aligned.bam.bai") into ch_indexedMappedNoUMI
publishDir path: './output/bams', mode: 'copy'
module 'samtools'
script:
"""
samtools index $bam ${baseName}.aligned.bam.bai
"""
}
ch_tumorPREUMI = Channel.create()
ch_normalPREUMI = Channel.create()
//split single bam channel into tumor and normal **CURRENTLY RELIES ON "SAMPLE_[FFPE|NORMAL]" naming scheme
ch_indexedMappedNoUMI.choice(ch_tumorPREUMI, ch_normalPREUMI){ a -> a[0] =~ /FFPE/ ? 0 : 1 }
//ch_mappedNoUMI.flatten().choice(ch_tumorPREUMI, ch_normalPREUMI){ a -> a[0] =~ /FFPE/ ? 0 : 1 }
//split SAMPLE from FFPE|NORMAL so channels can be joined by sample
ch_normalSplitPREUMI = ch_normalPREUMI.map{ baseName, bam, bai -> [ baseName.split('_')[0], baseName.split('_')[1], bam, bai]}
ch_tumorSplitPREUMI = ch_tumorPREUMI.map{ baseName, bam, bai -> [ baseName.split('_')[0], baseName.split('_')[1], bam, bai]}
//merge tumor and normal back together by sample number.
ch_tumorNormalPairsPREUMI = ch_tumorSplitPREUMI.join(ch_normalSplitPREUMI)
ch_bedSegments2 = Channel.fromPath("$padded_bed").splitText( by: 50000, file: "seg")
ch_vardictPREUMI= ch_tumorNormalPairsPREUMI.combine(ch_bedSegments2)
process runVardictPREUMI {
label 'vardict'
input:
set sample, ttype, file(tbam), file(tbai), ntype, file(nbam), file(nbai), file(segment) from ch_vardictPREUMI
output:
set sample, file(tbam), file(nbam), file("${sample}.${ttype}_v_${ntype}.${segment}.somatic.vardict.tsv") into ch_rawVardictSegmentsPREUMI
script:
"""
export PATH=/home/jste0021/scripts/VarDict-1.5.8/bin/:$PATH
VarDict -G ${ref} -f 0.01 -N "${tbam}|${nbam}" \
-b "${tbam}|${nbam}" -th ${task.cpus} --nosv -c 1 -S 2 -E 3 -g 4 ${segment} \
> "${sample}.${ttype}_v_${ntype}.${segment}.somatic.vardict.tsv"
"""
}
ch_collatedSegmentsPREUMI = ch_rawVardictSegmentsPREUMI.map{ sample, tbam, nbam, segment -> [sample, tbam.name, nbam.name, segment]}.groupTuple(by: [0,1,2])
process catSegmentsPREUMI {
label 'small_1'
echo true
input:
set sample, tbam, nbam, file(tsv) from ch_collatedSegmentsPREUMI
output:
set sample, tbam, nbam, file("${sample}.collated.vardict.tsv") into ch_rawVardictPREUMI
script:
myfiles = tsv.collect().join(' ')
"""
cat ${myfiles} > ${sample}.collated.vardict.tsv
"""
}
process makeVCFPREUMI {
label 'medium_6h'
input:
set sample, tbam, nbam, file(tsv) from ch_rawVardictPREUMI
output:
set sample, file("${sample}.somatic.vardict.vcf") into ch_outputVCFPREUMI
//publishDir path: './output/vcf/somatic', mode: 'copy'
script:
"""
module purge
module load R/3.5.1
cat $tsv | /home/jste0021/scripts/VarDict-1.5.8/bin/testsomatic.R | \
/home/jste0021/scripts/VarDict-1.5.8/bin/var2vcf_paired.pl -N "${tbam}|${nbam}" \
-f 0.01 > "${sample}.somatic.vardict.vcf"
"""
}
process reheaderPREUMIVCF {
label 'small_1'
input:
set sample, file(vcf) from ch_outputVCFPREUMI
output:
set sample, file("*.vcf.gz") into ch_reheaderVCFPREUMI
//publishDir path: './output/preUMI/intermediate', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools annotate -h ~/vh83/reference/genomes/b37/vcf_contig_header_lines.txt -O v ${vcf} | \
bcftools sort -o ${sample}.vardict.sorted.vcf.gz -O z -
"""
}
process sortVCFSPREUMI {
label 'medium_6h'
input:
set baseName, file(vcf) from ch_reheaderVCFPREUMI
output:
set baseName, file("${baseName}.NoUMI.reheader.sorted.vcf.gz") into ch_sortedVCFPREUMI
publishDir path: './output/vcf/noUMI', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools sort -o "${baseName}.NoUMI.reheader.sorted.vcf.gz" -O z ${vcf}
"""
}
process indexVCFSPREUMI {
label 'medium_1h'
input:
set baseName, file(vcf) from ch_sortedVCFPREUMI
output:
set baseName, file(vcf), file("${baseName}.NoUMI.reheader.sorted.vcf.gz.tbi") into ch_indexedVCFPREUMI
publishDir path: './output/vcf/noUMI', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools index -f --tbi ${vcf} -o ${baseName}.NoUMI.reheader.sorted.vcf.gz.tbi
"""
}
process vt_decompose_normalisePREUMI {
label 'medium_6h'
input:
set baseName, file(vcf), file(tbi) from ch_indexedVCFPREUMI
output:
set baseName, file("${baseName}.NoUMI.reheader.sorted.vt.vcf.gz") into ch_vtDecomposeVCFPREUMI
//publishDir path: './output/preUMI/intermediate', mode: 'copy'
module 'vt'
script:
"""
vt decompose -s $vcf | vt normalize -r $ref -o "${baseName}.NoUMI.reheader.sorted.vt.vcf.gz" -
"""
}
process apply_vepPREUMI {
label 'vep'
input:
set baseName, file(vcf) from ch_vtDecomposeVCFPREUMI
output:
set baseName, file("${baseName}.NoUMI.reheader.sorted.vt.vep.vcf") into ch_vepVCFPREUMI
publishDir path: './output/vcf/noUMI', mode: 'copy'
module 'vep/90'
"""
vep --cache --dir_cache $other_vep \
--assembly GRCh37 --refseq --offline \
--fasta $ref \
--sift b --polyphen b --symbol --numbers --biotype \
--total_length --hgvs --format vcf \
--vcf --force_overwrite --flag_pick --no_stats \
--custom $vep_brcaex,brcaex,vcf,exact,0,Clinical_significance_ENIGMA,Comment_on_clinical_significance_ENIGMA,Date_last_evaluated_ENIGMA,Pathogenicity_expert,HGVS_cDNA,HGVS_Protein,BIC_Nomenclature \
--custom $vep_gnomad,gnomAD,vcf,exact,0,AF_NFE,AN_NFE \
--custom $vep_revel,RVL,vcf,exact,0,REVEL_SCORE \
--plugin MaxEntScan,$vep_maxentscan \
--plugin ExAC,$vep_exac,AC,AN \
--plugin dbNSFP,$vep_dbnsfp,REVEL_score,REVEL_rankscore \
--plugin dbscSNV,$vep_dbscsnv \
--plugin CADD,$vep_cadd \
--fork ${task.cpus} \
-i ${vcf} \
-o "${baseName}.NoUMI.reheader.sorted.vt.vep.vcf"
"""
}
process groupreadsByUmi {
label 'medium_6h'
input:
set baseName, file(bam) from ch_pipedBams
output:
set baseName, file("${baseName}.piped.grouped.histogram.tsv"), file("${baseName}.piped.grouped.bam") into ch_umiGroupedBams
publishDir path: './output/metrics/UMI/family_sizes', mode: 'copy', pattern: "*.tsv"
script:
"""
java -Xmx${task.memory.toGiga() - 2}g -Djava.io.tmpdir=$tmp_dir -jar $fgbioJar GroupReadsByUmi \
-i ${bam} -f "${baseName}.piped.grouped.histogram.tsv" -o "${baseName}.piped.grouped.bam" -s Adjacency -e 1
"""
}
process generateConsensusReads {
label 'medium_6h'
input:
set baseName, file(hist), file(bam) from ch_umiGroupedBams
output:
set baseName, file("${baseName}.consensus.unmapped.bam") into ch_unmappedConsensusBams
//publishDir path: './output/UMI/intermediate', mode: 'copy'
script:
"""
java -Xmx${task.memory.toGiga() - 2}g -Djava.io.tmpdir=$tmp_dir -jar $fgbioJar CallMolecularConsensusReads \
--input $bam --output ${baseName}.consensus.unmapped.bam \
--error-rate-post-umi 30 --min-reads 1
"""
}
//process filterConsensusReads {
// input:
// set baseName, file(bam) from unmappedConsensusBams
// output:
// set baseName, file("${baseName}.consensus.filtered.unmapped.bam") into filteredConsensusBams
// publishDir path: './output', mode: 'copy'
//
// executor globalExecutor
// stageInMode globalStageInMode
// module 'java'
// module 'fgbio'
// cpus globalCores
// memory globalMemoryM
// time globalTimeM
// queue globalQueueL
//
//
// """
// java -Xmx6g -jar '/usr/local/fgbio/0.9.0/target/fgbio-0.9.0-17cb5fb-SNAPSHOT.jar' FilterConsensusReads \
// --input $bam --output ${baseName}.consensus.filtered.unmapped.bam \
// --ref $ref --reverse-per-base-tags true --min-reads 1 \
// -E 0.05 -N 40 -e 0.1 -n 0.1
// """
//
//}
process mapConsensusReads {
label 'bwa'
input:
set baseName, file(bam) from ch_unmappedConsensusBams
output:
set baseName, file("${baseName}.consensus.aligned.bam") into ch_mappedConsensusBams, ch_forMetrics2
publishDir path: './output/bams', mode: 'copy'
module bwaModule
script:
"""
java -Dpicard.useLegacyParser=false -Xmx${ (task.memory.toGiga() / 6).toInteger() }g -jar $picardJar SamToFastq \
-I "$bam" \
-FASTQ /dev/stdout \
-INTERLEAVE true -TMP_DIR $tmp_dir | \
bwa mem -M -t ${task.cpus} -p $ref /dev/stdin | \
java -Dpicard.useLegacyParser=false -Xmx${ (task.memory.toGiga() / 6).toInteger() }g -jar $picardJar MergeBamAlignment \
-ALIGNED_BAM /dev/stdin -UNMAPPED_BAM "$bam" \
-OUTPUT "${baseName}.consensus.aligned.bam" -R $ref -ADD_MATE_CIGAR true \
-SO coordinate -CLIP_ADAPTERS false -MAX_INSERTIONS_OR_DELETIONS '-1' \
-PRIMARY_ALIGNMENT_STRATEGY MostDistant -ATTRIBUTES_TO_RETAIN XS -TMP_DIR "$tmp_dir"
"""
}
process indexBam {
label 'small_1'
input:
set baseName, file(bam) from ch_mappedConsensusBams
output:
set baseName, file(bam), file("${baseName}.consensus.aligned.bam.bai") into ch_indexedConsensusBams
publishDir path: './output/bams', mode: 'copy'
module 'samtools'
script:
"""
samtools index $bam ${baseName}.consensus.aligned.bam.bai
"""
}
//I cant think of a better workflow to make sure Tumor and Normal are processed in order
//create channel for normal and tumor
ch_tumor = Channel.create()
ch_normal = Channel.create()
//split single bam channel into tumor and normal **CURRENTLY RELIES ON "SAMPLE_[FFPE|NORMAL]" naming scheme
ch_indexedConsensusBams.choice(ch_tumor, ch_normal){ a -> a[0] =~ /FFPE/ ? 0 : 1 }
//split SAMPLE from FFPE|NORMAL so channels can be joined by sample
ch_normalSplit = ch_normal.map{ baseName, bam, bai -> [ baseName.split('_')[0], baseName.split('_')[1], bam, bai]}
ch_tumorSplit = ch_tumor.map{ baseName, bam, bai -> [ baseName.split('_')[0], baseName.split('_')[1], bam, bai]}
//merge tumor and normal back together by sample number.
ch_tumorNormalPairs = ch_tumorSplit.join(ch_normalSplit)
//create bedfile segments
ch_bedSegments = Channel.fromPath("$padded_bed").splitText( by: 50000, file: "seg")
//create cartesian product of the input channel and the segments files
ch_vardictInput = ch_tumorNormalPairs.combine(ch_bedSegments)
process runVardict {
label 'vardict'
input:
set sample, ttype, file(tbam), file(tbai), ntype, file(nbam), file(nbai), file(segment) from ch_vardictInput
output:
set sample, file(tbam), file(nbam), file("${sample}.${ttype}_v_${ntype}.${segment}.somatic.vardict.tsv") into ch_rawVardictSegments
script:
"""
export PATH=/home/jste0021/scripts/VarDict-1.5.8/bin/:$PATH
VarDict -G ${ref} -f 0.01 -N "${tbam}|${nbam}" \
-b "${tbam}|${nbam}" -th ${task.cpus} --nosv -c 1 -S 2 -E 3 -g 4 ${segment} \
> "${sample}.${ttype}_v_${ntype}.${segment}.somatic.vardict.tsv"
"""
}
ch_collatedSegments = ch_rawVardictSegments.map{ sample, tbam, nbam, segment -> [sample, tbam.name, nbam.name, segment]}.groupTuple(by: [0,1,2])
process catSegments {
label 'small_1'
echo true
input:
set sample, tbam, nbam, file(tsv) from ch_collatedSegments
output:
set sample, tbam, nbam, file("${sample}.collated.vardict.tsv") into ch_rawVardict
script:
myfiles = tsv.collect().join(' ')
"""
cat ${myfiles} > ${sample}.collated.vardict.tsv
"""
}
process makeVCF {
label 'medium_6h'
input:
set sample, tbam, nbam, file(tsv) from ch_rawVardict
output:
set sample, file("${sample}.somatic.vardict.vcf") into ch_outputVCF
//publishDir path: './output/UMI/intermediate', mode: 'copy'
script:
"""
module purge
module load R/3.5.1
cat $tsv | /home/jste0021/scripts/VarDict-1.5.8/bin/testsomatic.R | \
/home/jste0021/scripts/VarDict-1.5.8/bin/var2vcf_paired.pl -N "${tbam}|${nbam}" -f 0.01 > "${sample}.somatic.vardict.vcf"
"""
}
process reheaderUMIVCF {
label 'small_1'
input:
set sample, file(vcf) from ch_outputVCF
output:
set sample, file("*.vcf.gz") into ch_reheaderVCF
//publishDir path: './output/UMI/intermediate', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools annotate -h ~/vh83/reference/genomes/b37/vcf_contig_header_lines.txt -O v ${vcf} | \
bcftools sort -o ${sample}.vardict.sorted.vcf.gz -O z -
"""
}
process sortVCFS {
label 'medium_6h'
input:
set baseName, file(vcf) from ch_reheaderVCF
output:
set baseName, file("${baseName}.UMI.reheader.sorted.vcf.gz") into ch_sortedVCF
//publishDir path: './output/vcf/UMI', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools sort -o "${baseName}.UMI.reheader.sorted.vcf.gz" -O z ${vcf}
"""
}
process indexVCFS {
label 'small_1'
input:
set baseName, file(vcf) from ch_sortedVCF
output:
set baseName, file(vcf), file("${baseName}.UMI.reheader.sorted.vcf.gz.tbi") into ch_indexedVCF
publishDir path: './output/vcf/UMI', mode: 'copy'
module 'bcftools/1.8'
script:
"""
bcftools index -f --tbi ${vcf} -o ${baseName}.UMI.reheader.sorted.vcf.gz.tbi
"""
}
process vt_decompose_normalise {
label 'medium_6h'
input:
set baseName, file(vcf), file(tbi) from ch_indexedVCF
output:
set baseName, file("${baseName}.UMI.reheader.sorted.vt.vcf.gz") into ch_vtDecomposeVCF
//publishDir path: './output/UMI/intermediate', mode: 'copy'
module 'vt'
script:
"""
vt decompose -s $vcf | vt normalize -r $ref -o "${baseName}.UMI.reheader.sorted.vt.vcf.gz" -
"""
}
process apply_vep {
label 'vep'
input:
set baseName, file(vcf) from ch_vtDecomposeVCF
output:
set baseName, file("${baseName}.UMI.VEP_Stats.html"), file("${baseName}.UMI.reheader.sorted.vt.vep.vcf") into ch_vepVCF
publishDir path: './output/vcf/UMI', mode: 'copy', pattern: "*.vcf"
publishDir path: './output/metrics/vep_stats', mode: 'copy', pattern: "*.html"
module 'vep/90'
script:
"""
vep --cache --dir_cache $other_vep \
--assembly GRCh37 --refseq --offline \
--fasta $ref \
--sift b --polyphen b --symbol --numbers --biotype \
--total_length --hgvs --format vcf \
--vcf --force_overwrite --flag_pick --stats_file "${baseName}.UMI.VEP_Stats.html" \
--custom $vep_brcaex,brcaex,vcf,exact,0,Clinical_significance_ENIGMA,Comment_on_clinical_significance_ENIGMA,Date_last_evaluated_ENIGMA,Pathogenicity_expert,HGVS_cDNA,HGVS_Protein,BIC_Nomenclature \
--custom $vep_gnomad,gnomAD,vcf,exact,0,AF_NFE,AN_NFE \
--custom $vep_revel,RVL,vcf,exact,0,REVEL_SCORE \
--plugin MaxEntScan,$vep_maxentscan \
--plugin ExAC,$vep_exac,AC,AN \
--plugin dbNSFP,$vep_dbnsfp,REVEL_score,REVEL_rankscore \
--plugin dbscSNV,$vep_dbscsnv \
--plugin CADD,$vep_cadd \
--fork ${task.cpus} \
-i ${vcf} \
-o "${baseName}.UMI.reheader.sorted.vt.vep.vcf"
"""
}
//ch_forMetrics = ch_forMetrics1.concat(ch_forMetrics2)
ch_forMetrics1.concat(ch_forMetrics2).into{ch_forMultipleMetrics;ch_forHSMetrics}
process collectHSMetrics {
label 'medium_6h'
input:
set sample, file(bam) from ch_forHSMetrics
output:
set sample, file("*.HSmetrics.txt"), file("*.pertarget.txt") into ch_metrics
publishDir path: './output/metrics/coverage', mode: 'copy'
script:
"""
module purge
module load R/3.5.1
java -Dpicard.useLegacyParser=false -Xmx${task.memory.toGiga() - 2}g -jar ${picardJar} CollectHsMetrics \
-I ${bam} \
-O "${bam.baseName}.HSmetrics.txt" \
-R ${ref} \
-BI $panel_int \
-TI $padded_int \
--PER_TARGET_COVERAGE "${bam.baseName}.pertarget.txt"
"""
}
process collectMultipleMetrics {
label 'medium_6h'
input:
set sample, file(bam) from ch_forMultipleMetrics
output:
set sample, file("*multiple_metrics*") into ch_metrics2
publishDir path: './output/metrics/multiple', mode: 'copy'
script:
"""
module purge
module load R/3.5.1
java -Dpicard.useLegacyParser=false -Xmx${task.memory.toGiga() - 2}g -jar ${picardJar} CollectMultipleMetrics \
-I $bam \
-O ${bam.baseName}.multiple_metrics \
-R $ref
"""
}
process multiQC {
label 'medium_6h'
input:
file('coverage/*') from ch_metrics2.collect()
file('multiple/*') from ch_metrics.collect()
file('fastqc/*') from ch_fastqcReports.collect()
file('adaptor/*') from ch_adaptorQC.collect()
output:
set file("*multiqc_report.html"), file("*multiqc_data") into ch_multiQCOut
publishDir path: './output/metrics/report', mode: 'copy'
module condaModule
conda '/home/jste0021/.conda/envs/py3.5/'
script:
"""
multiqc -f -v .
"""
}