-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.nf
executable file
·1843 lines (1415 loc) · 49.7 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
/*
*/
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* -- ______ ______ _ -- */
/* -- (____ \ /\ (____ \ | | -- */
/* -- ____) ) / \ ____) ) \ \ -- */
/* -- | __ ( / /\ \| __ ( \ \ -- */
/* -- | |__) ) |__| | |__) )____) ) -- */
/* -- |______/|______|______(______/ -- */
/* -- -- */
/* -- ______ ______ _ -- */
/* -- (_____ \| ___ \ /\ | | -- */
/* -- _____) ) | | | / \ ___ \ \ ____ ____ -- */
/* -- (_____ (| | | |/ /\ (___) \ \ / _ ) _ | -- */
/* -- | | | | | |__| |_____) | (/ / | | | -- */
/* -- |_|_| |_|______(______/ \____)_|| | -- */
/* -- |_| -- */
/* -- ______ ___ _ -- */
/* -- | ___ \ _ / __) | -- */
/* -- | | | | ____ _ _| |_ | |__| | ___ _ _ _ -- */
/* -- | | | |/ _ | \ / ) _)| __) |/ _ \| | | | -- */
/* -- | | | ( (/ / ) X (| |__| | | | |_| | | | | -- */
/* -- |_| |_|\____|_/ \_)\___)_| |_|\___/ \____| -- */
/* -- -- */
/* -- ______ _ _ _ -- */
/* -- (_____ (_) | (_) -- */
/* -- _____) ) ____ ____| |_ ____ ____ -- */
/* -- | ____/ | _ \ / _ ) | | _ \ / _ ) -- */
/* -- | | | | | | ( (/ /| | | | | ( (/ / -- */
/* -- |_| |_| ||_/ \____)_|_|_| |_|\____) -- */
/* -- |_| -- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
// the java modules
import java.nio.file.Paths
import java.nio.file.Files
// exotic source modules
import org.yaml.snakeyaml.Yaml
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- USAGE -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def usage() {
log.info"""
Usage:
The workflow can be parametrised with a json or a yaml file or with the
command line. Here are the parameters with the command line:
--design "<path>"
--output_directory "<path>"
--binomial_nomenclature "<Genus> <Species>"
--strandedness "<none|forward|reverse>"
--read_length "<integer>"
--single_end (run single end mode if present)
--genome_type (for example for human "<ensembl>")
--genome_version (for example for human "<GRCh38>")
--genome_release (for example for human "86")
--sequencing_run_directory "<path>"
--sequencing_project_directory "<path>"
--modules "<path>"
--genome_sequence_extension "toplevel.fa"
--fastq_screen_conf "<path>"
--publish_directory_mode "<symlink|link|copy|move>"
--publish_directory_overwrite (overwrite if present)
--r_script "<path>"
--multiqc_config "<path>"
"""
}
params.help = false
if (params.help){
usage()
exit 0
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- METHODS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
/*
* Takes a String, creates the corresponding path after checking if it exists
* and returns the directory path as a File object.
*/
static File createDirPathFromString(String dirpath) {
File dir = new File(dirpath)
if (!dir.exists()) {
boolean dir_creation = dir.mkdirs()
String msg =
"Problem: the " + dirpath +
" directory couldn't have been created..."
assert dir_creation : msg
}
return dir
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* are a list elements contained in another list ? */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def contains_elements(list1, list2) {
// are the elements of list1 present in list2 ?
is_present = []
list1.each{ list2.contains(it) }
// if at least one is absent
return ! is_present.contains(false)
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* gets the columns from the header of a csv file */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def get_columns(csv_path, sep) {
// the header
def header = ""
new File(csv_path).withReader{ header = it.readLine() }
// the columns
def columns = header.split(sep)
return columns
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* is the design file conform ? */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def check_design_file(file_path, single_end_columns, paired_end_columns,
single_end) {
// get the columns from the header of the csv design file
columns = get_columns(file_path, ",")
// the design file must be in accordance with the SINGLE_END parameter
def is_single_end_conform =
contains_elements(single_end_columns, columns) && single_end
def is_paired_end_conform =
contains_elements(paired_end_columns, columns) && (!single_end)
// exit if the situation is neither a SINGLE_END or a !SINGLE_END situation
if ( (!is_single_end_conform) && (!is_paired_end_conform) ) {
// error message
msg = 'Error: the design file must contain either the columns ' +
'["sample,"file"] if it is SINGLE_END, or the columns ' +
'["sample,"file1","file2"] if it is not SINGLE_END'
println msg
exit -1
} else {
return true
}
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* the conditions are all the columns that are not information columns */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def get_conditions(file_path, info_columns) {
// all the columns
def columns = get_columns(file_path, ",")
// the non info columns
def conditions = columns.findAll{ ! info_columns.contains(it) }
return conditions
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* maps the colum name to its position in the design file */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def get_column_map(file_path, info_columns) {
// associate name to position
def column_map = [:]
// the columns of the csv file
def columns = get_columns(file_path, ",")
// the conditions of the experiment
def conditions = get_conditions(file_path, info_columns)
// the sample name
column_map["sample"] = columns.findIndexOf{ it == "sample" }
// the conditions
conditions.each{ cd -> column_map[cd] = columns.findIndexOf{ it == cd } }
// the files location
files = columns.findAll{ ! (conditions+["sample"]).contains(it) }
files.each{ f -> column_map[f] = columns.findIndexOf{ it == f } }
return column_map
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* information in design file is converting into a list of map */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
def get_samples_info(file_path, sep, info_columns) {
// the list of sample information
def samples = []
// the columns and their position
def column_map = get_column_map(file_path, info_columns)
new File(file_path).splitEachLine(sep) { fields ->
def sample = [:]
def keys = column_map.keySet() as List
def values = keys.collect{ fields[column_map[it]] }
// check if it's not the header itself
if ( ! keys.equals(values) ) {
keys.eachWithIndex{ k, i -> sample[k] = values[i] }
samples.add(sample)
}
}
return samples
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- INPUT PARAMETERS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
if (workflow.commandLine.indexOf("-params-file")>0) {
// design
DESIGN_FILEPATH = new File(params.design).getAbsolutePath()
// the output directory
OUTPUT_DIRPATH = params.output_directory
// the reads
SINGLE_END = params.single_end
STRANDEDNESS = params.strandedness
READ_LENGTH = params.read_length
// the binomial nomenclature
GENUS = params.binomial.genus.toLowerCase()
SPECIES = params.binomial.species.toLowerCase()
// annotation
GENOME_TYPE = params.genome_type
GENOME_VERSION = params.genome_version
GENOME_RELEASE = params.genome_release
GENOME_SEQ_EXTENSION = params.genome_sequence_extension
// fastq screen configuration file
FSCREEN_CONF_FILEPATH = new File(params.fastq_screen_conf).getAbsolutePath()
// modules file
MODULES_FILEPATH = new File(params.modules).getAbsolutePath()
// session parameters
PUBLISHDIR_MODE = params.publish_directory_mode
PUBLISHDIR_OVERWRITE = params.publish_directory_overwrite
// r script path
R_SCRIPT_FILEPATH = new File(params.r_script).getAbsolutePath()
// multiqc config file
if (params.multiqc_config) {
MULTIQC_CONFIG_FILEPATH =
new File(params.multiqc_config).getAbsolutePath()
} else {
MULTIQC_CONFIG_FILEPATH = ""
}
} else {
// design
DESIGN_FILEPATH = new File(params.design).getAbsolutePath()
// the output directory
OUTPUT_DIRPATH = params.output_directory
// the binomial nomenclature
BINOMIAL = params.binomial_nomenclature.split(' ')
assert BINOMIAL.size()==2: "Should be --binomial_nomenclature " +
"<Genus> <Species>"
GENUS = BINOMIAL[0].toLowerCase()
SPECIES = BINOMIAL[1].toLowerCase()
// is single end ?
SINGLE_END = params.single_end ? true : false
// strandedness
STRANDEDNESS = params.strandedness.toLowerCase()
def strandedness_values = ["none", "forward", "reverse"]
assert STRANDEDNESS in strandedness_values : "Should be --strandedness " +
"<none|forward|reverse>"
// read length
READ_LENGTH = params.read_length
// annotation
GENOME_TYPE = params.genome_type
GENOME_VERSION = params.genome_version
GENOME_RELEASE = params.genome_release
GENOME_SEQ_EXTENSION = params.genome_sequence_extension
// fastq screen configuration file
FSCREEN_CONF_FILEPATH = new File(params.fastq_screen_conf).getAbsolutePath()
// modules file
MODULES_FILEPATH = new File(params.modules).getAbsolutePath()
// session parameters
PUBLISHDIR_MODE = params.publish_directory_mode.toLowerCase()
PUBLISHDIR_OVERWRITE = params.publish_directory_overwrite ? true : false
// r script path
R_SCRIPT_FILEPATH = new File(params.r_script).getAbsolutePath()
// multiqc config file
if (params.multiqc_config) {
MULTIQC_CONFIG_FILEPATH =
new File(params.multiqc_config).getAbsolutePath()
} else {
MULTIQC_CONFIG_FILEPATH = ""
}
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- MODULES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// the default modules
def MODULE_BAMTOOLS_DEFAULT = "BamTools/2.4.0-foss-2016b"
def MODULE_CUTADAPT_DEFAULT = "cutadapt/1.9.1-foss-2016b-Python-2.7.12"
def MODULE_FSCREEN_DEFAULT = "fastq_screen/0.9.3-2016a-Perl-5.22.1"
def MODULE_MULTIQC_DEFAULT = "multiqc/1.2-2016b-Python-2.7.12"
def MODULE_PICARD_DEFAULT = "picard/2.1.1-Java-1.8.0_92"
def MODULE_R_DEFAULT = "R/3.4.0-intel-2017a-X11-20170314"
def MODULE_RNASEQC_DEFAULT = "RNA-SeQC/1.1.8-Java-1.7.0_80"
def MODULE_RSEM_DEFAULT = "RSEM/1.3.0-foss-2016b"
def MODULE_RSEQC_DEFAULT = "RSeQC/2.6.4-foss-2016b-Python-2.7.12-R-3.3.1"
def MODULE_SAMTOOLS_DEFAULT = "SAMtools/1.3.1-foss-2016b"
def MODULE_STAR_DEFAULT = "STAR/2.5.2a-foss-2016b"
// the modules file
Yaml parser = new Yaml()
def yml = parser.load((MODULES_FILEPATH as File).text)
// get the modules if they are specified
MODULE_BAMTOOLS = yml["bamtools"] ? yml["bamtools"] : MODULE_BAMTOOLS_DEFAULT
MODULE_CUTADAPT = yml["cutadapt"] ? yml["cutadapt"] : MODULE_CUTADAPT_DEFAULT
MODULE_FSCREEN = yml["fscreen"] ? yml["fscreen"] : MODULE_FSCREEN_DEFAULT
MODULE_MULTIQC = yml["multiqc"] ? yml["multiqc"] : MODULE_MULTIQC_DEFAULT
MODULE_PICARD = yml["picard"] ? yml["picard"] : MODULE_PICARD_DEFAULT
MODULE_R = yml["r"] ? yml["r"] : MODULE_R_DEFAULT
MODULE_RNASEQC = yml["rnaseqc"] ? yml["rnaseqc"] : MODULE_RNASEQC_DEFAULT
MODULE_RSEM = yml["rsem"] ? yml["rsem"] : MODULE_RSEM_DEFAULT
MODULE_RSEQC = yml["rseqc"] ? yml["rseqc"] : MODULE_RSEQC_DEFAULT
MODULE_SAMTOOLS = yml["samtools"] ? yml["samtools"] : MODULE_SAMTOOLS_DEFAULT
MODULE_STAR = yml["star"] ? yml["star"] : MODULE_STAR_DEFAULT
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- READ LENGTH -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// three babs star indices have been built with these read length parameters
def starIndexReadLengths = [50, 75, 100]
// take the index with the closest read length to the experiment's
def diffs = []
starIndexReadLengths.each() { length ->
diff = (length - READ_LENGTH).abs()
diffs.add(diff)
}
def index = diffs.findIndexValues() { i -> i == diffs.min() }[0]
def ROUGH_READ_LENGTH = starIndexReadLengths[index.toInteger()]
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- EXPERIMENTAL VARIABLES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// the species
def BINOMIAL = GENUS.capitalize() + " " + SPECIES
def BINOMIAL_DIRNAME = BINOMIAL.replace(" ", "_").toLowerCase()
def BINOMIAL_FILENAME = BINOMIAL.replace(" ", "_")
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- OUTPUT DIRECTORIES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// the annotation
def GENOME_DIRNAME = "release-" + GENOME_RELEASE
def ROUGH_READ_LENGTH_DIRNAME = ROUGH_READ_LENGTH + "bp"
// the babs directories
def BABS_WORKING_DIRPATH = "/camp/stp/babs/working"
// the subdirectories names
def ALIGNMENT_DIRNAME = "alignment"
def ANALYSIS_DIRNAME = "analysis"
def OUTPUT_DIRNAME = "output"
def LOG_DIRNAME = "log"
// the subsubdirectories names (alignment)
def CUTADAPT_DIRNAME = "cutadapt"
def FSCREEN_DIRNAME = "fastq_screen"
def RSEM_DIRNAME = "rsem"
def STAR_DIRNAME = "star"
def STAR_MBSCREEN_DIRNAME = "mbscreen"
def PICARD_DIRNAME = "picard"
def RSEQC_DIRNAME = "rseqc"
def RNASEQC_DIRNAME = "rnaseqc"
// -- ######################## -- //
// -- the subdirectories paths -- //
// -- ######################## -- //
def CUTADAPT_DIRPATH = Paths.get(OUTPUT_DIRPATH, CUTADAPT_DIRNAME).toString()
def FSCREEN_DIRPATH = Paths.get(OUTPUT_DIRPATH, FSCREEN_DIRNAME).toString()
def STAR_DIRPATH = Paths.get(OUTPUT_DIRPATH, STAR_DIRNAME).toString()
def STAR_MBSCREEN_DIRPATH = Paths.get(OUTPUT_DIRPATH,
STAR_MBSCREEN_DIRNAME).toString()
def PICARD_DIRPATH = Paths.get(OUTPUT_DIRPATH, PICARD_DIRNAME).toString()
def RSEQC_DIRPATH = Paths.get(OUTPUT_DIRPATH, RSEQC_DIRNAME).toString()
def RNASEQC_DIRPATH = Paths.get(OUTPUT_DIRPATH, RNASEQC_DIRNAME).toString()
def ANALYSIS_DIRPATH = Paths.get(OUTPUT_DIRPATH, ANALYSIS_DIRNAME).toString()
def LOG_DIRPATH = Paths.get(OUTPUT_DIRPATH, LOG_DIRNAME).toString()
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- BABS COMMON FILES PATHS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// annotation
def ANNOT_EXTENSION = "gtf"
def ANNOT_BASENAME =
BINOMIAL_FILENAME + "." + GENOME_VERSION + "." + GENOME_RELEASE
// sequence
def SEQ_BASENAME = BINOMIAL_FILENAME + "." + GENOME_VERSION
// directory names
def BABS_DATA_DIRNAME = "data"
def BABS_GENOME_DIRNAME = "genomes"
def INDICE_DIRNAME = "genome_idx"
def ANNOT_DIRNAME = ANNOT_EXTENSION
def RSEM_STAR_MBIOL_DIRNAME = "molecular_biology"
def RSEM_STAR_MBIOL_INDICE_DIRNAME = "all.idx"
def SEQ_DIRNAME = "genome"
// indice names
def RSEM_STAR_INDICE_NAME = "genome"
def RSEM_STAR_MBSCREEN_INDICE_NAME = "molecular_biology.all"
/////////////////////
// directory paths //
/////////////////////
// the babs shared data directory path
def BABS_DATA_DIRPATH =
Paths.get(BABS_WORKING_DIRPATH, BABS_DATA_DIRNAME).toString()
// the babs genomes directory path
def BABS_GENOME_DIRPATH =
Paths.get(BABS_DATA_DIRPATH, BABS_GENOME_DIRNAME).toString()
// the directory path containing the annotation files for this experiment
def GENOME_DIRPATH =
Paths.get(
BABS_GENOME_DIRPATH, BINOMIAL_DIRNAME,
GENOME_TYPE, GENOME_VERSION,
GENOME_DIRNAME
).toString()
def ANNOT_DIRPATH = Paths.get(GENOME_DIRPATH, ANNOT_DIRNAME).toString()
def INDICE_DIRPATH = Paths.get(GENOME_DIRPATH, INDICE_DIRNAME).toString()
// the indice file for the alignment with star
def RSEM_STAR_INDICE_DIRPATH =
Paths.get(
INDICE_DIRPATH, RSEM_DIRNAME,
STAR_DIRNAME,
ROUGH_READ_LENGTH_DIRNAME
).toString()
// the indice file for the molecular biology alignment with star
def RSEM_STAR_MBSCREEN_INDICE_DIRPATH =
Paths.get(
BABS_GENOME_DIRPATH,
RSEM_STAR_MBIOL_DIRNAME,
RSEM_STAR_MBIOL_INDICE_DIRNAME,
RSEM_DIRNAME, STAR_DIRNAME,
ROUGH_READ_LENGTH_DIRNAME
).toString()
////////////////
// file names //
////////////////
def ANNOT_FILENAME = ANNOT_BASENAME + "." + ANNOT_EXTENSION
def ANNOT_RNASEQC_FILENAME = ANNOT_BASENAME + ".rnaseqc." + ANNOT_EXTENSION
def ANNOT_BED_FILENAME = ANNOT_BASENAME + ".bed"
def ANNOT_REFFLAT_FILENAME = ANNOT_BASENAME + ".refflat"
def ANNOT_RRNA_FILENAME = ANNOT_BASENAME + ".rRNA.list"
def ANNOT_RRNA_INTERVAL_FILENAME = ANNOT_BASENAME + ".rRNA.interval_list"
// i don't know if this nomenclature can be unified...
// mouse, human --> "primary_assembly.fa"
// yeast, fly --> "toplevel.fa"
def SEQ_FILENAME = SEQ_BASENAME + ".dna_sm." + GENOME_SEQ_EXTENSION
////////////////
// file paths //
////////////////
def ANNOT_FILEPATH = Paths.get(ANNOT_DIRPATH, ANNOT_FILENAME).toString()
def ANNOT_RNASEQC_FILEPATH =
Paths.get(ANNOT_DIRPATH, ANNOT_RNASEQC_FILENAME).toString()
def ANNOT_REFFLAT_FILEPATH =
Paths.get(ANNOT_DIRPATH, ANNOT_REFFLAT_FILENAME).toString()
def ANNOT_BED_FILEPATH =
Paths.get(ANNOT_DIRPATH, ANNOT_BED_FILENAME).toString()
def ANNOT_RRNA_FILEPATH =
Paths.get(ANNOT_DIRPATH, ANNOT_RRNA_FILENAME).toString()
def ANNOT_RRNA_INTERVAL_FILEPATH =
Paths.get(ANNOT_DIRPATH, ANNOT_RRNA_INTERVAL_FILENAME).toString()
def SEQ_FILEPATH =
Paths.get(GENOME_DIRPATH, SEQ_DIRNAME, SEQ_FILENAME).toString()
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- OUTPUT DIRECTORIES CREATION -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// the folder that contains the cutadapt output
File cutadapt_dir = createDirPathFromString(CUTADAPT_DIRPATH)
// the folder that contains the fastq screen output
File fscreen_dir = createDirPathFromString(FSCREEN_DIRPATH)
// the folder that contains the star output
File star_dir = createDirPathFromString(STAR_DIRPATH)
// the folder that contains the star output
File star_mbscreen_dir = createDirPathFromString(STAR_MBSCREEN_DIRPATH)
// the directory that contains picard's output
File picard_dir = createDirPathFromString(PICARD_DIRPATH)
// the directory that contains picard's output
File rseqc_dir = createDirPathFromString(RSEQC_DIRPATH)
// the directory that contains picard's output
File rnaseqc_dir = createDirPathFromString(RNASEQC_DIRPATH)
// the directory that contains logs
File analysis_dir = createDirPathFromString(ANALYSIS_DIRPATH)
// the directory that contains logs
File log_dir = createDirPathFromString(LOG_DIRPATH)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- THE INPUT CHANNEL -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// the information columns of the design file
def single_end_columns = ["file","sample"]
def paired_end_columns = ["file1","file2","sample"]
def info_columns = SINGLE_END ? single_end_columns : paired_end_columns
// is the design file OK ?
def conform_design_file =
check_design_file(
DESIGN_FILEPATH,
single_end_columns,
paired_end_columns,
SINGLE_END
)
// the information about each sample
def samples_info = get_samples_info(DESIGN_FILEPATH, ",", info_columns)
/* ============================================================= */
/* === is the path of the fastq files absolute or relative ? === */
// get the first file path as a representative
def file_columns = SINGLE_END ? ["file"] : ["file1", "file2"]
def first_filepath = samples_info[0][ file_columns[0] ]
// build the absolute path if it's necessary
if ( ! first_filepath.startsWith("/") ) {
samples_info.each { sample ->
file_columns.each { file_col ->
sample[file_col] = new File(sample[file_col]).getAbsolutePath()
}
}
}
/* ============================================================= */
// create a channel from the samples
samples = Channel.from(samples_info)
// files for dgea
r_script = Channel.fromPath(R_SCRIPT_FILEPATH)
design_file = Channel.fromPath(DESIGN_FILEPATH)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- CUTADAPT -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process cutadapt {
// custom label
tag { name }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_CUTADAPT
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir cutadapt_dir.toString(),
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
val sample from samples
output:
set val(name), file('*.cutadapt.fastq.gz') into trimmed_fastq
set val(name), file('*.log') into cutadapt_log
////////////////////////////////////////////////////////////////////////////
shell:
if (SINGLE_END) {
// name and location
name = sample["sample"]
fastq = sample["file"]
"""
cutadapt \
-a AGATCGGAAGAGC \
-o ${name}.cutadapt.fastq.gz \
-e 0.1 \
-q 10 \
-m 25 \
-O 1 \
${fastq} > ${name}.log
"""
} else {
// name and location
name = sample["sample"]
name_1 = sample["sample"] + "_1"
name_2 = sample["sample"] + "_2"
fastq_1 = sample["file1"]
fastq_2 = sample["file2"]
"""
cutadapt \
-a AGATCGGAAGAGC -A AGATCGGAAGAGC \
-o ${name_1}.cutadapt.fastq.gz \
-p ${name_2}.cutadapt.fastq.gz \
-e 0.1 \
-q 10 \
-m 25 \
-O 1 \
${fastq_1} ${fastq_2} > ${name}.log
"""
}
}
// the fastq files
trimmed_fastq_star = Channel.create()
trimmed_fastq_star_mbscreen = Channel.create()
trimmed_fastq_screen = Channel.create()
trimmed_fastq.into(
trimmed_fastq_star,
trimmed_fastq_star_mbscreen,
trimmed_fastq_screen
)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- FASTQ SCREEN -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process fastq_screen {
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_FSCREEN
// HPC
cpus 32
executor "slurm"
memory "6000"
// output directory
publishDir fscreen_dir.toString(),
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(fastq) from trimmed_fastq_screen
output:
set val(sample), file("*.html") into fastq_screen_html
set val(sample), file("*.txt") into fastq_screen_txt
shell:
"""
fastq_screen \
--force \
--outdir ./ \
--subset 200000 \
--conf ${FSCREEN_CONF_FILEPATH} \
--threads ${task.cpus} \
--aligner bowtie2 \
${fastq}
"""
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- STAR -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process rsem_star {
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_RSEM
module MODULE_STAR
// HPC
cpus 32
executor "slurm"
memory "6000"
// output directory
publishDir star_dir.toString(),
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(fastq) from trimmed_fastq_star
output:
set val(sample), file("*.STAR.genome.bam") into bam_star
set val(sample), file("*.transcript.bam") into transcript_bam_star
set val(sample), file("*.results") into star_results
set val(sample), file("*.stat") into star_stat
////////////////////////////////////////////////////////////////////////////
//--temporary-folder ${star_tmp_dir.toString()} \
//--calc-ci \
//--ci-memory 10240 \
shell:
if (SINGLE_END) {
"""
rsem-calculate-expression \
--temporary-folder "tmp" \
--star \
--num-threads ${task.cpus} \
--strandedness ${STRANDEDNESS} \
--estimate-rspd \
--seed 1 \
--star-output-genome-bam \
--star-gzipped-read-file \
${fastq} \
${RSEM_STAR_INDICE_DIRPATH}/${RSEM_STAR_INDICE_NAME} \
${sample}
"""
} else {
"""
rsem-calculate-expression \
--temporary-folder "tmp" \
--star \
--num-threads ${task.cpus} \
--strandedness ${STRANDEDNESS} \
--estimate-rspd \
--seed 1 \
--star-output-genome-bam \
--star-gzipped-read-file \
--paired-end ${fastq[0]} ${fastq[1]} \
${RSEM_STAR_INDICE_DIRPATH}/${RSEM_STAR_INDICE_NAME} \
${sample}
"""
}
}
// fork for multiqc
bam_star_sort = Channel.create()
bam_star_multiqc = Channel.create()
bam_star.into(bam_star_sort, bam_star_multiqc)
// fork for multiqc
star_results_dgea = Channel.create()
star_results_multiqc = Channel.create()
star_results.into(star_results_dgea, star_results_multiqc)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- DIFFERENTIAL GENE EXPRESSION ANALYSIS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process dgea {
// custom label
tag { script }
// just to be sure as it's still a test version
errorStrategy 'ignore'
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_R
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir analysis_dir.toString(),
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
file script from r_script
file design from design_file
file results from star_results_dgea.map{x->x[1]}.collect()
output:
file "*" into dgea
shell:
"""
Rscript ${script} \
-r . \
-d "${design}" \
-b "${BINOMIAL}" \
-a "${ANNOT_FILEPATH}" \
-t 0.05 \
-o .
"""
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- STAR MBSCREEN -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def star_mbscreen_indice_path = RSEM_STAR_MBSCREEN_INDICE_DIRPATH +
"/" + RSEM_STAR_MBSCREEN_INDICE_NAME
process rsem_star_mbscreen {
/* WARNING!
* This process tries to align the reads on a molecular biology contaminants
* database, so it can fail sometimes.
*/
errorStrategy 'ignore'
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_RSEM
module MODULE_STAR
// HPC
cpus 32
executor "slurm"
memory "6000"
// output directory
publishDir star_mbscreen_dir.toString(),
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(fastq) from trimmed_fastq_star_mbscreen
output:
set val(sample), file("*.STAR.genome.bam") into bam_star_mbscreen
set val(sample),
file("*.transcript.bam") into transcript_bam_star_mbscreen
set val(sample), file("*.results") into results_star_mbscreen
set val(sample), file("*.stat") into stat_star_mbscreen
////////////////////////////////////////////////////////////////////////////
shell:
if (SINGLE_END) {
"""
rsem-calculate-expression \
--temporary-folder "tmp" \
--star \
--num-threads ${task.cpus} \
--strandedness ${STRANDEDNESS} \
--seed 1 \
--star-gzipped-read-file \
--no-bam-output \
${fastq} \