forked from icbi-lab/nextNEOpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextNEOpi.nf
7535 lines (6302 loc) · 234 KB
/
nextNEOpi.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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nextflow
log.info ""
log.info " NEXTFLOW ~ version ${workflow.nextflow.version} ${workflow.nextflow.build}"
log.info "-------------------------------------------------------------------------"
log.info " Nextfow NeoAntigen Prediction Pipeline - nextNEOpi "
log.info "-------------------------------------------------------------------------"
log.info ""
log.info " Features: "
log.info " - somatic variants from tumor + matched normal samples"
log.info " - CNV analysis"
log.info " - tumor muational burden"
log.info " - class I and class II HLA typing"
log.info " - gene fusion peptide prediction using RNAseq data"
log.info " - peptide MHC binding perdiction"
log.info " - clonality of neoantigens"
log.info " - expression of neoantigens"
log.info ""
log.info "-------------------------------------------------------------------------"
log.info "C O N F I G U R A T I O N"
log.info ""
log.info "Command Line: \t\t " + workflow.commandLine
log.info "Working Directory: \t " + params.workDir
log.info "Output Directory: \t " + params.outputDir
log.info ""
log.info "I N P U T"
log.info ""
if (params.readsTumor != "NO_FILE") log.info " Reads Tumor: \t\t " + params.readsTumor
if (params.readsNormal != "NO_FILE") log.info " Reads Normal: \t\t " + params.readsNormal
if (params.readsRNAseq != "NO_FILE") log.info " Reads RNAseq: \t\t " + params.readsRNAseq
if (params.customHLA != "NO_FILE") log.info " Custom HLA file: \t\t " + params.customHLA
log.info ""
log.info "Please check --help for further instruction"
log.info "-------------------------------------------------------------------------"
// Check if License(s) were accepted
params.accept_license = false
if (params.accept_license) {
acceptLicense()
} else {
checkLicense()
}
/*
________________________________________________________________________________
C O N F I G U R A T I O N
________________________________________________________________________________
*/
if (params.help) exit 0, helpMessage()
// switch for enable/disable processes (debug/devel only: use if(params.RUNTHIS) { .... })
params.RUNTHIS = false
// default is not to process a batchfile
params.batchFile = false
// default is not to get bams as input data
bamInput = false
// we got bam input on cmd line
if (! params.batchFile) {
if(params.bamTumor != "NO_FILE" && params.readsTumor == "NO_FILE") {
bamInput = true
} else if(params.bamTumor == "NO_FILE" && params.readsTumor != "NO_FILE") {
bamInput = false
} else if(params.bamTumor != "NO_FILE" &&
(params.readsTumor != "NO_FILE" ||
params.readsNormal != "NO_FILE" ||
params.readsRNAseq != "NO_FILE")) {
exit 1, "Please do not provide tumor data as BAM and FASTQ"
}
} else {
batchCSV = file(params.batchFile).splitCsv(header:true)
validFQfields = ["tumorSampleName",
"readsTumorFWD",
"readsTumorREV",
"normalSampleName",
"readsNormalFWD",
"readsNormalREV",
"readsRNAseqFWD",
"readsRNAseqREV",
"HLAfile",
"sex"]
validBAMfields = ["tumorSampleName",
"bamTumor",
"normalSampleName",
"bamNormal",
"bamRNAseq",
"HLAfile",
"sex"]
if (batchCSV.size() > 0) {
if (batchCSV[0].keySet().sort() == validFQfields.sort()) {
bamInput = false
} else if (batchCSV[0].keySet().sort() == validBAMfields.sort()) {
bamInput = true
} else {
exit 1, "Error: Incorrect fields in batch file, please check your batchFile"
}
} else {
exit 1, "Error: No samples found, please check your batchFile"
}
}
// set single_end variable to supplied param
single_end = false
single_end_RNA = false
// initialize RNAseq presence
have_RNAseq = false
// initialize RNA tag seq
have_RNA_tag_seq = params.RNA_tag_seq
// initialize custom HLA types presence
use_custom_hlas = false
// set and initialize the Exome capture kit
setExomeCaptureKit(params.exomeCaptureKit)
// set and check references and databases
reference = defineReference()
database = defineDatabases()
// create tmp dir and make sure we have the realpath for it
tmpDir = mkTmpDir(params.tmpDir)
/*--------------------------------------------------
For workflow summary
---------------------------------------------------*/
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if ( !(workflow.runName ==~ /[a-z]+_[a-z]+/) ) {
custom_runName = workflow.runName
}
// Summary
def summary = [:]
summary['Pipeline Name'] = 'icbi/nextNEOpi'
summary['Pipeline Version'] = workflow.manifest.version
if(params.batchFile) summary['Batch file'] = params.batchFile
if(params.readsNormal != "NO_FILE") summary['Reads normal fastq files'] = params.readsNormal
if(params.readsTumor != "NO_FILE") summary['Reads tumor fastq files'] = params.readsTumor
if(params.customHLA != "NO_FILE") summary['Custom HLA file'] = params.customHLA
summary['Sex'] = params.sex
summary['Read length'] = params.readLength
summary['Exome capture kit'] = params.exomeCaptureKit
summary['Fasta Ref'] = params.references.RefFasta
summary['MillsGold'] = params.databases.MillsGold
summary['hcSNPS1000G'] = params.databases.hcSNPS1000G
summary['HapMap'] = params.databases.HapMap
summary['Cosmic'] = params.databases.Cosmic
summary['DBSNP'] = params.databases.DBSNP
summary['GnomAD'] = params.databases.GnomAD
summary['GnomADfull'] = params.databases.GnomADfull
summary['KnownIndels'] = params.databases.KnownIndels
summary['priority variant Caller'] = params.primaryCaller
summary['Mutect 1 and 2 minAD'] = params.minAD
summary['VarScan min_cov'] = params.min_cov
summary['VarScan min_cov_tumor'] = params.min_cov_tumor
summary['VarScan min_cov_normal'] = params.min_cov_normal
summary['VarScan min_freq_for_hom'] = params.min_freq_for_hom
summary['VarScan tumor_purity'] = params.tumor_purity
summary['VarScan somatic_pvalue'] = params.somatic_pvalue
summary['VarScan somatic_somaticpvalue'] = params.somatic_somaticpvalue
summary['VarScan strand_filter'] = params.strand_filter
summary['VarScan processSomatic_pvalue'] = params.processSomatic_pvalue
summary['VarScan max_normal_freq'] = params.max_normal_freq
summary['VarScan min_tumor_freq'] = params.min_tumor_freq
summary['VarScan min_map_q'] = params.min_map_q
summary['VarScan min_base_q'] = params.min_base_q
summary['VEP assembly'] = params.vep_assembly
summary['VEP species'] = params.vep_species
summary['VEP options'] = params.vep_options
summary['Number of scatters'] = params.scatter_count
summary['Output dir'] = params.outputDir
summary['Working dir'] = workflow.workDir
summary['TMP dir'] = tmpDir
summary['Current home'] = "$HOME"
summary['Current user'] = "$USER"
summary['Current path'] = "$PWD"
summary['JAVA_Xmx'] = params.JAVA_Xmx
summary['Picard maxRecordsInRam'] = params.maxRecordsInRam
summary['Script dir'] = workflow.projectDir
summary['Config Profile'] = workflow.profile
if(params.email) summary['E-mail Address'] = params.email
log.info summary.collect { k,v -> "${k.padRight(30)}: $v" }.join("\n")
log.info "-------------------------------------------------------------------------"
def create_workflow_summary(summary) {
def yaml_file = workDir.resolve('workflow_summary_mqc.yaml')
yaml_file.text = """
id: 'nextNEOpi-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'nextNEOpi Workflow Summary'
section_href: 'https://github.com/icbi-lab/nextNEOpi'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
${summary.collect { k,v -> " <dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }.join("\n")}
</dl>
""".stripIndent()
return yaml_file
}
// End Summary
// set DNA and RNA sample counts to 0
dna_count = 0
rna_count = 0
// did not get a CSV batch file and input is not BAM: just run a single sample
if (! params.batchFile && ! bamInput) {
// create channel with tumorSampleName/reads file set
if (params.readsTumor != "NO_FILE") {
// Sample name and reads file is passed via cmd line options
// Sample name to use, if not given uses fastq file simpleName
params.tumorSampleName = "undefined"
params.normalSampleName = "undefined"
single_end = (file(params.readsTumor) instanceof LinkedList) ? false : true
if(! single_end) {
tumorSampleName = params.tumorSampleName != "undefined" ? params.tumorSampleName : file(params.readsTumor)[0].simpleName
} else {
tumorSampleName = params.tumorSampleName != "undefined" ? params.tumorSampleName : file(params.readsTumor).simpleName
}
} else {
exit 1, "No tumor sample defined"
}
if (params.readsNormal != "NO_FILE") {
normal_libType = (file(params.readsNormal) instanceof LinkedList) ? "PE" : "SE"
if ((normal_libType == "PE" && single_end) || (normal_libType == "SE" && ! single_end)) {
exit 1, "Please do not mix pe and se for tumor/normal pairs: " + tumorSampleName + " - Not supported"
}
if(! single_end) {
normalSampleName = params.normalSampleName != "undefined" ? params.normalSampleName : file(params.readsNormal)[0].simpleName
} else {
normalSampleName = params.normalSampleName != "undefined" ? params.normalSampleName : file(params.readsNormal).simpleName
}
Channel
.fromFilePairs(params.readsTumor, size: -1)
.map { reads -> tuple(tumorSampleName,
normalSampleName,
reads[1][0],
(reads[1][1]) ? reads[1][1] : "NO_FILE_REV_T") }
.into { raw_reads_tumor_ch;
fastqc_reads_tumor_ch }
Channel
.fromFilePairs(params.readsNormal, size: -1)
.map { reads -> tuple(tumorSampleName,
normalSampleName,
reads[1][0],
(reads[1][1]) ? reads[1][1] : "NO_FILE_REV_N") }
.into { raw_reads_normal_ch; fastqc_reads_normal_ch }
} else {
exit 1, "No normal sample defined"
}
if (params.readsRNAseq) {
single_end_RNA = (file(params.readsRNAseq) instanceof LinkedList) ? false : true
Channel
.fromFilePairs(params.readsRNAseq, size: -1)
.map { reads -> tuple(tumorSampleName,
normalSampleName,
reads[1][0],
(reads[1][1]) ? reads[1][1] : "NO_FILE_RNA_REV") }
.into { raw_reads_tumor_neofuse_ch; fastqc_readsRNAseq_ch }
have_RNAseq = true
} else {
have_RNAseq = false
}
} else if ( params.batchFile && ! bamInput) {
// batchfile ()= csv with sampleId and T/N reads was provided
// create channel with all sampleId/reads file sets from the batch file
// check if reverse reads are specified, if not set up single end processing
// check if Normal reads are specified, if not set up exit with error
// attention: if one of the samples is no-Normal or single end, all others
// will be handled as such. You might want to process mixed sample data as
// separate batches.
batchCSV = file(params.batchFile).splitCsv(header:true)
pe_dna_count = 0
se_dna_count = 0
pe_rna_count = 0
se_rna_count = 0
sexMap = [:]
for ( row in batchCSV ) {
if(row.sex && row.sex != "None") {
if (row.sex in ["XX", "XY", "Female", "Male", "female", "male"]) {
sexMap[row.tumorSampleName] = (row.sex == "Female" || row.sex == "XX" || row.sex == "female") ? "XX" : "XY"
} else {
exit 1, "Sex should be one of: XX, XY, Female, Male, female, male, got: " + row.sex
}
} else {
println("WARNING: sex not specified assuming: XY")
sexMap[row.tumorSampleName] = "XY"
}
if (row.readsTumorREV == "None") {
single_end = true
se_dna_count++
} else {
pe_dna_count++
}
if (! row.readsTumorFWD || row.readsTumorFWD == "None") {
exit 1, "No tumor sample defined for " + row.tumorSampleName
} else {
dna_count++
}
if (! row.readsNormalFWD || row.readsNormalFWD == "None") {
exit 1, "No normal sample defined for " + row.tumorSampleName
}
if (! row.readsRNAseqFWD || row.readsRNAseqFWD == "None") {
have_RNAseq = false
} else {
have_RNAseq = true
if (! row.readsRNAseqREV || row.readsRNAseqREV == "None") {
single_end_RNA = true
se_rna_count++
} else {
pe_rna_count++
}
rna_count++
}
if (row.HLAfile != "None" || row.HLAfile != "") {
use_custom_hlas = true
}
}
if ((dna_count != rna_count) && (rna_count != 0)) {
exit 1, "Please do not mix samples with/without RNAseq data in batchfile"
}
if (pe_dna_count != 0 && se_dna_count != 0) {
exit 1, "Please do not mix pe and se DNA read samples in batch file. Create a separate batch file for se and pe DNA samples"
}
if (pe_rna_count != 0 && se_rna_count != 0) {
exit 1, "Please do not mix pe and se RNA read samples in batch file. Create a separate batch file for se and pe RNA samples"
}
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file(row.readsTumorFWD),
file((row.readsTumorREV == "None") ? "NO_FILE_REV_T" : row.readsTumorREV)) }
.into { raw_reads_tumor_ch;
fastqc_reads_tumor_ch }
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file(row.readsNormalFWD),
file((row.readsNormalREV == "None") ? "NO_FILE_REV_N" : row.readsNormalREV)) }
.into { raw_reads_normal_ch; fastqc_reads_normal_ch }
if (have_RNAseq) {
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file(row.readsRNAseqFWD),
file(row.readsRNAseqREV)) }
.into { raw_reads_tumor_neofuse_ch; fastqc_readsRNAseq_ch }
}
// user supplied HLA types (default: NO_FILE, will be checked in get_vhla)
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
file((row.HLAfile == "None") ? "NO_FILE_HLA" : row.HLAfile)) }
.set { custom_hlas_ch }
} else if (bamInput && ! params.batchFile) {
// bam files provided on cmd line
if (params.bamTumor != "NO_FILE") {
params.tumorSampleName = "undefined"
tumorSampleName = params.tumorSampleName != "undefined" ? params.tumorSampleName : file(params.bamTumor).simpleName
} else {
exit 1, "No tumor sample defined"
}
if (params.bamNormal != "NO_FILE") {
params.normalSampleName = "undefined"
normalSampleName = params.normalSampleName != "undefined" ? params.normalSampleName : file(params.bamNormal).simpleName
} else {
exit 1, "No normal sample defined"
}
Channel
.of(tuple(tumorSampleName,
normalSampleName,
file(params.bamTumor),
file(params.bamNormal)))
.set { dna_bam_files }
if (params.bamRNAseq) {
Channel
.of(tuple(tumorSampleName,
normalSampleName,
file(params.bamRNAseq)))
.set { rna_bam_files }
have_RNAseq = true
}
} else {
// bam files provided as batch file in CSV format
// bams will be transformed to fastq files
// library type SE/PE will be determinded automatically
// mixing of PE/SE samples is not possible in a batch file,
// but it is possible to provide PE DNA and SE RNA or vice versa
batchCSV = file(params.batchFile).splitCsv(header:true)
sexMap = [:]
for ( row in batchCSV ) {
if (row.sex && row.sex != "None") {
if (row.sex in ["XX", "XY", "Female", "female", "Male", "male"]) {
sexMap[row.tumorSampleName] = (row.sex == "Female" || row.sex == "XX" || row.sex == "female") ? "XX" : "XY"
} else {
exit 1, "Sex should be one of: XX, XY, Female, female, Male, male, got: " + row.sex
}
} else {
println("WARNING: sex not specified assuming: XY")
sexMap[row.tumorSampleName] = "XY"
}
if (! row.bamTumor || row.bamTumor == "" || row.bamTumor == "None") {
exit 1, "No tumor sample defined for " + row.tumorSampleName
}
if (! row.bamNormal || row.bamNormal == "" || row.bamNormal == "None") {
exit 1, "No normal sample defined for " + row.bamTumor
}
if (! row.bamRNAseq || row.bamRNAseq == "" || row.bamRNAseq == "None") {
have_RNAseq = false
} else {
have_RNAseq = true
rna_count++
}
if (row.HLAfile != "None" || row.HLAfile != "") {
use_custom_hlas = true
}
dna_count++
}
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file(row.bamTumor),
file(row.bamNormal)) }
.set { dna_bam_files }
if (have_RNAseq) {
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file(row.bamRNAseq)) }
.set { rna_bam_files }
}
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
file((row.HLAfile == "None") ? "NO_FILE_HLA" : row.HLAfile)) }
.set { custom_hlas_ch }
}
// set cutom HLA channel and sex channel if no batchFile was passed
if (! params.batchFile) {
// user supplied HLA types (default: NO_FILE, will be checked in get_vhla)
if (params.customHLA != "NO_FILE_HLA") {
use_custom_hlas = true
}
Channel
.of(tuple(
tumorSampleName,
file(params.customHLA)
))
.set { custom_hlas_ch }
sexMap = [:]
if (params.sex in ["XX", "XY", "Female", "Male", "female", "male"]) {
sexMap[tumorSampleName] = params.sex
} else {
exit 1, "Sex should be one of: XX, XY, Female, Male, female, male, got: " + params.sex
}
}
// we do not support mixed batches of samples with and without RNAseq data
// separate batches are needed for this
if (params.batchFile && (dna_count != rna_count) && (rna_count != 0)) {
exit 1, "Please do not mix samples with/without RNAseq data in batchfile"
}
// make empty RNAseq channels if no RNAseq data available
if (! have_RNAseq && params.batchFile) {
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
row.normalSampleName,
file("NO_FILE_RNA_FWD"),
file("NO_FILE_RNA_REV")) }
.into { raw_reads_tumor_neofuse_ch; fastqc_readsRNAseq_ch }
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
file("NO_FILE_OPTI_RNA")) }
.set { optitype_RNA_output }
Channel
.fromPath(params.batchFile)
.splitCsv(header:true)
.map { row -> tuple(row.tumorSampleName,
file("NO_FILE_HLAHD_RNA")) }
.set { hlahd_output_RNA }
} else if (! have_RNAseq && ! params.batchFile ){
Channel
.of(tuple(tumorSampleName,
normalSampleName,
file("NO_FILE_RNA_FWD"),
file("NO_FILE_RNA_REV")))
.into { raw_reads_tumor_neofuse_ch; fastqc_readsRNAseq_ch }
Channel
.of(tuple(
tumorSampleName,
"NO_FILE_OPTI_RNA"
))
.set { optitype_RNA_output }
Channel
.of(tuple(
tumorSampleName,
"NO_FILE_HLAHD_RNA"
))
.into { hlahd_output_RNA }
}
// optional panel of normals file
pon_file = file(params.mutect2ponFile)
scatter_count = Channel.from(params.scatter_count)
padding = params.readLength + 100
MIXCR = ( params.MIXCR != "" ) ? file(params.MIXCR) : ""
MiXMHC2PRED = ( params.MiXMHC2PRED != "" ) ? file(params.MiXMHC2PRED) : ""
// check HLAHD & OptiType
have_HLAHD = false
run_OptiType = (params.disable_OptiType) ? false : true
if (params.HLAHD_DIR != "") {
HLAHD = file(params.HLAHD_DIR + "/bin/hlahd.sh")
if (checkToolAvailable(HLAHD, "exists", "warn")) {
HLAHD_DIR = file(params.HLAHD_DIR)
HLAHD_PATH = HLAHD_DIR + "/bin"
have_HLAHD = true
}
}
if (! have_HLAHD && run_OptiType) {
log.warn "WARNING: HLAHD not available - can not predict Class II neoepitopes"
} else if (! have_HLAHD && ! run_OptiType && use_custom_hlas) {
log.warn "WARNING: HLAHD not available and OptiType disabled - using only user supplied HLA types"
} else if (! have_HLAHD && ! run_OptiType && ! use_custom_hlas) {
exit 1, "ERROR: HLAHD not available and OptiType disabled - can not predict HLA types"
}
// check if all tools are installed when not running conda or singularity
have_vep = false
if (! workflow.profile.contains('conda') && ! workflow.profile.contains('singularity')) {
def execTools = ["fastqc", "fastp", "bwa", "samtools", "sambamba", "gatk", "vep", "bam-readcount",
"perl", "bgzip", "tabix", "bcftools", "yara_mapper", "python", "cnvkit.py",
"OptiTypePipeline.py", "alleleCounter", "freec", "Rscript", "java", "multiqc",
"sequenza-utils"]
for (tool in execTools) {
checkToolAvailable(tool, "inPath", "error")
}
VARSCAN = "java " + params.JAVA_Xmx + " -jar " + file(params.VARSCAN)
have_vep = true
} else {
VARSCAN = "varscan " + params.JAVA_Xmx
}
// check if we have mutect1 installed
have_Mutect1 = false
if (params.MUTECT1 != "" && file(params.MUTECT1) && params.JAVA7 != "" && file(params.JAVA7)) {
if(checkToolAvailable(params.JAVA7, "inPath", "warn") && checkToolAvailable(params.MUTECT1, "exists", "warn")) {
JAVA7 = file(params.JAVA7)
MUTECT1 = file(params.MUTECT1)
have_Mutect1 = true
}
}
// check if we have GATK3 installed
have_GATK3 = false
if (file(params.GATK3) && file(params.JAVA8) && ! workflow.profile.contains('conda') && ! workflow.profile.contains('singularity')) {
if(checkToolAvailable(params.JAVA8, "inPath", "warn") && checkToolAvailable(params.GATK3, "exists", "warn")) {
JAVA8 = file(params.JAVA8)
GATK3 = file(params.GATK3)
have_GATK3 = true
}
} else if (workflow.profile.contains('singularity')) {
JAVA8 = "java"
GATK3 = "/usr/local/opt/gatk-3.8/GenomeAnalysisTK.jar"
have_GATK3 = true
} else if (workflow.profile.contains('conda')) {
JAVA8 = "java"
GATK3 = "\$CONDA_PREFIX/opt/gatk-3.8/GenomeAnalysisTK.jar"
have_GATK3 = true
}
/*
________________________________________________________________________________
P R O C E S S E S
________________________________________________________________________________
*/
/*
*********************************************
** P R E P R O C E S S I N G **
*********************************************
*/
// Handle BAM input files. We need to convert BAMs to Fastq
if(bamInput) {
process check_DNA_PE {
label 'nextNEOpiENV'
tag "$TumorReplicateId"
input:
set(
TumorReplicateId,
NormalReplicateId,
file(bamTumor),
file(bamNormal)
) from dna_bam_files
output:
set(
TumorReplicateId,
NormalReplicateId,
file(bamTumor),
file(bamNormal),
stdout
) into check_DNA_seqLib_ch
script:
"""
check_pe.py $bamTumor $bamNormal
"""
}
(bam_DNA_ch, check_DNA_seqLib_ch) = check_DNA_seqLib_ch.into(2)
check_seqLibTypes_ok(check_DNA_seqLib_ch, "DNA")
if (have_RNAseq) {
process check_RNA_PE {
label 'nextNEOpiENV'
tag "$TumorReplicateId"
input:
set(
TumorReplicateId,
NormalReplicateId,
file(bamRNAseq),
) from rna_bam_files
output:
set(
TumorReplicateId,
NormalReplicateId,
file(bamRNAseq),
stdout
) into check_RNA_seqLib_ch
script:
"""
check_pe.py $bamRNAseq
"""
}
(bam_RNA_ch, check_RNA_seqLib_ch) = check_RNA_seqLib_ch.into(2)
check_seqLibTypes_ok(check_RNA_seqLib_ch, "RNA")
}
process bam2fastq_DNA {
label 'nextNEOpiENV'
tag "$TumorReplicateId"
publishDir "${params.outputDir}/analyses/$TumorReplicateId/01_preprocessing",
mode: params.publishDirMode
input:
set(
TumorReplicateId,
NormalReplicateId,
file(bamTumor),
file(bamNormal),
libType
) from bam_DNA_ch
output:
set(
TumorReplicateId,
NormalReplicateId,
file("${TumorReplicateId}_FWD.fastq.gz"),
file("${tumorDNA_rev_fq}")
) into (
raw_reads_tumor_ch,
fastqc_reads_tumor_ch
)
set(
TumorReplicateId,
NormalReplicateId,
file("${NormalReplicateId}_FWD.fastq.gz"),
file("${normalDNA_rev_fq}")
) into (
raw_reads_normal_ch,
fastqc_reads_normal_ch
)
script:
if (libType == "MIXED") {
exit 1, "Please do not mix pe and se for tumor/normal pairs: " + TumorReplicateId + " - Not supported"
} else if (libType == "PE") {
tumorDNA_rev_fq = "${TumorReplicateId}_REV.fastq.gz"
normalDNA_rev_fq = "${NormalReplicateId}_REV.fastq.gz"
} else {
tumorDNA_rev_fq = "None"
normalDNA_rev_fq = "None"
}
if (libType == "PE")
"""
samtools sort -@ ${task.cpus} -m ${params.STperThreadMem} -l 0 -n ${bamTumor} | \\
samtools fastq \\
-@ ${task.cpus} \\
-c 5 \\
-1 ${TumorReplicateId}_FWD.fastq.gz \\
-2 ${TumorReplicateId}_REV.fastq.gz \\
-0 /dev/null -s /dev/null \\
-n \\
/dev/stdin
samtools sort -@ ${task.cpus} -m ${params.STperThreadMem} -l 0 -n ${bamNormal} | \\
samtools fastq \\
-@ ${task.cpus} \\
-c 5 \\
-1 ${NormalReplicateId}_FWD.fastq.gz \\
-2 ${NormalReplicateId}_REV.fastq.gz \\
-0 /dev/null -s /dev/null \\
-n \\
/dev/stdin
"""
else if (libType == "SE")
"""
samtools fastq \\
-@ ${task.cpus} \\
-n \\
${bamTumor} | \\
bgzip -@ ${task.cpus} -c /dev/stdin > ${TumorReplicateId}_FWD.fastq.gz
samtools fastq \\
-@ ${task.cpus} \\
-n \\
${bamNormal} | \\
bgzip -@ ${task.cpus} -c /dev/stdin > ${TumorReplicateId}_FWD.fastq.gz
touch None
"""
}
if (have_RNAseq) {
process bam2fastq_RNA {
label 'nextNEOpiENV'
tag "$TumorReplicateId"
publishDir "${params.outputDir}/analyses/$TumorReplicateId/01_preprocessing",
mode: params.publishDirMode
input:
set(
TumorReplicateId,
NormalReplicateId,
file(bamRNAseq),
libType
) from bam_RNA_ch
output:
set(
TumorReplicateId,
NormalReplicateId,
file("${TumorReplicateId}_RNA_FWD.fastq.gz"),
file("${tumorRNA_rev_fq}")
) into (
raw_reads_tumor_neofuse_ch,
fastqc_readsRNAseq_ch
)
script:
if (libType == "PE") {
tumorRNA_rev_fq = "${TumorReplicateId}_RNA_REV.fastq.gz"
} else if (libType == "SE") {
tumorRNA_rev_fq = "None"
} else {
exit 1, "An error occured: " + TumorReplicateId + ": RNAseq library type not SE or PE."
}
if (libType == "PE")
"""
samtools sort -@ ${task.cpus} -m ${params.STperThreadMem} -l 0 -n ${bamRNAseq} | \\
samtools fastq \\
-@ ${task.cpus} \\
-c 5 \\
-1 ${TumorReplicateId}_RNA_FWD.fastq.gz \\
-2 ${TumorReplicateId}_RNA_REV.fastq.gz \\
-0 /dev/null -s /dev/null \\
-n \\
/dev/stdin
"""
else if (libType == "SE")
"""
samtools fastq \\
-@ ${task.cpus} \\
-n \\
${bamRNAseq} | \\
bgzip -@ ${task.cpus} -c /dev/stdin > ${TumorReplicateId}_RNA_FWD.fastq.gz
touch None
"""
}
}
}
// END BAM input handling
// Common region files preparation for faster processing
if (params.WES) {
process 'RegionsBedToIntervalList' {
label 'nextNEOpiENV'
tag 'RegionsBedToIntervalList'
publishDir "$params.outputDir/supplemental/00_prepare_Intervals/",
mode: params.publishDirMode
input:
set(
file(RefDict),
file(RegionsBed)
) from Channel.value(
[ reference.RefDict,
reference.RegionsBed ]
)
output:
file(
"${RegionsBed.baseName}.interval_list"
) into (
RegionsBedToIntervalList_out_ch0,
RegionsBedToIntervalList_out_ch1
)
script:
"""
gatk --java-options ${params.JAVA_Xmx} BedToIntervalList \\
-I ${RegionsBed} \\
-O ${RegionsBed.baseName}.interval_list \\
-SD $RefDict
"""
}
process 'BaitsBedToIntervalList' {
label 'nextNEOpiENV'
tag 'BaitsBedToIntervalList'
publishDir "$params.outputDir/supplemental/00_prepare_Intervals/",
mode: params.publishDirMode
input:
set(
file(RefDict),
file(BaitsBed)
) from Channel.value(
[ reference.RefDict,
reference.BaitsBed ]
)
output:
file(
"${BaitsBed.baseName}.interval_list"
) into BaitsBedToIntervalList_out_ch0
script:
"""
gatk --java-options ${params.JAVA_Xmx} BedToIntervalList \\
-I ${BaitsBed} \\
-O ${BaitsBed.baseName}.interval_list \\
-SD $RefDict
"""
}
} else {
RegionsBedToIntervalList_out_ch0 = Channel.of('NO_FILE')
RegionsBedToIntervalList_out_ch1 = Channel.empty()
BaitsBedToIntervalList_out_ch0 = Channel.empty()
}
process 'preprocessIntervalList' {
label 'nextNEOpiENV'
tag 'preprocessIntervalList'
publishDir "$params.outputDir/supplemental/00_prepare_Intervals/",
mode: params.publishDirMode
input:
set(
file(RefFasta),
file(RefIdx),
file(RefDict)
) from Channel.value(
[ reference.RefFasta,
reference.RefIdx,
reference.RefDict ]
)
file(interval_list) from RegionsBedToIntervalList_out_ch0
output:
file(
"${interval_list.baseName}_merged_padded.interval_list"
) into (
preprocessIntervalList_out_ch0,
preprocessIntervalList_out_ch1,
preprocessIntervalList_out_ch2,
preprocessIntervalList_out_ch3,
preprocessIntervalList_out_ch4,
preprocessIntervalList_out_ch5,
preprocessIntervalList_out_ch6,
preprocessIntervalList_out_ch7,
preprocessIntervalList_out_ch8
)