forked from nf-core/eager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
3483 lines (2834 loc) · 147 KB
/
main.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
/*
------------------------------------------------------------------------------------------------------------
nf-core/eager
------------------------------------------------------------------------------------------------------------
EAGER Analysis Pipeline. Started 2018-06-05
#### Homepage / Documentation
https://github.com/nf-core/eager
#### Authors
For a list of authors and contributors, see: https://github.com/nf-core/eager/tree/dev#authors-alphabetical
------------------------------------------------------------------------------------------------------------
*/
log.info Headers.nf_core(workflow, params.monochrome_logs)
////////////////////////////////////////////////////
/* -- PRINT HELP -- */
////////////////////////////////////////////////////+
def json_schema = "$projectDir/nextflow_schema.json"
if (params.help) {
def command = "nextflow run nf-core/eager --input '*_R{1,2}.fastq.gz' -profile docker"
log.info NfcoreSchema.params_help(workflow, params, json_schema, command)
exit 0
}
////////////////////////////////////////////////////
/* -- VALIDATE PARAMETERS -- */
////////////////////////////////////////////////////+
if (params.validate_params) {
NfcoreSchema.validateParameters(params, json_schema, log)
}
// Validate BAM input isn't set to paired_end
if ( params.bam && !params.single_end ) {
exit 1, "[nf-core/eager] error: bams can only be specified with --single_end. Please check input command."
}
// Validate that skip_collapse is only set to True for paired_end reads!
if (!has_extension(params.input, "tsv") && params.skip_collapse && params.single_end){
exit 1, "[nf-core/eager] error: --skip_collapse can only be set for paired_end samples."
}
// Validate not trying to both skip collapse and skip trim
if ( params.skip_collapse && params.skip_trim ) {
exit 1, "[nf-core/eager error]: you have specified to skip both merging and trimming of paired end samples. Use --skip_adapterremoval instead."
}
// Bedtools validation
if( params.run_bedtools_coverage && !params.anno_file ){
exit 1, "[nf-core/eager] error: you have turned on bedtools coverage, but not specified a BED or GFF file with --anno_file. Please validate your parameters."
}
// Bedtools validation
if( !params.skip_preseq && !( params.preseq_mode == 'c_curve' || params.preseq_mode == 'lc_extrap' ) ) {
exit 1, "[nf-core/eager] error: you are running preseq with a unsupported mode. See documentation for more information. You gave: ${params.preseq_mode}."
}
// BAM filtering validation
if (!params.run_bam_filtering && params.bam_mapping_quality_threshold != 0) {
exit 1, "[nf-core/eager] error: please turn on BAM filtering if you want to perform mapping quality filtering! Provide: --run_bam_filtering."
}
if (params.dedupper == 'dedup' && !params.mergedonly) {
log.warn "[nf-core/eager] Warning: you are using DeDup but without specifying --mergedonly for AdapterRemoval, dedup will likely fail! See documentation for more information."
}
// Genotyping validation
if (params.run_genotyping){
if (params.genotyping_tool == 'pileupcaller' && ( !params.pileupcaller_bedfile || !params.pileupcaller_snpfile ) ) {
exit 1, "[nf-core/eager] error: please check your pileupCaller bed file and snp file parameters. You must supply a bed file and a snp file."
}
if (params.genotyping_tool == 'angsd' && ! ( params.angsd_glformat == 'text' || params.angsd_glformat == 'binary' || params.angsd_glformat == 'binary_three' || params.angsd_glformat == 'beagle' ) ) {
exit 1, "[nf-core/eager] error: please check your ANGSD output format! Options: 'text', 'binary', 'binary_three', 'beagle'. Found parameter: --angsd_glformat '${params.angsd_glformat}'."
}
}
// Consensus sequence generation validation
if (params.run_vcf2genome) {
if (!params.run_genotyping) {
exit 1, "[nf-core/eager] error: consensus sequence generation requires genotyping via UnifiedGenotyper on be turned on with the parameter --run_genotyping and --genotyping_tool 'ug'. Please check your genotyping parameters."
}
if (params.genotyping_tool != 'ug') {
exit 1, "[nf-core/eager] error: consensus sequence generation requires genotyping via UnifiedGenotyper on be turned on with the parameter --run_genotyping and --genotyping_tool 'ug'. Found parameter: --genotyping_tool '${params.genotyping_tool}'."
}
}
// MultiVCFAnalyzer validation
if (params.run_multivcfanalyzer) {
if (!params.run_genotyping) {
exit 1, "[nf-core/eager] error: MultiVCFAnalyzer requires genotyping to be turned on with the parameter --run_genotyping. Please check your genotyping parameters."
}
if (params.genotyping_tool != "ug") {
exit 1, "[nf-core/eager] error: MultiVCFAnalyzer only accepts VCF files from GATK UnifiedGenotyper. Found parameter: --genotyping_tool '${params.genotyping_tool}'."
}
if (params.gatk_ploidy != 2) {
exit 1, "[nf-core/eager] error: MultiVCFAnalyzer only accepts VCF files generated with a GATK ploidy set to 2. Found parameter: --gatk_ploidy ${params.gatk_ploidy}."
}
if (params.additional_vcf_files) {
ch_extravcfs_for_multivcfanalyzer = Channel.fromPath(params.additional_vcf_files, checkIfExists: true)
}
}
if (params.run_metagenomic_screening) {
if ( params.bam_unmapped_type == "discard" ) {
exit 1, "[nf-core/eager] error: metagenomic classification can only run on unmapped reads. Please supply --bam_unmapped_type 'fastq'. Supplied: --bam_unmapped_type '${params.bam_unmapped_type}'."
}
if (params.bam_unmapped_type != 'fastq' ) {
exit 1, "[nf-core/eager] error: metagenomic classification can only run on unmapped reads in FASTQ format. Please supply --bam_unmapped_type 'fastq'. Found parameter: --bam_unmapped_type '${params.bam_unmapped_type}'."
}
if (!params.database) {
exit 1, "[nf-core/eager] error: metagenomic classification requires a path to a database directory. Please specify one with --database '/path/to/database/'."
}
if (params.metagenomic_tool == 'malt' && params.malt_min_support_mode == 'percent' && params.metagenomic_min_support_reads != 1) {
exit 1, "[nf-core/eager] error: incompatible MALT min support configuration. Percent can only be used with --malt_min_support_percent. You modified: --metagenomic_min_support_reads."
}
if (params.metagenomic_tool == 'malt' && params.malt_min_support_mode == 'reads' && params.malt_min_support_percent != 0.01) {
exit 1, "[nf-core/eager] error: incompatible MALT min support configuration. Reads can only be used with --malt_min_supportreads. You modified: --malt_min_support_percent."
}
if (!params.metagenomic_min_support_reads.toString().isInteger()){
exit 1, "[nf-core/eager] error: incompatible min_support_reads configuration. min_support_reads can only be used with integers. --metagenomic_min_support_reads Found parameter: ${params.metagenomic_min_support_reads}."
}
}
// MaltExtract validation
if (params.run_maltextract) {
if (params.run_metagenomic_screening && params.metagenomic_tool != 'malt') {
exit 1, "[nf-core/eager] error: MaltExtract can only accept MALT output. Please supply --metagenomic_tool 'malt'. Found parameter: --metagenomic_tool '${params.metagenomic_tool}'"
}
if (params.run_metagenomic_screening && params.metagenomic_tool != 'malt') {
exit 1, "[nf-core/eager] error: MaltExtract can only accept MALT output. Please supply --metagenomic_tool 'malt'. Found parameter: --metagenomic_tool '${params.metagenomic_tool}'"
}
if (!params.maltextract_taxon_list) {
exit 1, "[nf-core/eager] error: MaltExtract requires a taxon list specifying the target taxa of interest. Specify the file with --params.maltextract_taxon_list."
}
}
/////////////////////////////////////////////////////////
/* -- VALIDATE INPUT FILES -- */
/////////////////////////////////////////////////////////
// Set up channels for annotation file
if (!params.run_bedtools_coverage){
ch_anno_for_bedtools = Channel.empty()
} else {
ch_anno_for_bedtools = Channel.fromPath(params.anno_file, checkIfExists: true)
.ifEmpty { exit 1, "[nf-core/eager] error: bedtools annotation file not found. Supplied parameter: --anno_file ${params.anno_file}."}
}
if (params.fasta) {
file(params.fasta, checkIfExists: true)
lastPath = params.fasta.lastIndexOf(File.separator)
lastExt = params.fasta.lastIndexOf(".")
fasta_base = params.fasta.substring(lastPath+1)
index_base = params.fasta.substring(lastPath+1,lastExt)
if (params.fasta.endsWith('.gz')) {
fasta_base = params.fasta.substring(lastPath+1,lastExt)
index_base = fasta_base.substring(0,fasta_base.lastIndexOf("."))
}
} else {
exit 1, "[nf-core/eager] error: please specify --fasta with the path to your reference"
}
// Validate reference inputs
if("${params.fasta}".endsWith(".gz")){
process unzip_reference{
tag "${zipped_fasta}"
input:
path zipped_fasta from file(params.fasta) // path doesn't like it if a string of an object is not prefaced with a root dir (/), so use file() to resolve string before parsing to `path`
output:
path "$unzip" into ch_fasta into ch_fasta_for_bwaindex,ch_fasta_for_bt2index,ch_fasta_for_faidx,ch_fasta_for_seqdict,ch_fasta_for_circulargenerator,ch_fasta_for_circularmapper,ch_fasta_for_damageprofiler,ch_fasta_for_qualimap,ch_fasta_for_pmdtools,ch_fasta_for_genotyping_ug,ch_fasta_for_genotyping_hc,ch_fasta_for_genotyping_freebayes,ch_fasta_for_genotyping_pileupcaller,ch_fasta_for_vcf2genome,ch_fasta_for_multivcfanalyzer,ch_fasta_for_genotyping_angsd,ch_fasta_for_damagerescaling,ch_fasta_for_bcftools_stats
script:
unzip = zipped_fasta.toString() - '.gz'
"""
pigz -f -d -p ${task.cpus} $zipped_fasta
"""
}
} else {
fasta_for_indexing = Channel
.fromPath("${params.fasta}", checkIfExists: true)
.into{ ch_fasta_for_bwaindex; ch_fasta_for_bt2index; ch_fasta_for_faidx; ch_fasta_for_seqdict; ch_fasta_for_circulargenerator; ch_fasta_for_circularmapper; ch_fasta_for_damageprofiler; ch_fasta_for_qualimap; ch_fasta_for_pmdtools; ch_fasta_for_genotyping_ug; ch_fasta__for_genotyping_hc; ch_fasta_for_genotyping_hc; ch_fasta_for_genotyping_freebayes; ch_fasta_for_genotyping_pileupcaller; ch_fasta_for_vcf2genome; ch_fasta_for_multivcfanalyzer;ch_fasta_for_genotyping_angsd;ch_fasta_for_damagerescaling;ch_fasta_for_bcftools_stats }
}
// Check that fasta index file path ends in '.fai'
if (params.fasta_index && !params.fasta_index.endsWith(".fai")) {
exit 1, "The specified fasta index file (${params.fasta_index}) is not valid. Fasta index files should end in '.fai'."
}
// Check if genome exists in the config file. params.genomes is from igenomes.conf, params.genome specified by user
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
exit 1, "The provided genome '${params.genome}' is not available in the iGenomes file. Currently the available genomes are ${params.genomes.keySet().join(', ')}"
}
// Index files provided? Then check whether they are correct and complete
if( params.bwa_index && (params.mapper == 'bwaaln' | params.mapper == 'bwamem' | params.mapper == 'circularmapper')){
Channel
.fromPath(params.bwa_index, checkIfExists: true)
.ifEmpty { exit 1, "[nf-core/eager] error: bwa indices not found in: ${index_base}." }
.into {bwa_index; bwa_index_bwamem}
bt2_index = Channel.empty()
}
if( params.bt2_index && params.mapper == 'bowtie2' ){
lastPath = params.bt2_index.lastIndexOf(File.separator)
bt2_dir = params.bt2_index.substring(0,lastPath+1)
bt2_base = params.bt2_index.substring(lastPath+1)
Channel
.fromPath(params.bt2_index, checkIfExists: true)
.ifEmpty { exit 1, "[nf-core/eager] error: bowtie2 indices not found in: ${bt2_dir}." }
.into {bt2_index; bt2_index_bwamem}
bwa_index = Channel.empty()
bwa_index_bwamem = Channel.empty()
}
// Adapter removal adapter-list setup
if ( !params.clip_adapters_list ) {
Channel
.fromPath("$projectDir/assets/nf-core_eager_dummy2.txt", checkIfExists: true)
.ifEmpty { exit 1, "[nf-core/eager] error: adapters list file not found. Please check input. Supplied: --clip_adapters_list '${params.clip_adapters_list}'." }
.set {ch_adapterlist}
} else {
Channel
.fromPath("${params.clip_adapters_list}", checkIfExists: true)
.ifEmpty { exit 1, "[nf-core/eager] error: adapters list file not found. Please check input. Supplied: --clip_adapters_list '${params.clip_adapters_list}'." }
.set {ch_adapterlist}
}
// SexDetermination channel set up and bedfile validation
if (!params.sexdeterrmine_bedfile) {
ch_bed_for_sexdeterrmine = Channel.fromPath("$projectDir/assets/nf-core_eager_dummy.txt")
} else {
ch_bed_for_sexdeterrmine = Channel.fromPath(params.sexdeterrmine_bedfile, checkIfExists: true)
}
// pileupCaller channel generation and input checks for 'random sampling' genotyping
if (!params.pileupcaller_bedfile) {
ch_bed_for_pileupcaller = Channel.fromPath("$projectDir/assets/nf-core_eager_dummy.txt")
} else {
ch_bed_for_pileupcaller = Channel.fromPath(params.pileupcaller_bedfile, checkIfExists: true)
}
if (!params.pileupcaller_snpfile) {
ch_snp_for_pileupcaller = Channel.fromPath("$projectDir/assets/nf-core_eager_dummy2.txt")
} else {
ch_snp_for_pileupcaller = Channel.fromPath(params.pileupcaller_snpfile, checkIfExists: true)
}
// Create input channel for MALT database directory, checking directory exists
if ( !params.database ) {
ch_db_for_malt = Channel.empty()
} else {
ch_db_for_malt = Channel.fromPath(params.database, checkIfExists: true)
}
// Create input channel for MaltExtract taxon list, to allow downloading of taxon list, checking file exists.
if ( !params.maltextract_taxon_list ) {
ch_taxonlist_for_maltextract = Channel.empty()
} else {
ch_taxonlist_for_maltextract = Channel.fromPath(params.maltextract_taxon_list, checkIfExists: true)
}
// Create input channel for MaltExtract NCBI files, checking files exists.
if ( !params.maltextract_ncbifiles ) {
ch_ncbifiles_for_maltextract = Channel.empty()
} else {
ch_ncbifiles_for_maltextract = Channel.fromPath(params.maltextract_ncbifiles, checkIfExists: true)
}
////////////////////////////////////////////////////
/* -- Collect configuration parameters -- */
////////////////////////////////////////////////////
// Check if genome exists in the config file
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
exit 1, "The provided genome '${params.genome}' is not available in the iGenomes file. Currently the available genomes are ${params.genomes.keySet().join(', ')}"
}
// Check AWS batch settings
if (workflow.profile.contains('awsbatch')) {
// AWSBatch sanity checking
if (!params.awsqueue || !params.awsregion) exit 1, 'Specify correct --awsqueue and --awsregion parameters on AWSBatch!'
// Check outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
if (!params.outdir.startsWith('s3:')) exit 1, 'Outdir not on S3 - specify S3 Bucket to run on AWSBatch!'
// Prevent trace files to be stored on S3 since S3 does not support rolling files.
if (params.tracedir.startsWith('s3:')) exit 1, 'Specify a local tracedir or run without trace! S3 cannot be used for tracefiles.'
}
ch_multiqc_config = file("$projectDir/assets/multiqc_config.yaml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config, checkIfExists: true) : Channel.empty()
ch_eager_logo = file("$projectDir/docs/images/nf-core_eager_logo_outline_drop.png")
ch_output_docs = file("$projectDir/docs/output.md", checkIfExists: true)
ch_output_docs_images = file("$projectDir/docs/images/", checkIfExists: true)
where_are_my_files = file("$projectDir/assets/where_are_my_files.txt")
///////////////////////////////////////////////////
/* -- INPUT FILE LOADING AND VALIDATING -- */
///////////////////////////////////////////////////
// check if we have valid --reads or --input
if (!params.input) {
exit 1, "[nf-core/eager] error: --input was not supplied! Please check '--help' or documentation under 'running the pipeline' for details"
}
// Read in files properly from TSV file
tsv_path = null
if (params.input && (has_extension(params.input, "tsv"))) tsv_path = params.input
ch_input_sample = Channel.empty()
if (tsv_path) {
tsv_file = file(tsv_path)
if (tsv_file instanceof List) exit 1, "[nf-core/eager] error: can only accept one TSV file per run."
if (!tsv_file.exists()) exit 1, "[nf-core/eager] error: input TSV file could not be found. Does the file exist and is it in the right place? You gave the path: ${params.input}"
ch_input_sample = extract_data(tsv_path)
} else if (params.input && !has_extension(params.input, "tsv")) {
log.info ""
log.info "No TSV file provided - creating TSV from supplied directory."
log.info "Reading path(s): ${params.input}\n"
inputSample = retrieve_input_paths(params.input, params.colour_chemistry, params.single_end, params.single_stranded, params.udg_type, params.bam)
ch_input_sample = inputSample
} else exit 1, "[nf-core/eager] error: --input file(s) not correctly not supplied or improperly defined, see '--help' flag and documentation under 'running the pipeline' for details."
ch_input_sample
.into { ch_input_sample_downstream; ch_input_sample_check }
///////////////////////////////////////////////////
/* -- INPUT CHANNEL CREATION -- */
///////////////////////////////////////////////////
// Check we don't have any duplicate file names
ch_input_sample_check
.map {
it ->
def r1 = file(it[8]).getName()
def r2 = file(it[9]).getName()
def bam = file(it[10]).getName()
[r1, r2, bam]
}
.collect()
.map{
file ->
filenames = file
filenames -= 'NA'
if( filenames.size() != filenames.unique().size() )
exit 1, "[nf-core/eager] error: You have duplicate input FASTQ and/or BAM file names! All files must have unique names, different directories are not sufficent. Please check your input."
}
// Drop samples with R1/R2 to fastQ channel, BAM samples to other channel
ch_branched_input = ch_input_sample_downstream.branch{
fastq: it[8] != 'NA' //These are all fastqs
bam: it[10] != 'NA' //These are all BAMs
}
//Removing BAM/BAI in case of a FASTQ input
ch_fastq_channel = ch_branched_input.fastq.map {
samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, r1, r2, bam ->
[samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, r1, r2]
}
//Removing R1/R2 in case of BAM input
ch_bam_channel = ch_branched_input.bam.map {
samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, r1, r2, bam ->
[samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, bam]
}
// Prepare starting channels, here we go
ch_input_for_convertbam = Channel.empty()
ch_bam_channel
.into { ch_input_for_convertbam; ch_input_for_indexbam; }
// Also need to send raw files for lane merging, if we want to host removed fastq
ch_fastq_channel
.into { ch_input_for_skipconvertbam; ch_input_for_lanemerge_hostremovalfastq }
////////////////////////////////////////////////////
/* -- PRINT PARAMETER SUMMARY -- */
////////////////////////////////////////////////////
log.info NfcoreSchema.params_summary_log(workflow, params, json_schema)
// Header log info
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Run Name'] = workflow.runName
summary['Input'] = params.input
summary['Fasta Ref'] = params.fasta
summary['Max Resources'] = "$params.max_memory memory, $params.max_cpus cpus, $params.max_time time per job"
if (workflow.containerEngine) summary['Container'] = "$workflow.containerEngine - $workflow.container"
summary['Output dir'] = params.outdir
summary['Launch dir'] = workflow.launchDir
summary['Working dir'] = workflow.workDir
summary['Script dir'] = workflow.projectDir
summary['User'] = workflow.userName
if (workflow.profile.contains('awsbatch')) {
summary['AWS Region'] = params.awsregion
summary['AWS Queue'] = params.awsqueue
summary['AWS CLI'] = params.awscli
}
summary['Config Profile'] = workflow.profile
if (params.config_profile_description) summary['Config Profile Description'] = params.config_profile_description
if (params.config_profile_contact) summary['Config Profile Contact'] = params.config_profile_contact
if (params.config_profile_url) summary['Config Profile URL'] = params.config_profile_url
summary['Config Files'] = workflow.configFiles.join(', ')
if (params.email || params.email_on_fail) {
summary['E-mail Address'] = params.email
summary['E-mail on failure'] = params.email_on_fail
summary['MultiQC maxsize'] = params.max_multiqc_email_size
}
Channel.from(summary.collect{ [it.key, it.value] })
.map { k,v -> "<dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }
.reduce { a, b -> return [a, b].join("\n ") }
.map { x -> """
id: 'nf-core-eager-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'nf-core/eager Workflow Summary'
section_href: 'https://github.com/nf-core/eager'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
$x
</dl>
""".stripIndent() }
.set { ch_workflow_summary }
// Check the hostnames against configured profiles
checkHostname()
log.info "Schaffa, Schaffa, Genome Baua!"
///////////////////////////////////////////////////
/* -- REFERENCE FASTA INDEXING -- */
///////////////////////////////////////////////////
// BWA Index
if( !params.bwa_index && params.fasta && (params.mapper == 'bwaaln' || params.mapper == 'bwamem' || params.mapper == 'circularmapper')){
process makeBWAIndex {
label 'sc_medium'
tag "${fasta}"
publishDir path: "${params.outdir}/reference_genome/bwa_index", mode: params.publish_dir_mode, saveAs: { filename ->
if (params.save_reference) filename
else if(!params.save_reference && filename == "where_are_my_files.txt") filename
else null
}
input:
path fasta from ch_fasta_for_bwaindex
path where_are_my_files
output:
path "BWAIndex" into (bwa_index, bwa_index_bwamem)
path "where_are_my_files.txt"
script:
"""
bwa index $fasta
mkdir BWAIndex && mv ${fasta}* BWAIndex
"""
}
bt2_index = Channel.empty()
}
// bowtie2 Index
if( !params.bt2_index && params.fasta && params.mapper == "bowtie2"){
process makeBT2Index {
label 'sc_medium'
tag "${fasta}"
publishDir path: "${params.outdir}/reference_genome/bt2_index", mode: params.publish_dir_mode, saveAs: { filename ->
if (params.save_reference) filename
else if(!params.save_reference && filename == "where_are_my_files.txt") filename
else null
}
input:
path fasta from ch_fasta_for_bt2index
path where_are_my_files
output:
path "BT2Index" into (bt2_index)
path "where_are_my_files.txt"
script:
"""
bowtie2-build $fasta $fasta
mkdir BT2Index && mv ${fasta}* BT2Index
"""
}
bwa_index = Channel.empty()
bwa_index_bwamem = Channel.empty()
}
// FASTA Index (FAI)
if (params.fasta_index) {
Channel
.fromPath( params.fasta_index )
.set { ch_fai_for_skipfastaindexing }
} else {
Channel
.empty()
.set { ch_fai_for_skipfastaindexing }
}
process makeFastaIndex {
label 'sc_small'
tag "${fasta}"
publishDir path: "${params.outdir}/reference_genome/fasta_index", mode: params.publish_dir_mode, saveAs: { filename ->
if (params.save_reference) filename
else if(!params.save_reference && filename == "where_are_my_files.txt") filename
else null
}
when: !params.fasta_index && params.fasta && ( params.mapper == 'bwaaln' || params.mapper == 'bwamem' || params.mapper == 'circularmapper')
input:
path fasta from ch_fasta_for_faidx
path where_are_my_files
output:
path "*.fai" into ch_fasta_faidx_index
path "where_are_my_files.txt"
script:
"""
samtools faidx $fasta
"""
}
ch_fai_for_skipfastaindexing.mix(ch_fasta_faidx_index)
.into { ch_fai_for_ug; ch_fai_for_hc; ch_fai_for_freebayes; ch_fai_for_pileupcaller; ch_fai_for_angsd }
// Stage dict index file if supplied, else load it into the channel
if (params.seq_dict) {
Channel
.fromPath( params.seq_dict )
.set { ch_dict_for_skipdict }
} else {
Channel
.empty()
.set { ch_dict_for_skipdict }
}
process makeSeqDict {
label 'sc_medium'
tag "${fasta}"
publishDir path: "${params.outdir}/reference_genome/seq_dict", mode: params.publish_dir_mode, saveAs: { filename ->
if (params.save_reference) filename
else if(!params.save_reference && filename == "where_are_my_files.txt") filename
else null
}
when: !params.seq_dict && params.fasta
input:
path fasta from ch_fasta_for_seqdict
path where_are_my_files
output:
path "*.dict" into ch_seq_dict
path "where_are_my_files.txt"
script:
"""
picard -Xmx${task.memory.toMega()}M CreateSequenceDictionary R=$fasta O="${fasta.baseName}.dict"
"""
}
ch_dict_for_skipdict.mix(ch_seq_dict)
.into { ch_dict_for_ug; ch_dict_for_hc; ch_dict_for_freebayes; ch_dict_for_pileupcaller; ch_dict_for_angsd }
//////////////////////////////////////////////////
/* -- BAM INPUT PREPROCESSING -- */
//////////////////////////////////////////////////
// Convert to FASTQ if re-mapping is requested
process convertBam {
label 'mc_small'
tag "$libraryid"
when:
params.run_convertinputbam
input:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, path(bam) from ch_input_for_convertbam
output:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, path("*fastq.gz"), val('NA') into ch_output_from_convertbam
script:
base = "${bam.baseName}"
"""
samtools fastq -tn ${bam} | pigz -p ${task.cpus} > ${base}.converted.fastq.gz
"""
}
// If not converted to FASTQ generate pipeline compatible BAM index file (i.e. with correct samtools version)
process indexinputbam {
label 'sc_small'
tag "$libraryid"
when:
bam != 'NA' && !params.run_convertinputbam
input:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, path(bam) from ch_input_for_indexbam
output:
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path(bam), file("*.{bai,csi}") into ch_indexbam_for_filtering
script:
def size = params.large_ref ? '-c' : ''
"""
samtools index ${bam} ${size}
"""
}
// convertbam bypass
ch_input_for_skipconvertbam.mix(ch_output_from_convertbam)
.into { ch_convertbam_for_fastp; ch_convertbam_for_fastqc }
//////////////////////////////////////////////////
/* -- SEQUENCING QC AND FASTQ PREPROCESSING -- */
//////////////////////////////////////////////////
// Raw sequencing QC - allow user evaluate if sequencing any good?
process fastqc {
label 'mc_small'
tag "${libraryid}_L${lane}"
publishDir "${params.outdir}/fastqc/input_fastq", mode: params.publish_dir_mode,
saveAs: { filename ->
filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename"
}
input:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, file(r1), file(r2) from ch_convertbam_for_fastqc
output:
path "*_fastqc.{zip,html}" into ch_prefastqc_for_multiqc
when:
!params.skip_fastqc
script:
if ( seqtype == 'PE' ) {
"""
fastqc -t ${task.cpus} -q $r1 $r2
rename 's/_fastqc\\.zip\$/_raw_fastqc.zip/' *_fastqc.zip
rename 's/_fastqc\\.html\$/_raw_fastqc.html/' *_fastqc.html
"""
} else {
"""
fastqc -q $r1
rename 's/_fastqc\\.zip\$/_raw_fastqc.zip/' *_fastqc.zip
rename 's/_fastqc\\.html\$/_raw_fastqc.html/' *_fastqc.html
"""
}
}
// Poly-G clipping for 2-colour chemistry sequencers, to reduce erroenous mapping of sequencing artefacts
if (params.complexity_filter_poly_g) {
ch_input_for_fastp = ch_convertbam_for_fastp.branch{
twocol: it[3] == '2' // Nextseq/Novaseq data with possible sequencing artefact
fourcol: it[3] == '4' // HiSeq/MiSeq data where polyGs would be true
}
} else {
ch_input_for_fastp = ch_convertbam_for_fastp.branch{
twocol: it[3] == "dummy" // seq/Novaseq data with possible sequencing artefact
fourcol: it[3] == '4' || it[3] == '2' // HiSeq/MiSeq data where polyGs would be true
}
}
process fastp {
label 'mc_small'
tag "${libraryid}_L${lane}"
publishDir "${params.outdir}/FastP", mode: params.publish_dir_mode
when:
params.complexity_filter_poly_g
input:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, file(r1), file(r2) from ch_input_for_fastp.twocol
output:
tuple samplename, libraryid, lane, colour, seqtype, organism, strandedness, udg, path("*.pG.fq.gz") into ch_output_from_fastp
path("*.json") into ch_fastp_for_multiqc
script:
if( seqtype == 'SE' ){
"""
fastp --in1 ${r1} --out1 "${r1.baseName}.pG.fq.gz" -A -g --poly_g_min_len "${params.complexity_filter_poly_g_min}" -Q -L -w ${task.cpus} --json "${r1.baseName}"_L${lane}_fastp.json
"""
} else {
"""
fastp --in1 ${r1} --in2 ${r2} --out1 "${r1.baseName}.pG.fq.gz" --out2 "${r2.baseName}.pG.fq.gz" -A -g --poly_g_min_len "${params.complexity_filter_poly_g_min}" -Q -L -w ${task.cpus} --json "${libraryid}"_L${lane}_polyg_fastp.json
"""
}
}
// Colour column only useful for fastp, so dropping now to reduce complexity downstream
ch_input_for_fastp.fourcol
.map {
def samplename = it[0]
def libraryid = it[1]
def lane = it[2]
def seqtype = it[4]
def organism = it[5]
def strandedness = it[6]
def udg = it[7]
def r1 = it[8]
def r2 = seqtype == "PE" ? it[9] : file("$projectDir/assets/nf-core_eager_dummy.txt")
[ samplename, libraryid, lane, seqtype, organism, strandedness, udg, r1, r2 ]
}
.set { ch_skipfastp_for_merge }
ch_output_from_fastp
.map{
def samplename = it[0]
def libraryid = it[1]
def lane = it[2]
def seqtype = it[4]
def organism = it[5]
def strandedness = it[6]
def udg = it[7]
def r1 = it[8] instanceof ArrayList ? it[8].sort()[0] : it[8]
def r2 = seqtype == "PE" ? it[8].sort()[1] : file("$projectDir/assets/nf-core_eager_dummy.txt")
[ samplename, libraryid, lane, seqtype, organism, strandedness, udg, r1, r2 ]
}
.set{ ch_fastp_for_merge }
ch_skipfastp_for_merge.mix(ch_fastp_for_merge)
.into { ch_fastp_for_adapterremoval; ch_fastp_for_skipadapterremoval }
// Sequencing adapter clipping and optional paired-end merging in preparation for mapping
process adapter_removal {
label 'mc_small'
tag "${libraryid}_L${lane}"
publishDir "${params.outdir}/adapterremoval", mode: params.publish_dir_mode
input:
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, file(r1), file(r2) from ch_fastp_for_adapterremoval
path adapterlist from ch_adapterlist.collect().dump(tag: "Adapter list")
output:
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path("output/*{combined.fq,.se.truncated,pair1.truncated}.gz") into ch_output_from_adapterremoval_r1
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path("output/*pair2.truncated.gz") optional true into ch_output_from_adapterremoval_r2
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path("output/*.settings") into ch_adapterremoval_logs
when:
!params.skip_adapterremoval
script:
def base = "${r1.baseName}_L${lane}"
def adapters_to_remove = !params.clip_adapters_list ? "--adapter1 ${params.clip_forward_adaptor} --adapter2 ${params.clip_reverse_adaptor}" : "--adapter-list ${adapterlist}"
//This checks whether we skip trimming and defines a variable respectively
def preserve5p = params.preserve5p ? '--preserve5p' : '' // applies to any AR command - doesn't affect output file combination
if ( seqtype == 'PE' && !params.skip_collapse && !params.skip_trim && !params.mergedonly && !params.preserve5p ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
cat *.collapsed.gz *.collapsed.truncated.gz *.singleton.truncated.gz *.pair1.truncated.gz *.pair2.truncated.gz > output/${base}.pe.combined.tmp.fq.gz
mv *.settings output/
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
"""
//PE mode, collapse and trim, outputting all reads, preserving 5p
} else if (seqtype == 'PE' && !params.skip_collapse && !params.skip_trim && !params.mergedonly && params.preserve5p) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
cat *.collapsed.gz *.singleton.truncated.gz *.pair1.truncated.gz *.pair2.truncated.gz > output/${base}.pe.combined.tmp.fq.gz
mv *.settings output/
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
"""
// PE mode, collapse and trim but only output collapsed reads
} else if ( seqtype == 'PE' && !params.skip_collapse && !params.skip_trim && params.mergedonly && !params.preserve5p ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
cat *.collapsed.gz *.collapsed.truncated.gz > output/${base}.pe.combined.tmp.fq.gz
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
mv *.settings output/
"""
// PE mode, collapse and trim but only output collapsed reads, preserving 5p
} else if ( seqtype == 'PE' && !params.skip_collapse && !params.skip_trim && params.mergedonly && params.preserve5p ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
cat *.collapsed.gz > output/${base}.pe.combined.tmp.fq.gz
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
mv *.settings output/
"""
// PE mode, collapsing but skip trim, (output all reads). Note: seems to still generate `truncated` files for some reason, so merging for safety.
// Will still do default AR length filtering I guess
} else if ( seqtype == 'PE' && !params.skip_collapse && params.skip_trim && !params.mergedonly ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --adapter1 "" --adapter2 ""
cat *.collapsed.gz *.pair1.truncated.gz *.pair2.truncated.gz > output/${base}.pe.combined.tmp.fq.gz
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
mv *.settings output/
"""
// PE mode, collapsing but skip trim, and only output collapsed reads. Note: seems to still generate `truncated` files for some reason, so merging for safety.
// Will still do default AR length filtering I guess
} else if ( seqtype == 'PE' && !params.skip_collapse && params.skip_trim && params.mergedonly ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} --collapse ${preserve5p} --adapter1 "" --adapter2 ""
cat *.collapsed.gz > output/${base}.pe.combined.tmp.fq.gz
## Add R_ and L_ for unmerged reads for DeDup compatibility
AdapterRemovalFixPrefix -Xmx${task.memory.toGiga()}g output/${base}.pe.combined.tmp.fq.gz > output/${base}.pe.combined.fq
pigz -p ${task.cpus - 1} output/${base}.pe.combined.fq
mv *.settings output/
"""
// PE mode, skip collapsing but trim (output all reads, as merging not possible) - activates paired-end mapping!
} else if ( seqtype == 'PE' && params.skip_collapse && !params.skip_trim ) {
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --file2 ${r2} --basename ${base}.pe --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
mv ${base}.pe.pair*.truncated.gz *.settings output/
"""
} else if ( seqtype != 'PE' && !params.skip_trim ) {
//SE, collapse not possible, trim reads only
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --basename ${base}.se --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} ${preserve5p} --trimns --trimqualities ${adapters_to_remove} --minlength ${params.clip_readlength} --minquality ${params.clip_min_read_quality} --minadapteroverlap ${params.min_adap_overlap}
mv *.settings *.se.truncated.gz output/
"""
} else if ( seqtype != 'PE' && params.skip_trim ) {
//SE, collapse not possible, trim reads only
"""
mkdir -p output
AdapterRemoval --file1 ${r1} --basename ${base}.se --gzip --threads ${task.cpus} --qualitymax ${params.qualitymax} ${preserve5p} --adapter1 "" --adapter2 ""
mv *.settings *.se.truncated.gz output/
"""
}
}
// When not collapsing paired-end data, re-merge the R1 and R2 files into single map. Otherwise if SE or collapsed PE, R2 now becomes NA
// Sort to make sure we get consistent R1 and R2 ordered when using `-resume`, even if not needed for FastQC
if ( params.skip_collapse ){
ch_output_from_adapterremoval_r1
.mix(ch_output_from_adapterremoval_r2)
.groupTuple(by: [0,1,2,3,4,5,6])
.map{
it ->
def samplename = it[0]
def libraryid = it[1]
def lane = it[2]
def seqtype = it[3]
def organism = it[4]
def strandedness = it[5]
def udg = it[6]
def r1 = file(it[7].sort()[0])
def r2 = seqtype == "PE" ? file(it[7].sort()[1]) : file("$projectDir/assets/nf-core_eager_dummy.txt")
[ samplename, libraryid, lane, seqtype, organism, strandedness, udg, r1, r2 ]
}
.into { ch_output_from_adapterremoval; ch_adapterremoval_for_postfastqc }
} else {
ch_output_from_adapterremoval_r1
.map{
it ->
def samplename = it[0]
def libraryid = it[1]
def lane = it[2]
def seqtype = it[3]
def organism = it[4]
def strandedness = it[5]
def udg = it[6]
def r1 = file(it[7])
def r2 = file("$projectDir/assets/nf-core_eager_dummy.txt")
[ samplename, libraryid, lane, seqtype, organism, strandedness, udg, r1, r2 ]
}
.into { ch_output_from_adapterremoval; ch_adapterremoval_for_postfastqc }
}
// AdapterRemoval bypass when not running it
if (!params.skip_adapterremoval) {
ch_output_from_adapterremoval.mix(ch_fastp_for_skipadapterremoval)
.dump(tag: "post_ar_adapterremoval_decision_skipar")
.filter { it =~/.*combined.fq.gz|.*truncated.gz/ }
.dump(tag: "ar_bypass")
.into { ch_adapterremoval_for_post_ar_trimming; ch_adapterremoval_for_skip_post_ar_trimming; }
} else {
ch_fastp_for_skipadapterremoval
.dump(tag: "post_ar_adapterremoval_decision_withar")
.into { ch_adapterremoval_for_post_ar_trimming; ch_adapterremoval_for_skip_post_ar_trimming; }
}
// Post AR fastq trimming
process post_ar_fastq_trimming {
label 'mc_small'
tag "${libraryid}"
publishDir "${params.outdir}/post_ar_fastq_trimmed", mode: params.publish_dir_mode
when: params.run_post_ar_trimming
input:
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path(r1), path(r2) from ch_adapterremoval_for_post_ar_trimming
output:
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path("*_R1_postartrimmed.fq.gz") into ch_post_ar_trimming_for_lanemerge_r1
tuple samplename, libraryid, lane, seqtype, organism, strandedness, udg, path("*_R2_postartrimmed.fq.gz") optional true into ch_post_ar_trimming_for_lanemerge_r2
script:
if ( seqtype == 'SE' | (seqtype == 'PE' && !params.skip_collapse) ) {
"""
fastp --in1 ${r1} --trim_front1 ${params.post_ar_trim_front} --trim_tail1 ${params.post_ar_trim_tail} -A -G -Q -L -w ${task.cpus} --out1 "${libraryid}"_L"${lane}"_R1_postartrimmed.fq.gz
"""
} else if ( seqtype == 'PE' && params.skip_collapse ) {
"""
fastp --in1 ${r1} --in2 ${r2} --trim_front1 ${params.post_ar_trim_front} --trim_tail1 ${params.post_ar_trim_tail} --trim_front2 ${params.post_ar_trim_front2} --trim_tail2 ${params.post_ar_trim_tail2} -A -G -Q -L -w ${task.cpus} --out1 "${libraryid}"_L"${lane}"_R1_postartrimmed.fq.gz --out2 "${libraryid}"_L"${lane}"_R2_postartrimmed.fq.gz
"""
}
}
// When not collapsing paired-end data, re-merge the R1 and R2 files into single map. Otherwise if SE or collapsed PE, R2 now becomes NA
// Sort to make sure we get consistent R1 and R2 ordered when using `-resume`, even if not needed for FastQC
if ( params.skip_collapse ){