-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.nf
1936 lines (1500 loc) · 67.6 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
/*
========================================================================================
circPipe
========================================================================================
* circPipe was implemented by Dr. Qi Zhao and Qijin Wei from Sun Yat-sen University Cancer Center.
* Homepage / Documentation
https://github.com/likelet/circpipe
*/
/*
* to be added
*
* Authors:
* Qi Zhao <[email protected]>: design and implement the pipeline.
* Wei qijin
*/
def helpMessage() {
log.info "INFO "+"""
=========================================
CircPipe v${workflow.manifest.version}
=========================================
Usage:
The typical command for running the pipeline is as follows:
nextflow path/to/circPipe/main.nf --reads "path/to/*{1,2}.fq.gz" -profile standard,docker
Mandatory arguments:
--reads Path to input data (must be surrounded with quotes)
--designfile A txt file that stored experimental design information
--comparefile A txt file that stored experimental compare information
Configuration:
--genomefile Path to Fasta reference (required if not set in config file)
--gtffile
--annotationfile Different annotation files from GENCODE database for annotating circRNAs.
e.g. [gencode.v25.annotation.gtf]/[gencode.v25.annotation.bed]/[hg38_gencode.txt]
--ciridir/--find_circdir
--mapsdir Home folder of ciri/find_circ/mapsplice installed location
--genomebuild specific genome build for circplot, default 'hg19'; Available 'GRCh38', 'hg10'
Options:
-profile Configuration profile to use. Can use multiple (comma separated)
Available: standard, conda, docker, singularity, test
If not set, the pipeline will create the index itself.
--singleEnd Specify that the reads are single ended
--selectTools Specify which tools should be use.
1 for circexplorer2, 2 for ciri, 3 for find_circ, 4 for mapsplice, 5 for segemehl
For example, you can set 1,2,3,4,5 for running five tools in the same time.
--skipDE skip differential expression analysis
--outdir The output directory of the results
--mRNA Path to the mRNA expression matrix. Only need to be set when you want to do the correlation.
Other options:
--email Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits
-name Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
""".stripIndent()
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help emssage
if (params.help){
helpMessage()
exit 0
}
/*
* Checking the input files
* Build up the output files
* Adding input files error exceptions Here
*/
outdir = file(params.outdir) //the output directory
// check variables
assert params.library == 'rnase' || params.aligner == 'total' : "Invalid library option: ${params.library}. Valid options: 'rnase', 'total'"
/*
========================================================================================
select the analysis tools
========================================================================================
*/
number_of_tools=0
String toolstring = params.selectTools
if( toolstring.indexOf("1")!=-1){
run_circexplorer2 = true
number_of_tools=number_of_tools+1
}else{
run_circexplorer2 = false
Star_multiqc=Channel.empty()
}
if( toolstring.indexOf("2")!=-1){
run_ciri = true
number_of_tools=number_of_tools+1
}else{
run_ciri = false
}
if( toolstring.indexOf("3")!=-1){
run_find_circ = true
number_of_tools=number_of_tools+1
}else{
run_find_circ = false
Bowtie2_multiqc=Channel.empty()
}
if( toolstring.indexOf("4")!=-1){
run_mapsplice = true
number_of_tools=number_of_tools+1
}else{
run_mapsplice = false
}
if( toolstring.indexOf("5")!=-1){
run_segemehl = true
number_of_tools=number_of_tools+1
}else{
run_segemehl = false
}
// jugde wether multiple tools involved
run_multi_tools=false
if(number_of_tools>1){
run_multi_tools=true
}
if(params.mRNA){
mRNAfile = file(params.mRNA) //the mRNA file
if( !mRNAfile.exists() ) exit 1, LikeletUtils.print_red("Missing mRNA expression file: ${params.mRNAfile}")
}
/*
========================================================================================
the reference directory
========================================================================================
*/
if(run_circexplorer2){
annotationfile = file(params.annotationfile) //the annotationfile
if( !annotationfile.exists() ) exit 1, LikeletUtils.print_red("Missing annotation file: ${params.annotationfile}")
}
genomefile = file(params.genomefile) //the genomefile
if( !genomefile.exists() ) exit 1, LikeletUtils.print_red("Missing genome file: ${params.genomefile}")
if(run_mapsplice){
if(params.refmapsplice){
Refmapsplice = Channel.fromPath(params.refmapsplice) //the mapsplice reference genome directory
}else{
process built_refmapsplice_reference_by_split {
storeDir "${params.outdir}/reference_genome/split"
input:
file genomefile
output:
file "split" into Refmapsplice
shell:
"""
mkdir split
perl ${baseDir}/bin/split_fasta_by_chromsome.pl ${genomefile} split
"""
}
}
}else{
Refmapsplice = Channel.fromPath(params.inputdir)
}
faifile = file(params.faifile) //the genomefile
if( !faifile.exists() ) exit 1, LikeletUtils.print_red("Missing genome file index: ${faifile}")
gtffile = file(params.gtffile) //the annotationfile-gtf-format
if( !gtffile.exists() ) exit 1, LikeletUtils.print_red("Missing gtf annotation file: ${gtffile}")
hisat2_index = Channel.fromPath("${params.hisat2_index}*.ht2")
.ifEmpty { exit 1, "HISAT2 index not found: ${params.hisat2_index}" }
/*
========================================================================================
checking the design and compare file
========================================================================================
*/
//design file
if(!params.skipDE){
designfile = file(params.designfile)
if(params.designfile) {
if( !designfile.exists() ) exit 1, LikeletUtils.print_red("Design file not found: ${params.designfile}")
}
//compare file
comparefile = file(params.comparefile)
if(params.comparefile){
if( !comparefile.exists() ) exit 1, LikeletUtils.print_red("Compare file not found: ${params.comparefile}")
}
}else {
// add the sentence avoiding errors by nextflow
designfile=file(params.designfile)
comparefile=file(params.comparefile)
}
/*
========================================================================================
showing the process and files
========================================================================================
*/
log.info "INFO "+LikeletUtils.print_cyan("""
========================================================================
________ _______
| ____ | | ___ |
| | |_| _ | | | | _
| | |_| | | | | |_|
| | _ _ __ _____ | |___| | _ ______ _____
| | | | | |/ / | ___| | _____| | | | __ | | _ |
| | | | | / | | | | | | | | | | | |_| |
| | _ | | | / | | | | | | | | | | | ___|
| |____| | | | | | | |___ | | | | | |__| | | |___
|________| |_| |_| |_____| |_| |_| | ____| |_____|
| |
| |
|_|
=======================================================================
""")
.stripIndent()
log.info "INFO "+LikeletUtils.print_purple("============You are running circpipe with the following parameters===============")
log.info "INFO "+LikeletUtils.print_purple("Checking parameters ...")
log.info "\n"
log.info "INFO "+LikeletUtils.print_yellow("=====================================Reads types================================")
log.info "INFO "+LikeletUtils.print_yellow("SingleEnd : ") + LikeletUtils.print_green(params.singleEnd)
log.info "\n"
log.info "INFO "+LikeletUtils.print_yellow("====================================Tools selected==============================")
log.info "INFO "+LikeletUtils.print_yellow("Circexplorer2 : ") + LikeletUtils.print_green(run_circexplorer2)
log.info "INFO "+LikeletUtils.print_yellow("Find_circ : ") + LikeletUtils.print_green(run_find_circ)
log.info "INFO "+LikeletUtils.print_yellow("Ciri : ") + LikeletUtils.print_green(run_ciri)
log.info "INFO "+LikeletUtils.print_yellow("Mapsplice : ") + LikeletUtils.print_green(run_mapsplice)
log.info "INFO "+LikeletUtils.print_yellow("Segemehl : ") + LikeletUtils.print_green(run_segemehl)
log.info "\n"
log.info "INFO "+LikeletUtils.print_yellow("==================================Input files selected==========================")
log.info "INFO "+LikeletUtils.print_yellow("Reads : ") + LikeletUtils.print_green(params.reads)
log.info "INFO "+LikeletUtils.print_yellow("Annotation file : ") + LikeletUtils.print_green(params.annotationfile)
log.info "INFO "+LikeletUtils.print_yellow("Genome file : ") + LikeletUtils.print_green(params.genomefile)
log.info "INFO "+LikeletUtils.print_yellow("GTF file : ") + LikeletUtils.print_green(params.gtffile)
log.info "\n"
log.info "INFO "+LikeletUtils.print_yellow("==================================Output files directory========================")
log.info "INFO "+LikeletUtils.print_yellow("Output directory : ") + LikeletUtils.print_green(params.outdir)
log.info "INFO "+LikeletUtils.print_yellow("================================== Others ========================")
log.info "INFO "+LikeletUtils.print_yellow("Skip Fastqc : ") + LikeletUtils.print_green(params.skip_fastp)
log.info "INFO "+LikeletUtils.print_yellow("Skip DE analysis : ") + LikeletUtils.print_green(params.skipDE)
log.info "\n"
/*
* Create the `read_pairs` channel that emits tuples containing three elements:
* the pair ID, the first read-pair file and the second read-pair file
*/
Channel
.fromFilePairs( params.reads, size: params.singleEnd ? 1 : 2 )
.ifEmpty { error "Cannot find any reads matching: ${params.reads}" }
.set { Read_pairs_fastp }
log.info "INFO "+LikeletUtils.print_yellow("===================check or build the index===============================")
/*
========================================================================================
check or build the index
========================================================================================
*/
//check star index
if(run_circexplorer2){
if(params.starindex){
starindex = Channel
.fromPath(params.starindex)
.ifEmpty { exit 1, "STAR index not found: ${params.starindex}" }
star_run_index = params.starindex
}else{
log.info "INFO "+LikeletUtils.print_yellow("Seems that you did not provide a STAR index for circexplorer2, circPipe will built it automaticaly. And it may take hours to prepare the reference. So you can go outside and have rest before it finished . ")
process makeSTARindex {
storeDir "${params.outdir}/reference_genome"
input:
file genomefile
file gtffile
output:
file "starindex" into starindex
script:
"""
mkdir starindex
STAR \
--runMode genomeGenerate \
--runThreadN ${task.cpus} \
--sjdbGTFfile ${gtffile} \
--genomeDir starindex/ \
--genomeFastaFiles ${genomefile} \
--sjdbOverhang 149
"""
}
star_run_index = 'starindex'
}
}else{
// avoiding throw errors by nextflow
starindex=Channel.empty()
}
// check bowtie2 index
if(run_find_circ){
if(params.bowtie2index){
(Bowtie2index,Bowtie2index_fc)= Channel
.fromPath(params.bowtie2index+"*.bt2")
.ifEmpty { exit 1, "Bowtie2 index not found: ${params.bowtie2index}, and it required by find_circ"}.into(2)
bowtie2_run_index = params.bowtie2index
}else{
log.info "INFO "+LikeletUtils.print_yellow("Seems that you did not provide a Bowtie2 index for find_circ, circPipe will built it automatically. And it may take hours to prepare the reference. So you can go outside and have rest before it finished . ")
process makeBowtie2index {
storeDir "${params.outdir}/reference_genome"
input:
file genomefile
output:
file "*.bt2" into Bowtie2index, Bowtie2index_fc
script:
"""
bowtie2-build -f ${genomefile} genome
"""
}
bowtie2_run_index = 'genome'
}
}else{
// avoiding throw errors by nextflow
(Bowtie2index,Bowtie2index_fc)=Channel.empty().into(2)
}
// check bowtie index
if(run_mapsplice){
if(params.bowtieindex){
Bowtieindex = Channel
.fromPath(params.bowtieindex+"*.ebwt")
.ifEmpty { exit 1, "Bowtie index not found: ${params.bowtieindex}" }
bowtie_run_index=params.bowtieindex
}else{
log.info "INFO "+LikeletUtils.print_yellow("Seems that you did not provide a Bowtie index for mapsplice, circPipe will built it automatically. And it may take hours to prepare the reference. So you can go outside and have rest before it finished . ")
process makeBowtieindex {
storeDir "${params.outdir}/reference_genome"
input:
file genomefile
output:
file "*.ebwt" into Bowtieindex
script:
"""
bowtie-build ${genomefile} genome
"""
}
bowtie_run_index = "genome"
}
}else{
// avoiding throw errors by nextflow
Bowtieindex=Channel.empty()
}
// check bwa index
if(run_ciri||run_multi_tools){
LikeletUtils.print_yellow("To note that we also utilized the bwa bam file for requantification, we required that all integrated analysis run the bwa mapping step")
if(params.bwaindex){
bwaindex = Channel
.fromPath(params.bwaindex+"*.{ann,amb,pac,bwt,sa}")
.ifEmpty { exit 1, "BWA index not found: ${params.bwaindex}" }
bowtie_run_index = params.bwaindex
}else{
LikeletUtils.print_yellow("Seems that you did not provide a BWA index for ciri, circPipe will built it automatically. And it may take hours to prepare the reference. So you can go outside and have rest before it finished . ")
process makeBWAindex {
storeDir "${params.outdir}/reference_genome"
input:
file genomefile
output:
file "*.{ann,amb,pac,bwt,sa}" into bwaindex
script:
"""
bwa index -p genome ${genomefile}
"""
bowtie_run_index="genome"
}
}
}else{
// avoiding throw errors by nextflow
bwaindex=Channel.empty()
}
// check segemehl index
if(run_segemehl){
if(params.segindex){
Segindex = Channel
.fromPath(params.segindex+"*.idx")
.ifEmpty { exit 1, "Segemehl index not found: ${params.segindex}" }
}else{
LikeletUtils.print_yellow("Seems that you did not provide a segemehl index for runing segemehl, circPipe will built it automatically. And it may take hours to prepare the reference. So you can go outside and have rest before it finished . ")
process makeSegemehlindex {
storeDir "${params.outdir}/reference_genome"
input:
file genomefile
file segdir
output:
file "genome.idx" into Segindex
script:
"""
segemehl.x -d ${genomefile} -x genome.idx
"""
}
}
}else{
// avoiding throw errors by nextflow
Segindex=Channel.empty()
}
log.info "INFO "+LikeletUtils.print_green("==========Index pass!...==========")
log.info "INFO "+LikeletUtils.print_green("==========Start running CircPipe...==========")
/*
========================================================================================
first step : run the fastp (QC tool)
========================================================================================
*/
if(params.skip_fastp){
(Fastpfiles_mapsplice,Fastpfiles_bwa,Fastpfiles_star,Fastpfiles_segemehl,Fastpfiles_bowtie2,Fastpfiles_recount,Fastpfiles_for_sailfish,Fastpfiles_hisat)=Read_pairs_fastp.into(9)
fastp_for_waiting=Channel.empty()
Fastp_for_multiqc=Channel.empty()
}else{
process RUN_FASTP{
tag "$sampleID"
publishDir "${params.outdir}/QC", mode: 'copy', pattern: "*_fastpreport.html", overwrite: true
input:
tuple val(sampleID), file(query_file) from Read_pairs_fastp
output:
tuple val(sampleID), file ('unzip_fastp_*') into (Fastqfor_swhich,Fastpfiles_mapsplice,Fastpfiles_bwa,Fastpfiles_star,Fastpfiles_segemehl,Fastpfiles_bowtie2,Fastpfiles_recount,Fastpfiles_for_sailfish,Fastpfiles_hisat)
file ('*.html') into fastp_for_waiting
file ('*_fastp.json') into Fastp_for_multiqc
script:
if(params.singleEnd){
"""
fastp \
-i ${query_file} \
-o unzip_fastp_${sampleID}.fq \
-h ${sampleID}_fastpreport.html \
-j ${sampleID}_fastp.json
"""
}else{
"""
fastp \
-i ${query_file[0]} \
-I ${query_file[1]} \
-o unzip_fastp_${sampleID}_1.fq \
-O unzip_fastp_${sampleID}_2.fq \
-h ${sampleID}_fastpreport.html \
-j ${sampleID}_fastp.json
"""
}
}
}
fastp_for_waiting = fastp_for_waiting.first() //wait for finish this process first
// $$$$$$\ $$\ $$\ $$$$$$\
// $$ __$$\ \__| $$ | $$ __$$\
// $$ / \__|$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$\ $$\ $$$$$$\ $$ | $$$$$$\ $$$$$$\ $$$$$$\ \__/ $$ |
// $$ | $$ |$$ __$$\ $$ _____|$$ __$$\ \$$\ $$ |$$ __$$\ $$ |$$ __$$\ $$ __$$\ $$ __$$\ $$$$$$ |
// $$ | $$ |$$ | \__|$$ / $$$$$$$$ | \$$$$ / $$ / $$ |$$ |$$ / $$ |$$ | \__|$$$$$$$$ | $$ ____/
// $$ | $$\ $$ |$$ | $$ | $$ ____| $$ $$< $$ | $$ |$$ |$$ | $$ |$$ | $$ ____| $$ |
// \$$$$$$ |$$ |$$ | \$$$$$$$\ \$$$$$$$\ $$ /\$$\ $$$$$$$ |$$ |\$$$$$$ |$$ | \$$$$$$$\ $$$$$$$$\
// \______/ \__|\__| \_______| \_______|\__/ \__|$$ ____/ \__| \______/ \__| \_______| \________|
// $$ |
// $$ |
// \__|
if(run_circexplorer2){
process RUN_STAR{
tag "$sampleID"
publishDir "${params.outdir}/Alignment/STAR", mode: 'link', overwrite: true
input:
tuple val(sampleID), file(query_file) from Fastpfiles_star
file index from starindex.collect()
output:
tuple val(sampleID), file ('*.junction') into starfiles
file ('*.out') into Star_multiqc
shell:
if(params.skip_fastp){
if(params.singleEnd){
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir ${star_run_index} \
--readFilesIn ${query_file} \
--readFilesCommand zcat \
--outFileNamePrefix star_${sampleID}_ \
--outSAMtype None
"""
}else{
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir ${star_run_index} \
--readFilesCommand zcat \
--readFilesIn ${query_file[0]} ${query_file[1]} \
--outFileNamePrefix star_${sampleID}_ \
--outSAMtype None
"""
}
}else{
if(params.singleEnd){
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir ${star_run_index} \
--readFilesIn ${query_file} \
--outFileNamePrefix star_${sampleID}_ \
--outSAMtype None
"""
}else{
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir ${star_run_index} \
--readFilesIn ${query_file[0]} ${query_file[1]} \
--outFileNamePrefix star_${sampleID}_ \
--outSAMtype None
"""
}
}
}
/*
========================================================================================
the first tool : star - circexplorer2
run the circexplorer2
========================================================================================
*/
process RUN_Circexplorer2{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', overwrite: true
input:
tuple val(sampleID), file (query_file) from starfiles
file annotationfile
file genomefile
output:
tuple val(sampleID), file ('*known.txt') into circexplorer2files
script:
"""
CIRCexplorer2 \
parse -t STAR ${query_file} \
> CIRCexplorer2_parse_${sampleID}.log
CIRCexplorer2 \
annotate -r ${annotationfile} \
-g ${genomefile} \
-b back_spliced_junction.bed \
-o CIRCexplorer2_${sampleID}_circularRNA_known.txt \
> CIRCexplorer2_annotate_${sampleID}.log
"""
}
/*
========================================================================================
the first tool : star - circexplorer2
produce the bed6 file
========================================================================================
*/
process RUN_Circexplorer2_Bed{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', pattern: "*candidates.bed", overwrite: true
input:
tuple val(sampleID), file (query_file) from circexplorer2files
output:
file ('*candidates.bed') into Modify_circexplorer2
val (sampleID) into Modify_circexplorer2_id
shell :
'''
if [ $((`cat !{query_file} | wc -l`)) == 0 ];then
touch !{sampleID}_Modify_circexplorer2.candidates.bed
else
grep circ !{query_file} \
| grep -v chrM \
| awk '{print $1 "\t" $2 "\t" $3 "\t" "circexplorer2" "\t" $13 "\t" $6}' \
> !{sampleID}_Modify_circexplorer2.temp.bed
cp !{sampleID}_Modify_circexplorer2.temp.bed circexplorer2_!{sampleID}.candidates.bed
fi
'''
}
/*
========================================================================================
the first tool : star - circexplorer2
produce the matrix
========================================================================================
*/
process RUN_Circexplorer2_Matrix{
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', pattern: "*.matrix", overwrite: true
input:
file (query_file) from Modify_circexplorer2.collect()
file gtffile
output:
file ('circexplorer2_merge.matrix') into (Output_circexplorer2,Plot_circexplorer2,Plot_circexplorer2_cor,Merge_circexplorer2)
file ('Name_circexplorer2.txt') into Name_circexplorer2
shell :
'''
# merge sample into matrix
java -jar !{baseDir}/bin/circpipetools.jar -i candidates.bed -o circexplorer2 -sup 5 -merge
mv circexplorer2_merge.bed circexplorer2_merge.matrix
# remove non samplename string from matrix header
sed -i 's/circexplorer2_//g' circexplorer2_merge.matrix
sed -i 's/.candidates.bed//g' circexplorer2_merge.matrix
echo -e "circexplorer2" > Name_circexplorer2.txt
'''
}
}else{
Merge_circexplorer2=Channel.empty()
Name_circexplorer2=Channel.empty()
}
/*
========================================================================================
the first tool : star - circexplorer2
run the star
========================================================================================
*/
// $$$$$$\ $$\ $$\
// $$ __$$\ \__| \__|
// $$ / \__|$$\ $$$$$$\ $$\
// $$ | $$ |$$ __$$\ $$ |
// $$ | $$ |$$ | \__|$$ |
// $$ | $$\ $$ |$$ | $$ |
// \$$$$$$ |$$ |$$ | $$ |
// \______/ \__|\__| \__|
//
//
//
/*
========================================================================================
the second tool : bwa - ciri
run the bwa
========================================================================================
*/
if(run_ciri){
process BWA_and_CIRI{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/CIRI", pattern: "*.txt",mode: 'copy', overwrite: true
input:
tuple val(sampleID), file (query_file) from Fastpfiles_bwa
file index from bwaindex.collect()
file genomefile
file gtffile
output:
tuple val(sampleID), file ('*.txt') into cirifiles
shell:
if(params.singleEnd){
"""
bwa mem -t ${task.cpus} -T 19 -M -R "@RG\\tID:fastp_${sampleID}\\tPL:PGM\\tLB:noLB\\tSM:fastp_${sampleID}" ${bowtie_run_index} ${query_file[0]} > ${sampleID}.sam
CIRI2.pl \
-T 10 \
-F ${genomefile} \
-A ${gtffile} \
-G CIRI_${sampleID}.log \
-I ${sampleID}.sam \
-O CIRI_${sampleID}.txt \
> CIRI_${sampleID}_detail.log
rm ${sampleID}.sam
"""
}else{
"""
bwa mem -t ${task.cpus} -T 19 -M -R "@RG\\tID:fastp_${sampleID}\\tPL:PGM\\tLB:noLB\\tSM:fastp_${sampleID}" ${bowtie_run_index} ${query_file[0]} ${query_file[1]} > ${sampleID}.sam
CIRI2.pl \
-T 10 \
-F ${genomefile} \
-A ${gtffile} \
-G CIRI_${sampleID}.log \
-I ${sampleID}.sam \
-O CIRI_${sampleID}.txt \
> CIRI_${sampleID}_detail.log
# bwa sam to bam file
rm ${sampleID}.sam
"""
}
}
/*
========================================================================================
the second tool : bwa - ciri
produce the bed6 file
========================================================================================
*/
process CIRI_BED{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/CIRI", mode: 'copy', pattern: "*candidates.bed", overwrite: true
input:
tuple val(sampleID), file (query_file) from cirifiles
output:
file ('*candidates.bed') into Modify_ciri
when:
run_ciri
shell :
'''
# conver to bed file and be cautious that convert 1-based coordinate to 0-based
if [ $((`cat !{query_file} | wc -l`)) == 1 ];then
touch !{sampleID}_modify_ciri.candidates.bed
else
cat !{query_file} \
| sed -e '1d' \
| grep -v chrM \
| awk '{print $2 "\t" $3-1 "\t" $4 "\t" "ciri" "\t" $5 "\t" $11}' \
> !{sampleID}_modify_ciri.temp.bed
cp !{sampleID}_modify_ciri.temp.bed ciri_!{sampleID}.candidates.bed
fi
'''
}
/*
========================================================================================
the second tool : bwa - ciri
produce the matrix
========================================================================================
*/
process CIRI_Matrix{
publishDir "${params.outdir}/circRNA_Identification/CIRI", mode: 'copy', pattern: "*.matrix", overwrite: true
input:
file (query_file) from Modify_ciri.collect()
file gtffile
output:
file ('ciri_merge.matrix') into (Output_ciri,Plot_ciri_cor,Plot_ciri,Merge_ciri)
file ('Name_ciri.txt') into Name_ciri
shell :
'''
# merge sample into matrix
java -jar !{baseDir}/bin/circpipetools.jar -i candidates.bed -o ciri -sup 5 -merge
mv ciri_merge.bed ciri_merge.matrix
# annotate circRNA with GTFs
# java -jar !{baseDir}/bin/circpipetools.jar -i ciri_merge.matrix -o annoted_ -gtf !{gtffile} -uniq
sed -i 's/ciri_//g' ciri_merge.matrix
sed -i 's/.candidates.bed//g' ciri_merge.matrix
#for what
echo -e "ciri" > Name_ciri.txt
'''
}
}else{
Merge_ciri=Channel.empty()
Name_ciri=Channel.empty()
}
// $$\ $$\ $$\ $$\
// $$$\ $$$ | $$ |\__|
// $$$$\ $$$$ | $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$ |$$\ $$$$$$$\ $$$$$$\
// $$\$$\$$ $$ | \____$$\ $$ __$$\ $$ _____|$$ __$$\ $$ |$$ |$$ _____|$$ __$$\
// $$ \$$$ $$ | $$$$$$$ |$$ / $$ |\$$$$$$\ $$ / $$ |$$ |$$ |$$ / $$$$$$$$ |
// $$ |\$ /$$ |$$ __$$ |$$ | $$ | \____$$\ $$ | $$ |$$ |$$ |$$ | $$ ____|
// $$ | \_/ $$ |\$$$$$$$ |$$$$$$$ |$$$$$$$ |$$$$$$$ |$$ |$$ |\$$$$$$$\ \$$$$$$$\
// \__| \__| \_______|$$ ____/ \_______/ $$ ____/ \__|\__| \_______| \_______|
// $$ | $$ |
// $$ | $$ |
// \__| \__|
if(run_mapsplice){
/*
========================================================================================
the third tool : mapsplice
run the mapsplice
========================================================================================
*/
process RUN_Mapsplice{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/Mapsplice", mode: 'copy', overwrite: true
input:
tuple val(sampleID), file (query_file) from Fastpfiles_mapsplice
//tuple val(sampleID), file (query_file) from Fastqraw_mapslice
file gtffile
file refmapsplice_dir from Refmapsplice.collect()
file index from Bowtieindex.collect()
output:
tuple val(sampleID), file('*') into Mapsplicefiles
shell:
if(params.singleEnd){
"""
source activate find_circ
gunzip -c ${query_file} > ${sampleID}.fastq
mapsplice.py \
-p ${task.cpus} \
-k 1 \
--fusion-non-canonical \
--qual-scale phred33 \
--non-canonical-double-anchor \
--min-fusion-distance 200 \
-x ${bowtie_run_index} \
--gene-gtf ${gtffile} \
-c ${refmapsplice_dir} \
-1 ${sampleID}.fastq \
--bam \
-o output_mapsplice_${sampleID}
rm *.fastq
"""
}else{
"""
source activate find_circ
gunzip -c ${query_file[0]} > ${sampleID}_1.fastq
gunzip -c ${query_file[1]} > ${sampleID}_2.fastq
mapsplice.py \
-p ${task.cpus} \
-k 1 \
--fusion-non-canonical \
--non-canonical-double-anchor \
--min-fusion-distance 200 \
-x ${bowtie_run_index} \
--gene-gtf ${gtffile} \
-c ${refmapsplice_dir} \
-1 ${sampleID}_1.fastq \
-2 ${sampleID}_2.fastq \
--bam \
-o output_mapsplice_${sampleID}
rm *.fastq
"""
}
}
/*
========================================================================================
the third tool : mapsplice
produce the bed6 file
========================================================================================
*/
process RUN_Mapsplice_Bed{
tag "$sampleID"
publishDir "${params.outdir}/circRNA_Identification/Mapsplice", mode: 'copy', pattern: "*candidates.bed", overwrite: true
input:
tuple val(sampleID), file (query_file) from Mapsplicefiles
file outdir
output:
file ('*candidates.bed') into Modify_mapsplice
shell :
'''
if [ $((`cat output_mapsplice_!{sampleID}/circular_RNAs.txt | wc -l`)) == 0 ];then
touch !{sampleID}_modify_mapsplice.candidates.bed
else
cat output_mapsplice_!{sampleID}/circular_RNAs.txt \