-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaline.nf
1245 lines (1144 loc) · 58 KB
/
aline.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
nextflow.enable.dsl=2
// Import
import static groovy.io.FileType.FILES
import java.nio.file.*
//*************************************************
// STEP 0 - parameters
//*************************************************
/*
* Default pipeline parameters. They can be overriden on the command line eg.
* given `params.foo` specify on the run command line `--foo some_value`.
*/
// Input/output params
params.reads = "/path/to/reads_{1,2}.fastq.gz"
params.genome = "/path/to/genome.fa"
params.outdir = "alignment_results"
params.reads_extension = ".fastq.gz" // Extension used to detect reads in folder
params.paired_reads_pattern = "{1,2}"
read_type_allowed = [ 'short_paired', 'short_single', 'pacbio', 'ont' ]
params.read_type = "short_paired"
params.relax = false // allow to use options that do not reflect expectation according to the read type
// Read feature params
libtype_allowed = [ 'U', 'IU', 'MU', 'OU', 'ISF', 'ISR', 'MSF', 'MSR', 'OSF', 'OSR' ]
params.library_type = "auto"
params.skip_libray_usage = false // Avoid to use library type provided by library_type or auto
params.read_length = "" // Use by star to set the sjdbOverhang parameter
// annotation is used by different aligner (star, etc.). To avoid to duplicate processes according to the presence of the annotation file, a specific process is dedicated to create a fake file is none provided.
// If process receive a file wich is not the fake one it includes the file in the command. To append the options of aligner we will use the annotation_file variable
// While the processes will be called sending the "annotation" channel created by the prepare_annotation process.
params.annotation = ""
// Trimming params
params.trimming_fastp = false
// Aligner params
align_tools = [ 'bbmap', 'bowtie', 'bowtie2', 'bwaaln', 'bwamem', 'bwasw', 'graphmap2', 'hisat2', 'kallisto', 'minimap2', 'novoalign', 'nucmer', 'ngmlr', 'star', 'subread', 'sublong' ]
params.aligner = ''
params.bbmap_options = ''
params.bowtie_options = ''
params.bowtie2_options = ''
params.bwaaln_options = ''
params.bwamem_options = ''
params.bwasw_options = ''
params.graphmap2_options = '' // owler option is possible
params.hisat2_options = ''
params.kallisto_options = ''
params.kallisto_index_options = '' // e.g. to use --distinguish, --make-unique, etc...
params.minimap2_options = ''
params.minimap2_index_options = '' // -k, -w, -H and -I
params.ngmlr_options = ''
params.novoalign_options = ''
params.novoalign_license = '' // license. You can ask for one month free trial license at http://www.novocraft.com/products/novoalign/
params.nucmer_options = ''
params.star_options = ''
params.star_index_options = ''
params.star_2pass = false
params.subread_options = '-t 0'// -t specifes the type of input sequencing data. Possible values include 0, denoting RNA-seq data, or 1, denoting genomic DNA-seq data.
params.sublong_options = '-X'// -X turn on the RNA-seq mode.
// Report params
params.fastqc = false
params.samtools_stats = false
params.multiqc_config = "$baseDir/config/multiqc_conf.yml"
// other
params.help = null
params.seqtk_sample_size = 10000 // number of reads to sample for seqtk - used to determnine the library type
bbmap_tool = "bbmap.sh"
star_tool = "STAR"
params.debug = false
//*************************************************
// STEP 1 - HELP
//*************************************************
log.info header()
if (params.help) { exit 0, helpMSG() }
//*************************************************
// STEP 1 - PARAMS CHECK
//*************************************************
def stop_pipeline = false
log.info """check aligner provided: ${params.aligner} ..."""
// Check aligner params. Can be a list (comma or space separated)
def aligner_list=[]
if( !params.aligner ){
exit 1, "Error: <aligner> parameter is empty, please provide a aligner(s) among this list ${align_tools}.\n"
} else {
str_list = params.aligner.tokenize(',')
str_list.each {
str_list2 = it.tokenize(' ')
str_list2.each {
if ( ! (it.toLowerCase() in align_tools) ){
exit 1, "Error: <${it}> aligner not acepted, please provide aligner(s) among this list ${align_tools}.\n"
}
else{
aligner_list.add(it.toLowerCase())
}
}
}
}
// check read type parameter
log.info """check read type parameter: ${params.read_type} ..."""
if( ! params.read_type ){
exit 1, "Error: <read_type> parameter is empty, please provide a read type among this list ${read_type_allowed}.\n"
} else {
if ( ! (params.read_type.toLowerCase() in read_type_allowed) ){
exit 1, "Error: <${params.read_type}> aligner not acepted, please provide a read type among this list ${read_type_allowed}.\n"
}
}
// check read library type parameter
log.info """check readlibrary type parameter: ${params.library_type} ..."""
if( ! params.library_type.contains("auto") ){
if ( ! (params.library_type.toUpperCase() in libtype_allowed) ){
exit 1, "Error: <${params.library_type}> library type is not accepted, please provide a library type among this list ${libtype_allowed}.\n"
}
}
// ---- check annotation file
def annotation_file
if (params.annotation){
if (params.annotation.startsWith('http:') || params.annotation.startsWith('https:') || params.annotation.startsWith('s3:') || params.annotation.startsWith('az:') || params.annotation.startsWith('gs:') || params.annotation.startsWith('ftp:') ) {
annotation_file = file(params.annotation)
annotation_file = annotation_file.getName()
} else {
File f = new File( "${params.annotation}" );
if (! f.exists() ){
log.error "Warning: Annotation file <${params.annotation}> does not exist.\n"
stop_pipeline = true
}
annotation_file = f.getName()
}
}
// ----------------------------------------------------------
// Add annotation file within the tool options if annotation provided
// Add specific options for aligner according to the read type
log.info """check alinger parameters ..."""
// --- bbmap tool ---
if ("bbmap" in aligner_list && !params.relax){
if (params.read_type == "pacbio" || params.read_type == "ont"){
bbmap_tool = "mapPacBio.sh"
// Function to check and set maxlen in params.bbmap_options when long_reads is set
// params is supposed to be a immutable. Using params.replace method might not be supported in the future
if ( !params.bbmap_options.contains("maxlen") ){
params.replace("bbmap_options", "${params.bbmap_options} maxlen=5000")
}
}
}
// --- bwa aln tool ---
//if ("bwaaln" in aligner_list && !params.relax){
// if (params.read_type == "pacbio" || params.read_type == "ont"){
// log.warn("""Error: bwaaln is not suitable for long reads.
//However, if you know what you are doing you can activate the AliNe --relax parameter to use it anyway.\n""")
// stop_pipeline = true
// }
//}
// --- bwa mem tool ---
if ("bwamem" in aligner_list && !params.relax){
if (params.read_type == "pacbio"){
if ( !params.bwamem_options.contains(" pacbio") ){
params.replace("bwamem_options", "${params.bwamem_options} -x pacbio")
}
}
if (params.read_type == "ont"){
if ( !params.bwamem_options.contains(" ont2d") ){
params.replace("bwamem_options", "${params.bwamem_options} -x ont2d")
}
}
}
// --- bwa sw tool ---
if ("bwasw" in aligner_list && !params.relax){
if (params.read_type == "pacbio"){
if ( !params.bwasw_options.contains(" pacbio") ){
params.replace("bwamem_options", "${params.bwasw_options} -x pacbio")
}
}
if (params.read_type == "ont"){
if ( !params.bwasw_options.contains(" ont2d") ){
params.replace("bwamem_options", "${params.bwasw_options} -x ont2d")
}
}
}
// --- graphmap2 tool ---
if ("graphmap2" in aligner_list ){
if (annotation_file && !params.graphmap2_options.contains("--gtf ") ){
params.replace("graphmap2_options", "${params.graphmap2_options} --gtf ${annotation_file}")
}
}
if ( "kallisto" in aligner_list ){
if ( params.read_type == "ont" || params.read_type == "pacbio"){
log.warn "Kallisto aligner is not recommended to align long reads!\n"
}
}
// ---- minimap2 tool ---
// Force -a option to be sure to get sam output
if ("minimap2" in aligner_list && !params.relax){
if (params.read_type == "short_single" || params.read_type == "short_paired"){
if ( ! params.minimap2_options.contains("--sr ") ){
params.replace("minimap2_options", "--sr ${params.minimap2_options}")
}
}
if (params.read_type == "pacbio"){
if ( ! params.minimap2_options.contains(" ava-pb") and ! params.minimap2_options.contains(" splice:hq") and
! params.minimap2_options.contains(" map-hifi") and ! params.minimap2_options.contains(" map-pb") ){
log.warn("""Warn: <${params.minimap2_options}> minimap2 options missing or not accepted for pacbio data.
We set the default <map-pb> parameter. If you do not agree, please provide options among this list:
ava-pb, splice:hq, map-hifi, map-pb (see https://github.com/lh3/minimap2).
If you wish to use parameter not intended for pacbio data use the --relax parameter to skip this warning message.\n""")
params.replace("minimap2_options", "${params.minimap2_options} -x map-pb")
}
}
if (params.read_type == "ont"){
if ( ! params.minimap2_options.contains(" ava-ont") and ! params.minimap2_options.contains(" splice") and
! params.minimap2_options.contains(" lr:hq") and ! params.minimap2_options.contains(" map-ont") ){
log.warn("""Warn: <${params.minimap2_options}> minimap2 options missing or not accepted for ont data.
We set the default <map-ont> option. If you do not agree, please provide options among this list:
ava-ont, splice, lr:hq, map-ont (see https://github.com/lh3/minimap2).
If you wish to use parameter not intended for pacbio data use the --relax parameter to skip this warning message.\n""")
params.replace("minimap2_options", "${params.minimap2_options} -x map-ont")
}
}
}
// relax or not this option has to be used
if ( ! params.minimap2_options.contains("-a ") ){
params.replace("minimap2_options", "${params.minimap2_options} -a")
}
// ngmlr tool - check options
if ("ngmlr" in aligner_list ){
if (!params.relax) {
// for pacbio reads, set -g 20 and -x 0
if (params.read_type == "ont"){
if (! params.ngmlr_options.contains("-x ont")){
params.replace("ngmlr_options", "${params.ngmlr_options} -x ont")
}
}
//else if (params.read_type.contains("short") ){
// log.warn ": ngmlr aligner do not handle short reads, please remove it from the list of aligner to use.\nOtherwise, if you know what you are doing you can activate the AliNe --relax parameter to use options that do not reflect expectation.\n"
//stop_pipeline = true
//}
}
if ( params.read_type == "short_paired"){
log.error "ngmlr aligner does not handle paired reads, please remove it from the list of aligner to use.\n"
stop_pipeline = true
}
}
// novoalign tool - load license into the container
def novoalign_lic = ""
if ("novoalign" in aligner_list ){
if( params.novoalign_license ){
File f = new File( "${params.novoalign_license}" );
if (! f.exists() ){
log.warn ": NovoAlign aligner selected but license file <${params.novoalign_license}> does not exist.\n"
stop_pipeline = true
}
license_file = f.getName()
novoalign_lic = "-v ${params.novoalign_license}:/usr/local/bin/${license_file}"
} else {
log.warn ": NovoAlign aligner selected but no license provided. Please provide a license to run novoalign.\n"
stop_pipeline = true
}
if (!params.relax) {
// for pacbio reads, set -g 20 and -x 0
if (params.read_type == "pacbio" || params.read_type == "ont"){
if (! params.novoalign_options.contains("-g ")){
params.replace("novoalign_options", "${params.novoalign_options} -g 20")
}
if (! params.novoalign_options.contains("-x ")){
params.replace("novoalign_options", "${params.novoalign_options} -x 0")
}
}
}
}
// --- star tool ---
if ( "star" in aligner_list ){
if (annotation_file && !params.star_options.contains("--sjdbGTFfile ") ){
params.replace("star_options", "${params.star_options} --sjdbGTFfile ${annotation_file}")
}
if (!params.relax){
if (params.read_type == "pacbio" || params.read_type == "ont"){
star_tool = "STARlong"
}
}
}
// --- subread tool ---
if ( "subread" in aligner_list ){
if (annotation_file && !params.subread_options.contains("-a ") ){
params.replace("subread_options", "${params.subread_options} -a ${annotation_file}")
}
}
if ( "sublong" in aligner_list ){
if ( params.read_type == "short_paired"){
log.error "Sublong aligner does not handle paired reads, please remove it from the list of aligner to use.\n"
stop_pipeline = true
}
}
if(stop_pipeline){
exit 1, "Please fix previous issues in order to run the pipeline.\n"
}
//*************************************************
// STEP 1 - LOG INFO
//*************************************************
log.info """
General Parameters
genome : ${params.genome}
reads : ${params.reads}
annotation : ${params.annotation}
aligner : ${params.aligner}
read_type : ${params.read_type}
paired_reads_pattern : ${params.paired_reads_pattern}
reads_extension : ${params.reads_extension}
library_type : ${params.library_type}
skip_libray_usage : ${params.skip_libray_usage}
outdir : ${params.outdir}
Report Parameters
fastqc : ${params.fastqc}
samtools_stats : ${params.samtools_stats}
multiqc_config : ${params.multiqc_config}
"""
log.info printAlignerOptions(aligner_list, annotation_file, params.star_index_options)
//*************************************************
// STEP 2 - Include needed modules
//*************************************************
include {read_length; set_tuple_withUserReadLength} from "$baseDir/modules/bash.nf"
include {bbmap_index; bbmap} from "$baseDir/modules/bbmap.nf"
include {bowtie_index; bowtie} from "$baseDir/modules/bowtie.nf"
include {bowtie2_index; bowtie2} from "$baseDir/modules/bowtie2.nf"
include {bwa_index; bwaaln; bwamem; bwasw} from "$baseDir/modules/bwa.nf"
include {seqkit_convert} from "$baseDir/modules/seqkit.nf"
include {graphmap2_index; graphmap2} from "$baseDir/modules/graphmap2.nf"
include {fastp} from "$baseDir/modules/fastp.nf"
include {fastqc as fastqc_raw; fastqc as fastqc_fastp; fastqc as fastqc_ali_bbmap; fastqc as fastqc_ali_bowtie ; fastqc as fastqc_ali_bowtie2 ;
fastqc as fastqc_ali_bwaaln; fastqc as fastqc_ali_bwamem; fastqc as fastqc_ali_bwasw; fastqc as fastqc_ali_graphmap2 ;
fastqc as fastqc_ali_hisat2; fastqc as fastqc_ali_kallisto; fastqc as fastqc_ali_minimap2; fastqc as fastqc_ali_ngmlr;
fastqc as fastqc_ali_novoalign ; fastqc as fastqc_ali_nucmer; fastqc as fastqc_ali_star; fastqc as fastqc_ali_subread ;
fastqc as fastqc_ali_sublong } from "$baseDir/modules/fastqc.nf"
include {hisat2_index; hisat2} from "$baseDir/modules/hisat2.nf"
include {kallisto_index; kallisto} from "$baseDir/modules/kallisto.nf"
include {minimap2_index; minimap2} from "$baseDir/modules/minimap2.nf"
include {multiqc} from "$baseDir/modules/multiqc.nf"
include {ngmlr} from "$baseDir/modules/ngmlr.nf"
include {nucmer} from "$baseDir/modules/mummer4.nf"
include {novoalign_index; novoalign} from "$baseDir/modules/novoalign.nf"
include {salmon_index; salmon_guess_lib; set_tuple_withUserLib} from "$baseDir/modules/salmon.nf"
include {samtools_sam2bam_nucmer; samtools_sam2bam as samtools_sam2bam_bowtie; samtools_sam2bam as samtools_sam2bam_bowtie2; samtools_sam2bam as samtools_sam2bam_bwaaln;
samtools_sam2bam as samtools_sam2bam_bwamem; samtools_sam2bam as samtools_sam2bam_bwasw; samtools_sam2bam as samtools_sam2bam_graphmap2;
samtools_sam2bam as samtools_sam2bam_hisat2; samtools_sam2bam as samtools_sam2bam_minimap2;
samtools_sam2bam as samtools_sam2bam_ngmlr; samtools_sam2bam as samtools_sam2bam_novoalign } from "$baseDir/modules/samtools.nf"
include {samtools_sort as samtools_sort_bbmap; samtools_sort as samtools_sort_bowtie; samtools_sort as samtools_sort_bowtie2; samtools_sort as samtools_sort_bwaaln;
samtools_sort as samtools_sort_bwamem; samtools_sort as samtools_sort_bwasw; samtools_sort as samtools_sort_graphmap2;
samtools_sort as samtools_sort_hisat2; samtools_sort as samtools_sort_minimap2; samtools_sort as samtools_sort_ngmlr;
samtools_sort as samtools_sort_novoalign; samtools_sort as samtools_sort_nucmer;
samtools_sort as samtools_sort_sublong } from "$baseDir/modules/samtools.nf"
include {samtools_stats as samtools_stats_ali_bbmap; samtools_stats as samtools_stats_ali_bowtie ; samtools_stats as samtools_stats_ali_bowtie2 ;
samtools_stats as samtools_stats_ali_bwaaln; samtools_stats as samtools_stats_ali_bwamem; samtools_stats as samtools_stats_ali_bwasw; samtools_stats as samtools_stats_ali_graphmap2 ;
samtools_stats as samtools_stats_ali_hisat2; samtools_stats as samtools_stats_ali_kallisto; samtools_stats as samtools_stats_ali_minimap2; samtools_stats as samtools_stats_ali_ngmlr;
samtools_stats as samtools_stats_ali_novoalign ; samtools_stats as samtools_stats_ali_nucmer; samtools_stats as samtools_stats_ali_star; samtools_stats as samtools_stats_ali_subread ;
samtools_stats as samtools_stats_ali_sublong } from "$baseDir/modules/samtools.nf"
include {seqtk_sample} from "$baseDir/modules/seqtk.nf"
include {subread_index; subread; sublong_index; sublong} from "$baseDir/modules/subread.nf"
include {prepare_star_index_options; star_index; star; star2pass} from "$baseDir/modules/star.nf"
//*************************************************
// STEP 3 - CHECK 2 for parameters
//*************************************************
// check profile
if (
workflow.profile.contains('singularity') ||
workflow.profile.contains('docker')
) { "executer selected" }
else { exit 1, "No executer selected: -profile docker/singularity"}
// --------- handle read input (file or folder / local or remote / paired or not) --------
def list_files = []
def pattern_reads
def fromFilePairs_input
def path_reads = params.reads
// check if paired reads
def per_pair = false // read the reads per pair
if (params.read_type == "short_paired") {
per_pair = true
}
// Case of remote data
def via_URL = false
def read_list=[]
if (path_reads.startsWith('https:') || path_reads.startsWith('s3:') || path_reads.startsWith('az:') || path_reads.startsWith('gs:') || path_reads.startsWith('ftp:') ) {
log.info "The input is a based on URLs! ${path_reads}\n"
via_URL = true
str_list = path_reads.tokenize(',')
str_list.each {
str_list2 = it.tokenize(' ')
str_list2.each {
read_list.add(file(it)) // use file insted of File for URL
}
}
fromFilePairs_input = read_list
}
// Case of local data
else {
File input_reads = new File(path_reads)
if(input_reads.exists()){
if ( input_reads.isDirectory()) {
// in case of folder provided, add a trailing slash if missing
path_reads = "${input_reads}" + "/"
}
}
if (params.read_type == "short_paired") {
pattern_reads = "${params.paired_reads_pattern}${params.reads_extension}"
fromFilePairs_input = "${path_reads}*${params.paired_reads_pattern}${params.reads_extension}"
} else{
pattern_reads = "${params.reads_extension}"
fromFilePairs_input = "${path_reads}*${params.reads_extension}"
}
if(input_reads.exists()){
if ( input_reads.isDirectory()) {
log.info "The input ${path_reads} is a folder!\n"
input_reads.eachFileRecurse(FILES){
if (it.name =~ ~/${pattern_reads}/){
list_files.add(it)
}
}
samples_number = list_files.size()
log.info "${samples_number} files in ${path_reads} with pattern ${pattern_reads}"
}
else {
log.info "The input ${path_reads} is a file!\n"
fromFilePairs_input = "${path_reads}"
if (params.read_type == "short_paired") {
log.error "Providing a file is not authorized for (local) paired data! Please provide a folder path or change <read_type> parameter to <short_single>.\n"
}
}
} else {
exit 1, "The input ${path_reads} does not exists!\n"
}
}
//*************************************************
// STEP 4 - Main Workflow
//*************************************************
workflow {
main:
// In case of URL paired data, we cannot use fromFilePairs because matching pattern impossible. We must recreate manually a structure similar
if (via_URL && per_pair){
my_samples = Channel.of(read_list)
reads = my_samples.flatten().map { it -> [it.name.split('_')[0], it] }
.groupTuple()
.ifEmpty { exit 1, "Cannot find reads matching ${path_reads}!\n" }
} else {
reads = Channel.fromFilePairs(fromFilePairs_input, size: per_pair ? 2 : 1, checkIfExists: true)
.ifEmpty { exit 1, "Cannot find reads matching ${path_reads}!\n" }
}
genome = Channel.fromPath(params.genome, checkIfExists: true)
.ifEmpty { exit 1, "Cannot find genome matching ${params.genome}!\n" }
if(annotation_file){
annotation = Channel.fromPath(params.annotation, checkIfExists: true)
.ifEmpty { exit 1, "Cannot find annotation matching ${annotation_file}!\n" }
} else {
annotation = Channel.of("$baseDir/config/aline_null.gtf") // use the fake file (not used by tools just for the processes to be called)
}
align(reads, genome, annotation, aligner_list)
}
//*************************************************
// STEP 4 - Workflow align
//*************************************************
workflow align {
take:
raw_reads
genome
annotation
aligner_list
main:
// Initialize channels
Channel.empty().set{logs}
Channel.empty().set{sorted_bam}
// ------------------------------------------------------------------------------------------------
// PREPROCESSING
// ------------------------------------------------------------------------------------------------
// ------------------- QC -----------------
if(params.fastqc){
fastqc_raw(raw_reads, "fastqc/raw", "raw")
logs.concat(fastqc_raw.out).set{logs} // save log
}
// ------------------- Standardize Score to Be Phred+33 ----------------
params.debug && log.info('Standardize Score to Be Phred+33')
seqkit_convert(raw_reads, "seqkit_score")
seqkit_convert.out.trimmed.set{raw_reads_standardized}
// ------------------------------------------------------------------------------------------------
// TRIMMING
// ------------------------------------------------------------------------------------------------
// ------------------- FASTP -----------------
if (params.trimming_fastp){
params.debug && log.info('fastp trimming')
fastp(raw_reads_standardized, "fastp")
fastp.out.trimmed.set{raw_reads_trim}
logs.concat(fastp.out.report).set{logs} // save log
if(params.fastqc){
fastqc_fastp(raw_reads_trim, "fastqc/trimming_fastp", "trimmed")
logs.concat(fastqc_fastp.out).set{logs} // save log
}
} else {
raw_reads_trim = raw_reads_standardized
}
// ------------------------------------------------------------------------------------------------
// LIBRARY TYPE GUESSING -
// here we subsample and do read length and library type guessing only if needed.
// ------------------------------------------------------------------------------------------------
// In which case I need the mean read length (kallisto, star)
// Need to list here all aligner that need the read length
params.debug && log.info('read_length guessing')
def guess_read_length = null
if ( (!params.read_length) &&
( ("kallisto" in aligner_list && params.read_type == "short_single" && ( !params.kallisto_options.contains("-l ") || !params.kallisto_options.contains("--fragment-length ") ) ) ||
( annotation.toString() != "aline_null.gtf" && !params.star_index_options.contains("--sjdbOverhang") ) ) ){
guess_read_length=1
}
params.debug && log.info('subsample guessing')
// Should I subsample for library type guessing?
def subsample_lg = false
if (params.library_type.contains("auto")){
subsample_lg = true
}
// Subsample if needed (can be for library guessing or read length guessing)
if (subsample_lg || guess_read_length){
// ------------------- subsample -----------------
seqtk_sample(raw_reads_trim)
}
// ------------------- set libtype -----------------
if (params.library_type.contains("auto")){
// ------------------- guess libtype -------------------
salmon_index(genome.collect())
salmon_guess_lib(seqtk_sample.out.sampled, salmon_index.out.index, "salmon_libtype")
salmon_guess_lib.out.tuple_id_libtype.set{tuple_id_lib}
} else {
set_tuple_withUserLib(raw_reads_trim)
set_tuple_withUserLib.out.set{tuple_id_lib}
}
reads = raw_reads_trim.join(tuple_id_lib)
// ------------------- set read length -----------------
if (guess_read_length){
read_length(seqtk_sample.out.sampled, "mean_read_length")
read_length.out.tuple_id_readlength.set{tuple_id_readle}
}else{
set_tuple_withUserReadLength(raw_reads_trim)
set_tuple_withUserReadLength.out.set{tuple_id_readle}
}
reads = reads.join(tuple_id_readle)
// ------------------------------------------------------------------------------------------------
// ALIGNEMENT
// ------------------------------------------------------------------------------------------------
// ------------------- BBMAP -----------------
if ("bbmap" in aligner_list ){
// index
bbmap_index(genome.collect(), "alignment/bbmap/indicies")
// align
bbmap(reads, genome.collect(), bbmap_index.out.collect(), "alignment/bbmap")
logs.concat(bbmap.out.bbmap_summary).set{logs} // save log
// sort
samtools_sort_bbmap(bbmap.out.tuple_sample_bam, "alignment/bbmap")
samtools_sort_bbmap.out.tuple_sample_sortedbam.set{bbmap_ali} // set name
// save aligned reads
sorted_bam.concat(bbmap_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bbmap(bbmap_ali, "fastqc/bbmap", "bbmap")
logs.concat(fastqc_ali_bbmap.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bbmap(bbmap_ali, genome.collect(), "samtools_stats/bbmap", "bbmap")
logs.concat(samtools_stats_ali_bbmap.out).set{logs} // save log
}
}
// ------------------- BOWTIE -----------------
if ( "bowtie" in aligner_list ){ // &&
bowtie_index(genome.collect(), "alignment/bowtie/indicies") // index
bowtie(reads, genome.collect(), bowtie_index.out.collect(), "alignment/bowtie") // align
logs.concat(bowtie.out.bowtie_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_bowtie(bowtie.out.tuple_sample_sam)
// sort
samtools_sort_bowtie(samtools_sam2bam_bowtie.out.tuple_sample_bam, "alignment/bowtie")
samtools_sort_bowtie.out.tuple_sample_sortedbam.set{bowtie_ali} // set name
// save aligned reads
sorted_bam.concat(bowtie_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bowtie(bowtie_ali, "fastqc/bowtie", "bowtie")
logs.concat(fastqc_ali_bowtie.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bowtie(bowtie_ali, genome.collect(), "samtools_stats/bowtie", "bowtie")
logs.concat(samtools_stats_ali_bowtie.out).set{logs} // save log
}
}
// ------------------- BOWTIE2 -----------------
if ( "bowtie2" in aligner_list ){
// index
bowtie2_index(genome.collect(), "alignment/bowtie2/indicies")
// align
bowtie2(reads, genome.collect(), bowtie2_index.out.collect(), "alignment/bowtie2")
logs.concat(bowtie2.out.bowtie2_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_bowtie2(bowtie2.out.tuple_sample_sam)
// sort
samtools_sort_bowtie2(samtools_sam2bam_bowtie2.out.tuple_sample_bam, "alignment/bowtie2")
samtools_sort_bowtie2.out.tuple_sample_sortedbam.set{bowtie2_ali} // set name
// save aligned reads
sorted_bam.concat(bowtie2_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bowtie2(bowtie2_ali, "fastqc/bowtie2", "bowtie2")
logs.concat(fastqc_ali_bowtie2.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bowtie2(bowtie2_ali, genome.collect(), "samtools_stats/bowtie2", "bowtie2")
logs.concat(samtools_stats_ali_bowtie2.out).set{logs} // save log
}
}
// ------------------- BWA -----------------
if ("bwaaln" in aligner_list || "bwamem" in aligner_list || "bwasw" in aligner_list){
// index
bwa_index(genome.collect(), "alignment/bwa/indicies")
if ("bwaaln" in aligner_list){
// align
bwaaln(reads, genome.collect(), bwa_index.out.collect(), "alignment/bwa/bwaaln")
logs.concat(bwaaln.out.bwaaln_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_bwaaln(bwaaln.out.tuple_sample_sam)
// sort
samtools_sort_bwaaln(samtools_sam2bam_bwaaln.out.tuple_sample_bam, "alignment/bwa/bwaaln")
samtools_sort_bwaaln.out.tuple_sample_sortedbam.set{bwaaln_ali} // set name
// save aligned reads
sorted_bam.concat(bwaaln_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bwaaln(bwaaln_ali, "fastqc/bwaaln", "bwaaln")
logs.concat(fastqc_ali_bwaaln.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bwaaln(bwaaln_ali, genome.collect(), "samtools_stats/bwaaln", "bwaaln")
logs.concat(samtools_stats_ali_bwaaln.out).set{logs} // save log
}
}
if ("bwamem" in aligner_list){
// align
bwamem(reads, genome.collect(), bwa_index.out.collect(), "alignment/bwa/bwamem")
logs.concat(bwamem.out.bwamem_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_bwamem(bwamem.out.tuple_sample_sam)
// sort
samtools_sort_bwamem(samtools_sam2bam_bwamem.out.tuple_sample_bam, "alignment/bwa/bwamem")
samtools_sort_bwamem.out.tuple_sample_sortedbam.set{bwamem_ali} // set name
// save aligned reads
sorted_bam.concat(bwamem_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bwamem(bwamem_ali, "fastqc/bwamem", "bwamem")
logs.concat(fastqc_ali_bwamem.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bwamem(bwamem_ali, genome.collect(), "samtools_stats/bwamem", "bwamem")
logs.concat(samtools_stats_ali_bwamem.out).set{logs} // save log
}
}
if ("bwasw" in aligner_list){
// align
bwasw(reads, genome.collect(), bwa_index.out.collect(), "alignment/bwa/bwasw")
logs.concat(bwasw.out.bwasw_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_bwasw(bwasw.out.tuple_sample_sam)
// sort
samtools_sort_bwasw(samtools_sam2bam_bwasw.out.tuple_sample_bam, "alignment/bwa/bwasw")
samtools_sort_bwasw.out.tuple_sample_sortedbam.set{bwasw_ali} // set name
// save aligned reads
sorted_bam.concat(bwasw_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_bwasw(bwasw_ali, "fastqc/bwasw", "bwasw")
logs.concat(fastqc_ali_bwasw.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_bwasw(bwasw_ali, genome.collect(), "samtools_stats/bwasw", "bwasw")
logs.concat(samtools_stats_ali_bwasw.out).set{logs} // save log
}
}
}
// ------------------- GRAPHMAP2 -----------------
if ("graphmap2" in aligner_list ){
// index
graphmap2_index(genome.collect(), "alignment/graphmap2/indicies")
// align
graphmap2(reads, genome.collect(), graphmap2_index.out.collect(), annotation.collect(), "alignment/graphmap2")
logs.concat(graphmap2.out.graphmap2_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_graphmap2(graphmap2.out.tuple_sample_sam)
// sort
samtools_sort_graphmap2(samtools_sam2bam_graphmap2.out.tuple_sample_bam, "alignment/graphmap2")
samtools_sort_graphmap2.out.tuple_sample_sortedbam.set{graphmap2_ali} // set name
// save aligned reads
sorted_bam.concat(graphmap2_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_graphmap2(graphmap2_ali, "fastqc/graphmap2", "graphmap2")
logs.concat(fastqc_ali_graphmap2.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_graphmap2(graphmap2_ali, genome.collect(), "samtools_stats/graphmap2", "graphmap2")
logs.concat(samtools_stats_ali_graphmap2.out).set{logs} // save log
}
}
// ------------------- HISAT2 -----------------
if ("hisat2" in aligner_list){
// index
hisat2_index(genome.collect(), "alignment/hisat2/indicies")
// align
hisat2(reads, hisat2_index.out.collect(), "alignment/hisat2")
logs.concat(hisat2.out.hisat2_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_hisat2(hisat2.out.tuple_sample_sam)
// sort
samtools_sort_hisat2(samtools_sam2bam_hisat2.out.tuple_sample_bam, "alignment/hisat2")
samtools_sort_hisat2.out.tuple_sample_sortedbam.set{hisat2_ali} // set name
// save aligned reads
sorted_bam.concat(hisat2_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_hisat2(hisat2_ali, "fastqc/hisat2", "hisat2")
logs.concat(fastqc_ali_hisat2.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_hisat2(hisat2_ali, genome.collect(), "samtools_stats/hisat2", "hisat2")
logs.concat(samtools_stats_ali_hisat2.out).set{logs} // save log
}
}
// ------------------- KALLISTO -----------------
if ("kallisto" in aligner_list){
// index
kallisto_index(genome.collect(), "alignment/kallisto/indicies")
// align
kallisto(reads, kallisto_index.out.collect(), "alignment/kallisto")
logs.concat(kallisto.out.kallisto_summary).set{logs} // save log
kallisto.out.tuple_sample_bam.set{kallisto_ali} // set name
// save aligned reads
sorted_bam.concat(kallisto_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_kallisto(kallisto_ali, "fastqc/kallisto", "kallisto")
logs.concat(fastqc_ali_kallisto.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_kallisto(kallisto_ali, genome.collect(), "samtools_stats/kallisto", "kallisto")
logs.concat(samtools_stats_ali_kallisto.out).set{logs} // save log
}
}
// ------------------- minimap2 -----------------
if ("minimap2" in aligner_list ){
// index
minimap2_index(genome.collect(), "alignment/minimap2/indicies")
// align
minimap2(reads, genome.collect(), minimap2_index.out.collect(), "alignment/minimap2")
logs.concat(minimap2.out.minimap2_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_minimap2(minimap2.out.tuple_sample_sam)
// sort
samtools_sort_minimap2(samtools_sam2bam_minimap2.out.tuple_sample_bam, "alignment/minimap2")
samtools_sort_minimap2.out.tuple_sample_sortedbam.set{minimap2_ali} // set name
// save aligned reads
sorted_bam.concat(minimap2_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_minimap2(minimap2_ali, "fastqc/minimap2", "minimap2")
logs.concat(fastqc_ali_minimap2.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_minimap2(minimap2_ali, genome.collect(), "samtools_stats/minimap2", "minimap2")
logs.concat(samtools_stats_ali_minimap2.out).set{logs} // save log
}
}
// --------------------- NGMLR --------------------
if ("ngmlr" in aligner_list ){
// align
ngmlr(reads, genome.collect(), "alignment/ngmlr")
logs.concat(ngmlr.out.ngmlr_summary).set{logs} // save log
// convert sam to bam
samtools_sam2bam_ngmlr(ngmlr.out.tuple_sample_sam)
// sort
samtools_sort_ngmlr(samtools_sam2bam_ngmlr.out.tuple_sample_bam, "alignment/ngmlr")
samtools_sort_ngmlr.out.tuple_sample_sortedbam.set{ngmlr_ali} // set name
// save aligned reads
sorted_bam.concat(ngmlr_ali).set{sorted_bam}
// stat on aligned reads
if (params.fastqc){
fastqc_ali_ngmlr(ngmlr_ali, "fastqc/ngmlr", "ngmlr")
logs.concat(fastqc_ali_ngmlr.out).set{logs} // save log
}
if (params.samtools_stats){
samtools_stats_ali_ngmlr(ngmlr_ali, genome.collect(), "samtools_stats/ngmlr", "ngmlr")
logs.concat(samtools_stats_ali_ngmlr.out).set{logs} // save log
}
}
// ------------------- novoalign -----------------
if ("novoalign" in aligner_list ){
// index
novoalign_index(genome.collect(), "alignment/minimap2/indicies")
// align
novoalign(reads, genome.collect(), novoalign_index.out.collect(), novoalign_lic, "alignment/novoalign")
// convert sam to bam
samtools_sam2bam_novoalign(novoalign.out.tuple_sample_sam)
// sort
samtools_sort_novoalign(samtools_sam2bam_novoalign.out.tuple_sample_bam, "alignment/novoalign")
samtools_sort_novoalign.out.tuple_sample_sortedbam.set{novoalign_ali} // set name
// save aligned reads
sorted_bam.concat(novoalign_ali).set{sorted_bam}
// stat on aligned reads
if (params.fastqc){
fastqc_ali_novoalign(novoalign_ali, "fastqc/novoalign", "novoalign")
logs.concat(fastqc_ali_novoalign.out).set{logs} // save log
}
if (params.samtools_stats){
samtools_stats_ali_novoalign(novoalign_ali, genome.collect(), "samtools_stats/novoalign", "novoalign")
logs.concat(samtools_stats_ali_novoalign.out).set{logs} // save log
}
}
// ------------------- nucmer (mummer4) -----------------
if ("nucmer" in aligner_list ){
// align
nucmer(reads, genome.collect(), "alignment/nucmer")
// No summary available. To get one we could run show-coords see https://mummer4.github.io/tutorial/tutorial.html
// convert sam to bam
samtools_sam2bam_nucmer(nucmer.out.tuple_sample_sam, genome.collect())
// sort
samtools_sort_nucmer(samtools_sam2bam_nucmer.out.tuple_sample_bam, "alignment/nucmer")
samtools_sort_nucmer.out.tuple_sample_sortedbam.set{nucmer_ali} // set name
// save aligned reads
sorted_bam.concat(nucmer_ali).set{sorted_bam}
// stat on aligned reads
if (params.fastqc){
fastqc_ali_nucmer(nucmer_ali, "fastqc/nucmer", "nucmer")
logs.concat(fastqc_ali_nucmer.out).set{logs} // save log
}
if (params.samtools_stats){
samtools_stats_ali_nucmer(nucmer_ali, genome.collect(), "samtools_stats/nucmer", "nucmer")
logs.concat(samtools_stats_ali_nucmer.out).set{logs} // save log
}
}
// ------------------- STAR -----------------
if ( "star" in aligner_list ){
// Take read length information from only one sample for --sjdbOverhang option
// only needed if --sjdbFileChrStartEnd or --sjdbGTFfile option is activated)
first_file = reads.first()
prepare_star_index_options(first_file, annotation.collect())
star_index(genome.collect(), prepare_star_index_options.out, annotation, "alignment/star/indicies") // index
star(reads, star_index.out.collect(), annotation.collect(), "alignment/star") // align out is bam and sorted
logs.concat(star.out.star_summary).set{logs} // save log
star.out.splice_junctions.collect().set{splice_junctions} // save splice junction files
// If 2pass mode
if(params.star_2pass){
star2pass(reads, star_index.out.collect(), splice_junctions, annotation.collect(), "alignment/star") // align out is bam and sorted
logs.concat(star2pass.out.star_summary).set{logs} // save log
star2pass.out.tuple_sample_bam.set{star_ali} // save aligned reads
} else {
star.out.tuple_sample_bam.set{star_ali} // save aligned reads
}
// save aligned reads
sorted_bam.concat(star_ali).set{sorted_bam}
// stat on aligned reads
if(params.fastqc){
fastqc_ali_star(star_ali, "fastqc/star", "star")
logs.concat(fastqc_ali_star.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_star(star_ali, genome.collect(), "samtools_stats/star", "star")
logs.concat(samtools_stats_ali_star.out).set{logs} // save log
}
}
// ---------------- subread -----------------
if ( "subread" in aligner_list ){
// index
subread_index(genome.collect(), "alignment/subread/indicies")
// align
subread(reads, genome.collect(), subread_index.out.collect(), annotation.collect(), "alignment/subread")
subread.out.tuple_sample_bam.set{subread_ali} // set name
// save aligned reads
sorted_bam.concat(subread_ali).set{sorted_bam}
// stat on sorted aligned reads
if(params.fastqc){
fastqc_ali_subread(subread_ali, "fastqc/subread", "subread")
logs.concat(fastqc_ali_subread.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_subread(subread_ali, genome.collect(), "samtools_stats/subread", "subread")
logs.concat(samtools_stats_ali_subread.out).set{logs} // save log
}
}
// ---------------- sublong -----------------
if ( "sublong" in aligner_list ){
// index
sublong_index(genome.collect(), "alignment/sublong/indicies")
// align
sublong(reads, genome.collect(), sublong_index.out.collect(), "alignment/sublong")
// sort
samtools_sort_sublong(sublong.out.tuple_sample_bam, "alignment/sublong")
samtools_sort_sublong.out.tuple_sample_sortedbam.set{sublong_ali} // set name
// save aligned reads
sorted_bam.concat(sublong_ali).set{sorted_bam}
// stat on sorted aligned reads
if(params.fastqc){
fastqc_ali_sublong(sublong_ali, "fastqc/sublong", "sublong")
logs.concat(fastqc_ali_sublong.out).set{logs} // save log
}
if(params.samtools_stats){
samtools_stats_ali_sublong(sublong_ali, genome.collect(), "samtools_stats/sublong", "sublong")
logs.concat(samtools_stats_ali_sublong.out).set{logs} // save log
}
}
// ------------------- MULTIQC -----------------
multiqc(logs.collect(),params.multiqc_config)
emit:
sorted_bam // channel: [ val(meta), pdf ]
}
//*************************************************
def header(){
// Log colors ANSI codes
c_reset = params.monochrome_logs ? '' : "\033[0m";
c_dim = params.monochrome_logs ? '' : "\033[2m";
c_black = params.monochrome_logs ? '' : "\033[0;30m";
c_green = params.monochrome_logs ? '' : "\033[0;32m";
c_yellow = params.monochrome_logs ? '' : "\033[0;33m";
c_blue = params.monochrome_logs ? '' : "\033[0;34m";
c_purple = params.monochrome_logs ? '' : "\033[0;35m";
c_cyan = params.monochrome_logs ? '' : "\033[0;36m";
c_white = params.monochrome_logs ? '' : "\033[0;37m";
c_red = params.monochrome_logs ? '' : "\033[0;31m";