-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·2683 lines (2067 loc) · 59.3 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
/*
*/
// groovy modules
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
// the java modules
import java.nio.file.Paths
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- FUNCTIONS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
/* ------------------ */
def is_single_end(dir) {
// fastq files
def files = []
new File(dir).eachFile() { files << it }
// one or two tags in the filenames ?
def paths = files.collect{ it.toString() }.sort()
def tags = paths.collect{
it.replaceAll(".*_(R\\d)_\\d{3}.fastq.gz", "\$1")
}.unique().sort()
single_end = tags.size() == 2 ? false : true
return single_end
}
/* ---------------------------------- */
def get_rough_read_length(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.toInteger()).abs()
diffs.add(diff)
}
def index = diffs.findIndexValues() { i -> i == diffs.min() }[0]
def rough_read_length = starIndexReadLengths[index.toInteger()]
return rough_read_length
}
/* ----------------------------------------------------------- */
def get_path(species, filetype, genome_dirpath=GENOME_DIRPATH) {
def binomial = species.toLowerCase().tokenize(" ")
if ( binomial[0] == "homo" & binomial[1] == "sapiens" ) {
annot = HUMAN_ANNOT
} else if ( binomial[0] == "mus" & binomial[1] == "musculus" ) {
annot = MOUSE_ANNOT
}
def filename = ""
def directory = ""
if ( filetype.toLowerCase() == "gtf" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".gtf"
} else if ( filetype.toLowerCase() == "fasta" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"genome"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
"dna_sm" +
"." +
annot["fasta_suffix"] +
".fa"
} else if ( filetype.toLowerCase() == "bed" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".bed"
} else if ( filetype.toLowerCase() == "rnaseqc_gtf" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".rnaseqc.gtf"
} else if ( filetype.toLowerCase() == "refflat" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".refflat"
} else if ( filetype.toLowerCase() == "rrna" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".rRNA.list"
} else if ( filetype.toLowerCase() == "rrna_interval" ) {
directory =
Paths.get(
genome_dirpath,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"gtf"
).toString()
filename =
binomial[0].capitalize() +
"_" +
binomial[1] +
"." +
annot["version"] +
"." +
annot["release"] +
".rRNA.interval_list"
}
return Paths.get(directory, filename).toString()
}
/* ----------------------------- */
def get_idx_path(species, length) {
def binomial = species.toLowerCase().tokenize(" ")
if ( binomial[0] == "homo" & binomial[1] == "sapiens" ) {
annot = HUMAN_ANNOT
} else if ( binomial[0] == "mus" & binomial[1] == "musculus" ) {
annot = MOUSE_ANNOT
}
def path =
Paths.get(
GENOME_DIRPATH,
binomial.join("_"),
"ensembl",
annot["version"],
"release-" + annot["release"],
"genome_idx",
"rsem",
"star",
length + "bp",
"genome"
).toString()
return path
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- SCRIPTS PATHS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def CHROM_SCRIPT =
Paths.get(
workflow.projectDir.toString(),
"scripts",
"py",
"reads_per_chrom.py"
)
def QC_GENES_SCRIPT =
Paths.get(
workflow.projectDir.toString(),
"scripts",
"cpp",
"qc_directionality"
)
def TRANSCRIPTS_SCRIPT =
Paths.get(
workflow.projectDir.toString(),
"scripts",
"cpp",
"transcript_directionality"
)
def TXT_DIRPATH =
Paths.get(
workflow.projectDir.toString(),
"scripts",
"qc_genes_list",
"txt"
).toString()
def RRNA = Paths.get(TXT_DIRPATH, "human_rrna_ids.txt")
def MTRRNA = Paths.get(TXT_DIRPATH, "human_mtrrna_ids.txt")
def GLOBIN = Paths.get(TXT_DIRPATH, "human_globin_ids.txt")
def TSS_SCRIPT =
Paths.get(
workflow.projectDir.toString(),
"scripts",
"py",
"tss_coverage.py"
)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- MODULES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def MODULE_ANACONDA = "Anaconda2/5.1.0"
def MODULE_CUTADAPT = "cutadapt/1.9.1-foss-2016b-Python-2.7.12"
def MODULE_FASTQC = "FastQC/0.11.7-Java-1.8.0_162"
def MODULE_FSCREEN = "fastq_screen/0.9.3-2016a-Perl-5.22.1"
def MODULE_GCC = "GCC/6.4.0-2.28"
def MODULE_HTSEQ = "HTSeq/0.6.1p1-foss-2016b-Python-2.7.12"
def MODULE_MULTIQC = "multiqc/1.3-2016b-Python-2.7.12"
def MODULE_PANDAS = "pandas/0.16.2-2016b-Python-2.7.12"
def MODULE_PICARD = "picard/2.1.1-Java-1.8.0_92"
def MODULE_PYTHON = "Python/3.6.3-foss-2017b"
def MODULE_R = "R/3.4.0-intel-2017a-X11-20170314"
def MODULE_RNASEQC = "RNA-SeQC/1.1.8-Java-1.7.0_80"
def MODULE_RSEM = "RSEM/1.3.0-foss-2016b"
def MODULE_RSEQC = "RSeQC/2.6.4-foss-2016b-Python-2.7.12-R-3.3.1"
def MODULE_SAMTOOLS = "SAMtools/1.3.1-foss-2016b"
def MODULE_SEQTK = "seqtk/1.2-foss-2016b"
def MODULE_STAR = "STAR/2.5.2a-foss-2016b"
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- CONFIGURATION FILES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def FSCREEN_CONF_FILEPATH =
Paths.get(workflow.projectDir.toString(),
"conf",
"fastq_screen.conf"
).toString()
def MULTIQC_CONF_FILEPATH =
Paths.get(workflow.projectDir.toString(),
"multiqc",
"conf.yml"
).toString()
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- OUTPUT DIRECTORIES -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def OUTPUT_DIRNAME = "output"
def CHROM_DIRNAME = "chromosome"
def CUTADAPT_DIRNAME = "cutadapt"
def FSCREEN_DIRNAME = "fscreen"
def IDXSTATS_DIRNAME = "idxstats"
def INFO_DIRNAME = "info"
def QC_GENES_DIRNAME = "qc_genes"
def RNASEQC_DIRNAME = "rnaseqc"
def SAMPLING_DIRNAME = "sampling"
def STAR_DIRNAME = "rsem_star"
def STATS_DIRNAME = "stats"
def TRANSCRIPTS_DIRNAME = "transcripts"
def TSS_DIRNAME = "tss"
def FASTQC_DIRNAME = "fastqc"
def FASTQC_RAW_DIRNAME = "raw"
def FASTQC_CUTADAPT_DIRNAME = "cutadapt"
def PICARD_DIRNAME = "picard"
def PICARD_GROUP_DIRNAME = "group"
def PICARD_DUPLICATE_DIRNAME = "duplicate"
def PICARD_COMPLEXITY_DIRNAME = "complexity"
def PICARD_RNASEQMETRICS_DIRNAME = "rnaseqmetrics"
def PICARD_MULTIMETRICS_DIRNAME = "multimetrics"
def RSEQC_DIRNAME = "rseqc"
def RSEQC_INFER_EXPERIMENT_DIRNAME = "infer_experiment"
def RSEQC_JUNCTION_ANNOTATION_DIRNAME = "junction_annotation"
def RSEQC_JUNCTION_SATURATION_DIRNAME = "junction_saturation"
def RSEQC_MISMATCH_PROFILE_DIRNAME = "mismatch_profile"
def RSEQC_READ_DISTRIBUTION_DIRNAME = "read_distribution"
def RSEQC_TRANSCRIPT_INTEGRITY_DIRNAME = "transcript_integrity"
def OUTPUT_DIRPATH =
Paths.get(workflow.projectDir.toString(), OUTPUT_DIRNAME).toString()
def CHROM_DIRPATH = Paths.get(OUTPUT_DIRPATH, CHROM_DIRNAME).toString()
def CUTADAPT_DIRPATH = Paths.get(OUTPUT_DIRPATH, CUTADAPT_DIRNAME).toString()
def FSCREEN_DIRPATH = Paths.get(OUTPUT_DIRPATH, FSCREEN_DIRNAME).toString()
def IDXSTATS_DIRPATH = Paths.get(OUTPUT_DIRPATH, IDXSTATS_DIRNAME).toString()
def INFO_DIRPATH = Paths.get(OUTPUT_DIRPATH, INFO_DIRNAME).toString()
def QC_GENES_DIRPATH = Paths.get(OUTPUT_DIRPATH, QC_GENES_DIRNAME).toString()
def RNASEQC_DIRPATH = Paths.get(OUTPUT_DIRPATH, RNASEQC_DIRNAME).toString()
def SAMPLING_DIRPATH = Paths.get(OUTPUT_DIRPATH, SAMPLING_DIRNAME).toString()
def STAR_DIRPATH = Paths.get(OUTPUT_DIRPATH, STAR_DIRNAME).toString()
def STATS_DIRPATH = Paths.get(OUTPUT_DIRPATH, STATS_DIRNAME).toString()
def TRANSCRIPTS_DIRPATH =
Paths.get(OUTPUT_DIRPATH, TRANSCRIPTS_DIRNAME).toString()
def TSS_DIRPATH = Paths.get(OUTPUT_DIRPATH, TSS_DIRNAME).toString()
def FASTQC_DIRPATH = Paths.get(OUTPUT_DIRPATH, FASTQC_DIRNAME).toString()
def FASTQC_RAW_DIRPATH =
Paths.get(FASTQC_DIRPATH, FASTQC_RAW_DIRNAME).toString()
def FASTQC_CUTADAPT_DIRPATH =
Paths.get(FASTQC_DIRPATH, FASTQC_CUTADAPT_DIRNAME).toString()
def PICARD_DIRPATH = Paths.get(OUTPUT_DIRPATH, PICARD_DIRNAME).toString()
def PICARD_GROUP_DIRPATH =
Paths.get(PICARD_DIRPATH, PICARD_GROUP_DIRNAME).toString()
def PICARD_DUPLICATE_DIRPATH =
Paths.get(PICARD_DIRPATH, PICARD_DUPLICATE_DIRNAME).toString()
def PICARD_COMPLEXITY_DIRPATH =
Paths.get(PICARD_DIRPATH, PICARD_COMPLEXITY_DIRNAME).toString()
def PICARD_RNASEQMETRICS_DIRPATH =
Paths.get(PICARD_DIRPATH, PICARD_RNASEQMETRICS_DIRNAME).toString()
def PICARD_MULTIMETRICS_DIRPATH =
Paths.get(PICARD_DIRPATH, PICARD_MULTIMETRICS_DIRNAME).toString()
def RSEQC_DIRPATH = Paths.get(OUTPUT_DIRPATH, RSEQC_DIRNAME).toString()
def RSEQC_INFER_EXPERIMENT_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_INFER_EXPERIMENT_DIRNAME).toString()
def RSEQC_JUNCTION_ANNOTATION_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_JUNCTION_ANNOTATION_DIRNAME).toString()
def RSEQC_JUNCTION_SATURATION_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_JUNCTION_SATURATION_DIRNAME).toString()
def RSEQC_MISMATCH_PROFILE_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_MISMATCH_PROFILE_DIRNAME).toString()
def RSEQC_READ_DISTRIBUTION_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_READ_DISTRIBUTION_DIRNAME).toString()
def RSEQC_TRANSCRIPT_INTEGRITY_DIRPATH =
Paths.get(RSEQC_DIRPATH, RSEQC_TRANSCRIPT_INTEGRITY_DIRNAME).toString()
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- PARAMETERS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def SPECIES = params.species
def STRANDEDNESS = params.strandedness
def DIRECTORY = params.directory
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- VARIOUS SETTINGS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// be careful, no def because it's a global variable
GENOME_DIRPATH = "/camp/stp/babs/working/data/genomes"
def ANACONDA_ENV = "/camp/stp/babs/working/software/anaconda/envs/qc_pipeline"
def PUBLISHDIR_MODE = "copy"
def PUBLISHDIR_OVERWRITE = true
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- SPECIES ANNOTATIONS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// be careful, no def because it's a global variable
HUMAN_ANNOT = [:]
HUMAN_ANNOT["version"] = "GRCh38"
HUMAN_ANNOT["release"] = "86"
HUMAN_ANNOT["fasta_suffix"] = "primary_assembly"
// be careful, no def because it's a global variable
MOUSE_ANNOT = [:]
MOUSE_ANNOT["version"] = "GRCm38"
MOUSE_ANNOT["release"] = "86"
MOUSE_ANNOT["fasta_suffix"] = "primary_assembly"
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- IS SINGLE-END ? -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def SINGLE_END = is_single_end(DIRECTORY)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- THE INPUT CHANNELS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// transmit to read length determination and to fastqc
Channel
.fromPath( DIRECTORY + "/*.fastq.gz" )
.into{
read_length_fastq;
fastqc_fastq
}
if (SINGLE_END) {
samples =
Channel
.fromPath( DIRECTORY + "/*.fastq.gz" )
.map{[
"name":it.toString().replaceAll(".*\\/(.*)\\.fastq.gz", "\$1"),
"file": it
]}
} else {
samples =
Channel
.fromFilePairs( DIRECTORY + "/*_R{1,2}_*.fastq.gz" )
.map{[
"name":it[0]
.toString()
.replaceAll(".*\\/(.*)_R\\d_\\d{3}\\.fastq.gz", "\$1"),
"file1": it[1][0], "file2": it[1][1]
]}
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- READ LENGTH -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
// get read length from fastq files
process fastq_read_length {
// custom label
tag { fastq }
// problem with slurm otherwise
beforeScript "module purge"
// HPC
cpus 1
executor "local"
memory "1000"
input:
file(fastq) from read_length_fastq
output:
file "*.read_length" into fastq_read_length
shell:
"""
zcat ${fastq} \
| head -n 16 \
| sed -n "2~4p" \
| awk '{ print length }' \
| sort \
| uniq \
| sed -n "1p" \
> ${fastq}.read_length
"""
}
// the mean of read lengths for all fastq files
process read_length {
// custom label
tag { lengths }
// problem with slurm otherwise
beforeScript "module purge"
// HPC
cpus 1
executor "local"
memory "1000"
// output directory
publishDir INFO_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
file(lengths) from fastq_read_length.collect()
output:
file("read_length.txt") into read_length
shell:
"""
N=\$(ls ${lengths} | wc -l)
cat ${lengths} \
| tr "\n" "+" \
| sed 's/+\$//' \
| awk -v N="\$N" '{ print "scale=0;(" \$0 ")/" N }' \
| bc \
> read_length.txt
"""
}
// get read length from the file
read_length.splitText().set{ read_length }
READ_LENGTH = read_length.collect().get().getAt(0)
ROUGH_READ_LENGTH = get_rough_read_length(READ_LENGTH)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- ANNOTATION FILE PATHS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
def ANNOT_GTF_FILEPATH = get_path(SPECIES, "gtf")
def SEQ_FILEPATH = get_path(SPECIES, "fasta")
def ANNOT_BED_FILEPATH = get_path(SPECIES, "bed")
def ANNOT_RNASEQC_FILEPATH = get_path(SPECIES, "rnaseqc_gtf")
def ANNOT_REFFLAT_FILEPATH = get_path(SPECIES, "refflat")
def ANNOT_RRNA_FILEPATH = get_path(SPECIES, "rrna")
def ANNOT_RRNA_INTERVAL_FILEPATH = get_path(SPECIES, "rrna_interval")
RSEM_STAR_INDICE_PREFIX_FILEPATH = get_idx_path(SPECIES, ROUGH_READ_LENGTH)
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- FASTQC -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process fastqc {
// custom label
tag { name }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_FASTQC
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir FASTQC_RAW_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
file fastq from fastqc_fastq
output:
file "*fastqc*" into fastqc
shell:
name = fastq.toString().replaceFirst(".fastq.gz", "")
"""
fastqc ${fastq}
"""
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- 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_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
val sample from samples
output:
set val(name), file('*.log') into cutadapt_log
set val(name), file('*.cutadapt.fastq.gz') \
into \
cutadapt_sampling,
cutadapt_star,
cutadapt_fscreen,
cutadapt_fastqc,
cutadapt_multiqc
////////////////////////////////////////////////////////////////////////////
shell:
// sample name
name = sample["name"]
if (SINGLE_END) {
// locations
fastq = sample["file"]
// command arguments
adapters = "-a AGATCGGAAGAGC"
input = "-o " + name + ".cutadapt.fastq.gz"
output = fastq
} else {
// locations
name_1 = sample["name"] + "_1.cutadapt.fastq.gz"
name_2 = sample["name"] + "_2.cutadapt.fastq.gz"
fastq_1 = sample["file1"]
fastq_2 = sample["file2"]
// command arguments
adapters = "-a AGATCGGAAGAGC -A AGATCGGAAGAGC"
input = "-o " + name_1 + " -p " + name_2
output = fastq_1 + " " + fastq_2
}
"""
cutadapt \
${adapters} \
${input} \
-e 0.1 \
-q 10 \
-m 25 \
-O 1 \
${output} > ${name}.log
"""
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- FASTQC CUTADAPT -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process fastqc_cutadapt {
// custom label
tag { name }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_FASTQC
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir FASTQC_CUTADAPT_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(name), file(fastq) from cutadapt_fastqc
output:
file "*fastqc*" into fastqc_cutadapt
shell:
name = fastq.toString().replaceFirst(".fastq.gz", "")
"""
fastqc ${fastq}
"""
}
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- SAMPLING -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
process sampling {
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_SEQTK
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir SAMPLING_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(fastq) from cutadapt_sampling
output:
set val(sample), file("*.fastq.gz") into sampling, sampling_multiqc
shell:
n = 1000
if (SINGLE_END) {
name = fastq.toString().replaceFirst(".fastq.gz", "")
"""
seqtk sample ${fastq} ${n} | gzip -c > ${name}.sampled.fastq.gz
"""
} else {
name = fastq.collect { it.toString().replaceFirst(".fastq.gz", "") }
"""
seqtk sample -s1903 ${fastq[0]} ${n} \
| gzip -c > ${name[0]}.sampled.fastq.gz
seqtk sample -s1903 ${fastq[1]} ${n} \
| gzip -c > ${name[1]}.sampled.fastq.gz
"""
}
}
process sampled_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 SAMPLING_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(fastq) from sampling
output:
set val(sample), file("*.STAR.genome.bam") \
into \
sampled_bam,
sampled_bam_multiqc
shell:
if (SINGLE_END) {
input = fastq
} else {
input = "--paired-end " + fastq[0] + " " + fastq[1]
}
"""
rsem-calculate-expression \
--temporary-folder "tmp" \
--star \
--num-threads ${task.cpus} \
--strandedness ${STRANDEDNESS} \
--estimate-rspd \
--seed 1 \
--output-genome-bam \
--star-output-genome-bam \
--star-gzipped-read-file \
${input} \
${RSEM_STAR_INDICE_PREFIX_FILEPATH} \
${sample}
"""
}
process sampled_sort {
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_SAMTOOLS
// HPC
cpus 32
executor "slurm"
memory "6000"
// output directory
publishDir SAMPLING_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(bam) from sampled_bam
output:
set val(sample), file("*.bam"), file("*.bai") \
into \
sampled_sorted_bam,
sampled_sorted_bam_multiqc
shell:
filename = sample + ".sorted.bam"
"""
samtools sort \
--threads ${task.cpus} \
-o ${filename} \
${bam}
samtools index ${filename}
"""
}
process sampled_picard_group {
// custom label
tag { sample }
// problem with slurm otherwise
beforeScript "module purge"
// modules
module MODULE_PICARD
// HPC
cpus 1
executor "slurm"
memory "6000"
// output directory
publishDir SAMPLING_DIRPATH,
mode: PUBLISHDIR_MODE,
overwrite: PUBLISHDIR_OVERWRITE
input:
set val(sample), file(bam), file(bai) from sampled_sorted_bam
output:
set val(sample), file("*.bam") \
into \
sampled_picard_rg,
sampled_picard_rg_multiqc
shell:
tmp_dirname = "tmp"
filename = sample + ".rg.bam"
"""