forked from likelet/circPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
2314 lines (1900 loc) · 72.2 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
*/
println(PATH)
//pre-defined functions for render command
//=======================================================================================
ANSI_RESET = "\u001B[0m";
ANSI_BLACK = "\u001B[30m";
ANSI_RED = "\u001B[31m";
ANSI_GREEN = "\u001B[32m";
ANSI_YELLOW = "\u001B[33m";
ANSI_BLUE = "\u001B[34m";
ANSI_PURPLE = "\u001B[35m";
ANSI_CYAN = "\u001B[36m";
ANSI_WHITE = "\u001B[37m";
def print_red = { str -> ANSI_RED + str + ANSI_RESET }
def print_black = { str -> ANSI_BLACK + str + ANSI_RESET }
def print_green = { str -> ANSI_GREEN + str + ANSI_RESET }
def print_yellow = { str -> ANSI_YELLOW + str + ANSI_RESET }
def print_blue = { str -> ANSI_BLUE + str + ANSI_RESET }
def print_cyan = { str -> ANSI_CYAN + str + ANSI_RESET }
def print_purple = { str -> ANSI_PURPLE + str + ANSI_RESET }
def print_white = { str -> ANSI_WHITE + str + ANSI_RESET }
def helpMessage() {
log.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:
--redir The folder containing all reference files and index
--genomefile Path to Fasta reference (required if not set in config file)
--gtffile/--bedfile/
--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/--knifedir Home folder of ciri/find_circ/mapsplice/knife installed location
Options:
-profile Configuration profile to use. Can use multiple (comma separated)
Available: standard, conda, docker, singularity, awsbatch, test
--starindex/--bowtie2index/
--bwaindex/--segindex/
--bowtieindex/--refmapsplice Path to STAR/bowtie2/segemehl/bowtie/bwa/mapsplice index.
If not set, the pipeline will create the index itself.
--singleEnd Specify that the reads are single ended
--merge Merge the different matrixes produce by different tools and draw the venn graph
--separate Annotate the results separately
--selectTools Specify which tools should be use.
1 for circexplorer2, 2 for ciri, 3 for find_circ, 4 for mapsplice, 5 for segemehl, 6 for knife.
For example, you can set 1,2,3,4,5 for running five tools in the same time.
--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.
AWSBatch options:
--awsqueue The AWSBatch JobQueue that needs to be set when running on AWSBatch
--awsregion The AWS Region for your AWS Batch job to run on
""".stripIndent()
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help emssage
if (params.help){
helpMessage()
exit 0
}
/*
// AWSBatch sanity checking
if(workflow.profile == 'awsbatch'){
if (!params.awsqueue || !params.awsregion) exit 1, "Specify correct --awsqueue and --awsregion parameters on AWSBatch!"
if (!workflow.workDir.startsWith('s3') || !params.outdir.startsWith('s3')) exit 1, "Specify S3 URLs for workDir and outdir parameters on AWSBatch!"
}
//
// NOTE - THIS IS NOT USED IN THIS PIPELINE, EXAMPLE ONLY
// If you want to use the above in a process, define the following:
// input:
// file fasta from fasta
//
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if( !(workflow.runName ==~ /[a-z]+_[a-z]+/) ){
custom_runName = workflow.runName
}
// Check workDir/outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
if( workflow.profile == 'awsbatch') {
if(!workflow.workDir.startsWith('s3:') || !params.outdir.startsWith('s3:')) exit 1, "Workdir or Outdir not on S3 - specify S3 Buckets for each to run on AWSBatch!"
}
*/
/*
* Checking the input files
* Build up the output files
* Adding input files error exceptions Here
*/
outdir = file(params.outdir) //the output directory
/*
========================================================================================
select the analysis tools
========================================================================================
*/
if( params.selectTools ==~ /.*1.*/ ){
params.circexplorer2 = true
}else{
params.circexplorer2 = false
}
if( params.selectTools ==~ /.*2.*/ ){
params.ciri = true
}else{
params.ciri = false
}
if( params.selectTools ==~ /.*3.*/ ){
params.find_circ = true
}else{
params.find_circ = false
}
if( params.selectTools ==~ /.*4.*/ ){
params.mapsplice = true
}else{
params.mapsplice = false
}
if( params.selectTools ==~ /.*5.*/ ){
params.segemehl = true
}else{
params.segemehl = false
}
if( params.selectTools ==~ /.*6.*/ ){
params.knife = true
}else{
params.knife = false
}
otherTools = file(params.otherTools) //the other tools directory
if( !otherTools.exists() ) exit 1, print_red("Missing other tools directory: ${otherTools}")
if(params.mRNA){
mRNA = file(params.mRNA) //the mRNA file
if( !mRNA.exists() ) exit 1, print_red("Missing mRNA expression file: ${mRNA}")
}
/*
========================================================================================
the reference directory
========================================================================================
*/
refdir = file(params.refdir) //the reference genome directory
if( !refdir.exists() ) exit 1, print_red("Missing Reference Genome Directory: ${refdir}")
refmapsplice = file(params.refmapsplice) //the mapsplice reference genome directory
if(params.mapsplice){
if( !refmapsplice.exists() ) exit 1, print_red("Missing Mapsplice Reference Genome Directory: ${refmapsplice}")
}
annotationfile = file(params.annotationfile) //the annotationfile
if(params.circexplorer2){
if( !annotationfile.exists() ) exit 1, print_red("Missing annotation file: ${annotationfile}")
}
genomefile = file(params.genomefile) //the genomefile
if( !genomefile.exists() ) exit 1, print_red("Missing genome file: ${genomefile}")
gtffile = file(params.gtffile) //the annotationfile-gtf-format
if( !gtffile.exists() ) exit 1, print_red("Missing gtf annotation file: ${gtffile}")
bedfile = file(params.bedfile) //the annotationfile-bed-format
if( !bedfile.exists() ) exit 1, print_red("Missing bed annotation file: ${bedfile}")
/*
========================================================================================
checking the design and compare file
========================================================================================
*/
//design file
designfile = file(params.designfile)
if(params.designfile) {
if( !designfile.exists() ) exit 1, print_red("Design file not found: ${params.designfile}")
}
//compare file
comparefile = file(params.comparefile)
if(params.comparefile){
if( !comparefile.exists() ) exit 1, print_red("Compare file not found: ${params.comparefile}")
}
/*
========================================================================================
showing the process and files
========================================================================================
*/
log.info print_cyan("""
========================================================================
________ _______
| ____ | | ___ |
| | |_| _ | | | | _
| | |_| | | | | |_|
| | _ _ __ _____ | |___| | _ ______ _____
| | | | | |/ / | ___| | _____| | | | __ | | _ |
| | | | | / | | | | | | | | | | | |_| |
| | _ | | | / | | | | | | | | | | | ___|
| |____| | | | | | | |___ | | | | | |__| | | |___
|________| |_| |_| |_____| |_| |_| | ____| |_____|
| |
| |
|_|
=======================================================================
""")
.stripIndent()
log.info print_purple("============You are running cirPipe with the following parameters===============")
log.info print_purple("Checking parameters ...")
log.info "\n"
log.info print_yellow("=====================================Reads types================================")
log.info print_yellow("SingleEnd : ") + print_green(params.singleEnd)
log.info "\n"
log.info print_yellow("====================================Tools selected==============================")
log.info print_yellow("Circexplorer2 : ") + print_green(params.circexplorer2)
log.info print_yellow("Find_circ : ") + print_green(params.find_circ)
log.info print_yellow("Ciri : ") + print_green(params.ciri)
log.info print_yellow("Mapsplice : ") + print_green(params.mapsplice)
log.info print_yellow("Segemehl : ") + print_green(params.segemehl)
log.info print_yellow("Knife : ") + print_green(params.knife)
log.info "\n"
log.info print_yellow("==================================Input files selected==========================")
log.info print_yellow("Reads : ") + print_green(params.reads)
log.info print_yellow("Annotation file : ") + print_green(params.annotationfile)
log.info print_yellow("Genome file : ") + print_green(params.genomefile)
log.info print_yellow("Gtf file : ") + print_green(params.gtffile)
log.info print_yellow("Bed file : ") + print_green(params.bedfile)
log.info "\n"
log.info print_yellow("==================================Output files directory========================")
log.info print_yellow("Output directory : ") + print_green(params.outdir)
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 print_yellow("===================check or build the index===============================")
/*
========================================================================================
check or build the index
========================================================================================
*/
if(params.circexplorer2==true){
if(params.starindex){
starindex = Channel
.fromPath(params.starindex)
.ifEmpty { exit 1, "STAR index not found: ${params.starindex}" }
}else{
process makeSTARindex {
publishDir "${params.outdir}/reference_genome", mode: 'copy', overwrite: true
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
"""
}
}
}else{
starindex = Channel
.fromPath(params.refdir)
}
if(params.find_circ==true){
if(params.bowtie2index){
bowtie2index = Channel
.fromPath(params.bowtie2index)
.ifEmpty { exit 1, "Bowtie2 index not found: ${params.bowtie2index}" }
bowtie2index_fc = Channel
.fromPath(params.bowtie2index)
.ifEmpty { exit 1, "Bowtie2 index not found: ${params.bowtie2index}" }
}else{
process makeBowtie2index {
publishDir "${params.outdir}/reference_genome", mode: 'copy', overwrite: true
input:
file genomefile
output:
file "bowtie2index" into bowtie2index
file "bowtie2index" into bowtie2index_fc
file "bowtie2index" into bowtie2_build_knife
script:
"""
mkdir bowtie2index
cd ./bowtie2index
bowtie2-build -f \
../${genomefile} \
genome
cd ../
"""
}
}
}else{
bowtie2index = Channel
.fromPath(params.refdir)
bowtie2index_fc = Channel
.fromPath(params.refdir)
}
if(params.mapsplice==true){
if(params.bowtieindex){
bowtieindex = Channel
.fromPath(params.bowtieindex)
.ifEmpty { exit 1, "Bowtie index not found: ${params.bowtieindex}" }
}else{
process makeBowtieindex {
publishDir "${params.outdir}/reference_genome", mode: 'copy', overwrite: true
input:
file genomefile
output:
file "bowtieindex" into bowtieindex
file "bowtieindex" into bowtie_build_knife
script:
"""
mkdir bowtieindex
cd ./bowtieindex
bowtie-build \
../${genomefile} \
genome
cd ../
"""
}
}
}else{
bowtieindex = Channel
.fromPath(params.refdir)
}
if(params.ciri==true){
if(params.bwaindex){
bwaindex = Channel
.fromPath(params.bwaindex)
.ifEmpty { exit 1, "BWA index not found: ${params.bwaindex}" }
}else{
process makeBWAindex {
publishDir "${params.outdir}/reference_genome", mode: 'copy', overwrite: true
input:
file genomefile
output:
file "bwaindex" into bwaindex
script:
"""
mkdir bwaindex
cd ./bwaindex
bwa \
index ../${genomefile} \
-p genome
cd ../
"""
}
}
}else{
bwaindex = Channel
.fromPath(params.refdir)
}
if(params.segemehl==true){
if(params.segindex){
segindex = Channel
.fromPath(params.segindex)
.ifEmpty { exit 1, "Segemehl index not found: ${params.segindex}" }
}else{
process makeSegemehlindex {
publishDir "${params.outdir}/reference_genome", mode: 'copy', overwrite: true
input:
file genomefile
file segdir
output:
file "genome.idx" into segindex
script:
"""
${segdir}/segemehl.x \
-d ${genomefile} \
-x genome.idx
"""
}
}
}else{
segindex = Channel
.fromPath(params.refdir)
}
log.info print_purple("==========Index pass!...==========")
log.info print_purple("==========Start running CircPipe...==========")
/*
========================================================================================
first step : run the fastp (QC tool)
========================================================================================
*/
process Fastp{
tag "$pair_id"
publishDir "${params.outdir}/QC", mode: 'copy', pattern: "*_fastpreport.html", overwrite: true
input:
set pair_id, file(query_file) from read_pairs_fastp
output:
set pair_id, file ('unzip_fastp_*') into fastpfiles_mapsplice,fastpfiles_bwa,fastpfiles_star,fastpfiles_segemehl,fastpfiles_knife,fastpfiles_bowtie2
file ('*.html') into fastp_for_waiting
file ('*_fastp.json') into fastp_for_multiqc
script:
if(params.singleEnd){
"""
fastp \
-i ${query_file} \
-o unzip_fastp_${pair_id}.fq \
-h ${pair_id}_fastpreport.html \
-j ${pair_id}_fastp.json
"""
}else{
"""
fastp \
-i ${query_file[0]} \
-I ${query_file[1]} \
-o unzip_fastp_${pair_id}_1.fq \
-O unzip_fastp_${pair_id}_2.fq \
-h ${pair_id}_fastpreport.html \
-j ${pair_id}_fastp.json
"""
}
}
fastp_for_waiting = fastp_for_waiting.first() //wait for finish this process first
/*
========================================================================================
run the multiqc (merge the results of fastp)
========================================================================================
*/
process Multiqc{
publishDir "${params.outdir}/QC", mode: 'copy', pattern: "*.html", overwrite: true
input:
file (query_file) from fastp_for_multiqc.collect()
output:
file ('*.html') into multiqc_results
script:
"""
multiqc .
"""
}
/*
========================================================================================
the first tool : star - circexplorer2
run the star
========================================================================================
*/
process Star{
tag "$pair_id"
publishDir "${params.outdir}/Alignment/STAR", mode: 'link', overwrite: true
input:
set pair_id, file(query_file) from fastpfiles_star
file index from starindex.collect()
output:
set pair_id, file ('*.junction') into starfiles
when:
params.circexplorer2
shell:
if(params.singleEnd){
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir $index \
--readFilesIn ${query_file} \
--outFileNamePrefix star_${pair_id}_
"""
}else{
"""
STAR \
--runThreadN ${task.cpus} \
--chimSegmentMin 10 \
--genomeDir $index \
--readFilesIn ${query_file[0]} ${query_file[1]} \
--outFileNamePrefix star_${pair_id}_
"""
}
}
/*
========================================================================================
the first tool : star - circexplorer2
run the circexplorer2
========================================================================================
*/
process Circexplorer2{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', overwrite: true
input:
set pair_id, file (query_file) from starfiles
file annotationfile
file genomefile
output:
set pair_id, file ('*known.txt') into circexplorer2files
when:
params.circexplorer2
script:
"""
CIRCexplorer2 \
parse -t STAR ${query_file} \
> CIRCexplorer2_parse_${pair_id}.log
CIRCexplorer2 \
annotate -r ${annotationfile} \
-g ${genomefile} \
-b back_spliced_junction.bed \
-o CIRCexplorer2_${pair_id}_circularRNA_known.txt \
> CIRCexplorer2_annotate_${pair_id}.log
"""
}
/*
========================================================================================
the first tool : star - circexplorer2
produce the bed6 file
========================================================================================
*/
process Circexplorer2_Bed{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', pattern: "*candidates.bed", overwrite: true
input:
set pair_id, file (query_file) from circexplorer2files
file otherTools
output:
file ('*candidates.bed') into modify_circexplorer2
val (pair_id) into modify_circexplorer2_id
when:
params.circexplorer2
shell :
'''
if [ $((`cat !{query_file} | wc -l`)) == 0 ];then
touch !{pair_id}_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}' \
> !{pair_id}_modify_circexplorer2.temp.bed
python !{otherTools}/quchong.py !{pair_id}_modify_circexplorer2.temp.bed !{pair_id}_modify_circexplorer2.candidates.bed
fi
'''
}
/*
========================================================================================
the first tool : star - circexplorer2
produce the matrix
========================================================================================
*/
process Circexplorer2_Matrix{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRCexplorer2", mode: 'copy', pattern: "*.matrix", overwrite: true
input:
file (query_file) from modify_circexplorer2.collect()
val (pair_id) from modify_circexplorer2_id.collect()
file otherTools
file designfile
file gtffile
output:
file ('circexplorer2.txt') into merge_circexplorer2
file ('*.matrix') into output_circexplorer2
file ('name_circexplorer2.txt') into name_circexplorer2
file ('*annote.txt') into de_circexplorer2
file ('*.matrix') into plot_circexplorer2
file ('*annote.txt') into cor_circexplorer2
file ('*.matrix') into plot_circexplorer2_cor
when:
params.circexplorer2
shell :
'''
for file in !{query_file}
do
cat $file >> concatenate.bed
done
python !{otherTools}/hebinglist.py concatenate.bed merge_concatenate.bed
sort -t $'\t' -k 1,1 -k 2n,2 -k 3n,3 merge_concatenate.bed > mergeconcatenate.bed
cat mergeconcatenate.bed | awk '{print $1 "_" $2 "_" $3 "_" $4 }' > id.txt
cat mergeconcatenate.bed > circexplorer2.txt
cat circexplorer2.txt | awk '{print $1 "\t" $2 "\t" $3 "\t" "." "\t" "." "\t" $4 }' > annotation.bed
java -jar !{otherTools}/bed1114.jar -i annotation.bed -o circexplorer2_ -gtf !{gtffile} -uniq
cat !{designfile} > designfile.txt
sed -i '1d' designfile.txt
cat designfile.txt | awk '{print $1}' > samplename.txt
echo -e "id\\c" > merge_header.txt
cat samplename.txt | while read line
do
if [ $((`cat ${line}_modify_circexplorer2.candidates.bed | wc -l`)) == 0 ];then
python !{otherTools}/createzero.py mergeconcatenate.bed counts.txt
else
python !{otherTools}/quchongsamples.py mergeconcatenate.bed ${line}_modify_circexplorer2.candidates.bed counts.txt
fi
paste -d"\t" id.txt counts.txt > temp.txt
cat temp.txt > id.txt
echo -e "\\t${line}\\c" >> merge_header.txt
done
sed -i 's/\\[//g' merge_header.txt
sed -i 's/\\,//g' merge_header.txt
sed -i 's/\\]//g' merge_header.txt
echo -e "\\n\\c" >> merge_header.txt
cat merge_header.txt id.txt > circexplorer2_merge.matrix
echo -e "circexplorer2" > name_circexplorer2.txt
'''
}
/*
========================================================================================
the first tool : star - circexplorer2
Differential Expression
========================================================================================
*/
process Circexplorer2_DE{
publishDir "${params.outdir}/DE_Analysis/Circexplorer2", mode: 'copy', pattern: "*", overwrite: true
input:
file (anno_file) from de_circexplorer2
file otherTools
file designfile
file comparefile
file (matrix_file) from plot_circexplorer2
output:
file ('*') into end_circexplorer2
when:
params.circexplorer2
shell:
'''
Rscript !{otherTools}/edgeR_circ.R !{otherTools}/R_function.R !{matrix_file} !{designfile} !{comparefile} !{anno_file}
'''
}
/*
========================================================================================
the first tool : star - circexplorer2
Correlation
========================================================================================
*/
process Circexplorer2_Cor{
publishDir "${params.outdir}/Corrrelation_Analysis/Circexplorer2", mode: 'copy', pattern: "*", overwrite: true
input:
file (matrix_file) from plot_circexplorer2_cor
file (anno_file) from cor_circexplorer2
file mRNA
file otherTools
when:
params.mRNA && params.circexplorer2
output:
file ('*') into cor_plot_circexplorer2
shell:
'''
Rscript !{otherTools}/correlation.R !{otherTools}/R_function.R !{mRNA} !{matrix_file} !{anno_file}
'''
}
/*
========================================================================================
the second tool : bwa - ciri
run the bwa
========================================================================================
*/
process Bwa{
tag "$pair_id"
publishDir "${params.outdir}//Alignment/BWA", mode: 'link', overwrite: true
input:
set pair_id, file (query_file) from fastpfiles_bwa
file index from bwaindex.collect()
output:
set pair_id, file ('*.sam') into bwafiles
when:
params.ciri
shell:
if(params.singleEnd){
"""
bwa \
mem -t ${task.cpus} \
-k 15 \
-T 19 -M -R \
"@RG\\tID:fastp_${pair_id}\\tPL:PGM\\tLB:noLB\\tSM:fastp_${pair_id}" \
${index}/genome \
${query_file} \
> bwa_${pair_id}.mem.sam
"""
}else{
"""
bwa \
mem -t ${task.cpus} \
-T 19 -M -R \
"@RG\\tID:fastp_${pair_id}\\tPL:PGM\\tLB:noLB\\tSM:fastp_${pair_id}" \
${index}/genome \
${query_file[0]} ${query_file[1]} \
> bwa_${pair_id}.mem.sam
"""
}
}
/*
========================================================================================
the second tool : bwa - ciri
run the ciri
========================================================================================
*/
process Ciri{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRI", mode: 'copy', overwrite: true
input:
set pair_id, file (query_file) from bwafiles
file gtffile
file genomefile
output:
set pair_id, file ('*.txt') into cirifiles
when:
params.ciri
script:
"""
CIRI2.pl \
-T 10 \
-F ${genomefile} \
-A ${gtffile} \
-G CIRI_${pair_id}.log \
-I ${query_file} \
-O CIRI_${pair_id}.txt \
> CIRI_${pair_id}_detail.log
"""
}
/*
========================================================================================
the second tool : bwa - ciri
produce the bed6 file
========================================================================================
*/
process Ciri_Bed{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRI", mode: 'copy', pattern: "*candidates.bed", overwrite: true
input:
set pair_id, file (query_file) from cirifiles
file otherTools
output:
file ('*candidates.bed') into modify_ciri_file
val (pair_id) into modify_ciri_id
when:
params.ciri
shell :
'''
if [ $((`cat !{query_file} | wc -l`)) == 1 ];then
touch !{pair_id}_modify_ciri.candidates.bed
else
cat !{query_file} \
| sed -e '1d' \
| grep -v chrM \
| awk '{print $2 "\t" $3 "\t" $4 "\t" "ciri" "\t" $5 "\t" $11}' \
> !{pair_id}_modify_ciri.temp.bed
python !{otherTools}/quchong.py !{pair_id}_modify_ciri.temp.bed !{pair_id}_modify_ciri.candidates.bed
fi
'''
}
/*
========================================================================================
the second tool : bwa - ciri
produce the matrix
========================================================================================
*/
process Ciri_Matrix{
tag "$pair_id"
publishDir "${params.outdir}/circRNA_Identification/CIRI", mode: 'copy', pattern: "*.matrix", overwrite: true
input:
file (query_file) from modify_ciri_file.collect()
val (pair_id) from modify_ciri_id.collect()
file otherTools
file designfile
file gtffile
output:
file ('ciri.txt') into merge_ciri
file ('*.matrix') into output_ciri
file ('name_ciri.txt') into name_ciri
file ('*annote.txt') into de_ciri
file ('*.matrix') into plot_ciri
file ('*annote.txt') into cor_ciri
file ('*.matrix') into plot_ciri_cor
when:
params.ciri
shell :
'''
for file in !{query_file}
do
cat $file >> concatenate.bed
done
python !{otherTools}/hebinglist.py concatenate.bed merge_concatenate.bed
sort -t $'\t' -k 1,1 -k 2n,2 -k 3n,3 merge_concatenate.bed > mergeconcatenate.bed
cat mergeconcatenate.bed | awk '{print $1 "_" $2 "_" $3 "_" $4 }' > id.txt
cat mergeconcatenate.bed > ciri.txt
cat ciri.txt | awk '{print $1 "\t" $2 "\t" $3 "\t" "." "\t" "." "\t" $4 }' > annotation.bed
java -jar !{otherTools}/bed1114.jar -i annotation.bed -o ciri_ -gtf !{gtffile} -uniq
cat !{designfile} > designfile.txt
sed -i '1d' designfile.txt
cat designfile.txt | awk '{print $1}' > samplename.txt
echo -e "id\\c" > merge_header.txt
cat samplename.txt | while read line
do
if [ $((`cat ${line}_modify_ciri.candidates.bed | wc -l`)) == 0 ];then
python !{otherTools}/createzero.py mergeconcatenate.bed counts.txt
else
python !{otherTools}/quchongsamples.py mergeconcatenate.bed ${line}_modify_ciri.candidates.bed counts.txt
fi
paste -d"\t" id.txt counts.txt > temp.txt
cat temp.txt > id.txt
echo -e "\\t${line}\\c" >> merge_header.txt
done
sed -i 's/\\[//g' merge_header.txt
sed -i 's/\\,//g' merge_header.txt
sed -i 's/\\]//g' merge_header.txt
echo -e "\\n\\c" >> merge_header.txt
cat merge_header.txt id.txt > ciri_merge.matrix
echo -e "ciri" > name_ciri.txt
'''
}
/*
========================================================================================
the second tool : bwa - ciri
Differential Expression
========================================================================================
*/
process Ciri_DE{