forked from nf-core/circrna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
2217 lines (1820 loc) · 84.5 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
/*
================================================================================
nf-core/circrna
================================================================================
Started August 2020.
Dev version to nf-core Feb 2021.
--------------------------------------------------------------------------------
@Homepage
https://github.com/nf-core/circrna
-------------------------------------------------------------------------------
@Documentation
https://nf-co.re/circrna
--------------------------------------------------------------------------------
@Authors
Barry Digby (@BarryDigby)
--------------------------------------------------------------------------------
*/
log.info Headers.nf_core(workflow, params.monochrome_logs)
/*
================================================================================
Print Help
================================================================================
*/
def json_schema = "$workflow.projectDir/nextflow_schema.json"
if (params.help) {
def command = "nextflow run nf-core/circrna -profile singularity --input '*_R{1,2}.fastq.gz' --input_type 'fastq' --genome 'GRCh38' --module 'circrna_discovery, mirna_prediction, differential_expression' --tool 'CIRCexplorer2' --phenotype 'metadata.csv' "
log.info NfcoreSchema.params_help(workflow, params, json_schema, command)
exit 0
}
// Moved from nextflow.config
// Function to ensure that resource requirements don't go beyond
// a maximum limit
def check_max(obj, type) {
if (type == 'memory') {
try {
if (obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1)
return params.max_memory as nextflow.util.MemoryUnit
else
return obj
} catch (all) {
println " ### ERROR ### Max memory '${params.max_memory}' is not valid! Using default value: $obj"
return obj
}
} else if (type == 'time') {
try {
if (obj.compareTo(params.max_time as nextflow.util.Duration) == 1)
return params.max_time as nextflow.util.Duration
else
return obj
} catch (all) {
println " ### ERROR ### Max time '${params.max_time}' is not valid! Using default value: $obj"
return obj
}
} else if (type == 'cpus') {
try {
return Math.min( obj, params.max_cpus as int )
} catch (all) {
println " ### ERROR ### Max cpus '${params.max_cpus}' is not valid! Using default value: $obj"
return obj
}
}
}
/*
================================================================================
Check parameters
================================================================================
*/
if (params.validate_params) {
NfcoreSchema.validateParameters(params, json_schema, log)
}
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)){
exit 1, "The provided genome '${params.genome}' is not available in the iGenomes file. Currently the available genomes are ${params.genomes.keySet().join(', ')}"
}
// Check Tools selected
// Is schema enumerate case sensitive? Seems easier to let toLowerCase take care of misplaced caps from user.
toolList = defineToolList()
tool = params.tool ? params.tool.split(',').collect{it.trim().toLowerCase()} : []
if (!checkParameterList(tool, toolList)) exit 1, "[nf-core/circrna] error: Unknown tool selected, see --help for more information."
// Check Modules selected
moduleList = defineModuleList()
module = params.module ? params.module.split(',').collect{it.trim().toLowerCase()} : []
if (!checkParameterList(module, moduleList)) exit 1, "[nf-core/circrna] error: Unknown module selected, see --help for more information."
// Check phenotype file and stage the channel
// (Must not have NA's, must have 'condition' as colname)
if(params.phenotype){
pheno_file = file(params.phenotype)
ch_phenotype = examine_phenotype(pheno_file)
} else {
ch_phenotype = Channel.empty()
}
// Check BBDUK params
/*
check adapters file exists
check combinations of parameters have been supplied correctly
*/
if(params.trim_fastq){
if(params.adapters){
adapters = file(params.adapters, checkIfExists: true)
if(!params.k && !params.ktrim || !params.k && params.ktrim || params.k && !params.ktrim){
exit 1, "[nf-core/circrna] error: Adapter file provided for trimming but missing values for '--k' and/or '--ktrim'.Please provide values for '--k' and '--ktrim'.\n\nPlease check the parameter documentation online."
}
}
if(params.trimq && !params.qtrim || !params.trimq && params.qtrim){
exit 1, "[nf-core/circrna] error: Both '--trimq' and '--qtrim' are required to perform quality filtering - only one has been provided.\n\nPlease check the parameter documentation online."
}
}
// Check filtering params
tools_selected = tool.size()
// Check '--tool_filter'' does not exceed number of tools selected
if(tools_selected > 1 && params.tool_filter > tools_selected){
exit 1, "[nf-core/circrna] error: The parameter '--tool_filter' (${params.tool_filter}) exceeds the number of tools selected (${params.tool}). Please select a value less than or equal to the number of quantification tools selected ($tools_selected).\n\nPlease check the help documentation."
}
// Check Input data (if !csv choose path)
if(has_extension(params.input, "csv")){
csv_file = file(params.input, checkIfExists: true)
ch_input = extract_data(csv_file)
}else if(params.input && !has_extension(params.input, "csv")){
log.info ""
log.info "Input data log info:"
log.info "No input sample CSV file provided, attempting to read from path instead."
log.info "Reading input data from path: ${params.input}\n"
log.info ""
ch_input = retrieve_input_paths(params.input, params.input_type)
}
(bam_input, fastq_input) = ch_input.into(2)
// Check AWS batch settings
if (workflow.profile.contains('awsbatch')) {
// AWSBatch sanity checking
if (!params.awsqueue || !params.awsregion) exit 1, 'Specify correct --awsqueue and --awsregion parameters on AWSBatch!'
// Check outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
if (!params.outdir.startsWith('s3:')) exit 1, 'Outdir not on S3 - specify S3 Bucket to run on AWSBatch!'
// Prevent trace files to be stored on S3 since S3 does not support rolling files.
if (params.tracedir.startsWith('s3:')) exit 1, 'Specify a local tracedir or run without trace! S3 cannot be used for tracefiles.'
}
// Stage config files
ch_multiqc_config = file("$workflow.projectDir/assets/multiqc_config.yaml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config, checkIfExists: true) : Channel.empty()
ch_output_docs = file("$workflow.projectDir/docs/output.md", checkIfExists: true)
ch_output_docs_images = file("$workflow.projectDir/docs/images/", checkIfExists: true)
/*
================================================================================
PRINTING PARAMETER SUMMARY
================================================================================
*/
log.info NfcoreSchema.params_summary_log(workflow, params, json_schema)
// 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
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Run Name'] = custom_runName ?: workflow.runName
if (workflow.containerEngine) summary['Container'] = "${workflow.containerEngine} - ${workflow.container}"
summary['Max Resources'] = "${params.max_memory} memory, ${params.max_cpus} cpus, ${params.max_time} time per job"
summary['Config Files'] = workflow.configFiles.join(', ')
summary['Launch dir'] = workflow.launchDir
summary['Output dir'] = params.outdir
summary['Publish dir mode'] = params.publish_dir_mode
summary['Working dir'] = workflow.workDir
summary['Script dir'] = workflow.projectDir
summary['User'] = workflow.userName
summary['Input'] = params.input
summary['Input type'] = params.input_type
if('differential_expression' in module) summary['Phenotype file'] = params.phenotype
summary['circRNA tool(s)'] = params.tool
summary['modules'] = params.module
summary['BSJ filter'] = params.bsj_reads
if(tools_selected > 1) summary['Tool filter'] = params.tool_filter
summary['Genome'] = params.genome
if(params.fasta) summary['Reference FASTA'] = params.fasta
if(params.gtf) summary['Reference GTF'] = params.gtf
if(params.bowtie) summary['Bowtie indices'] = params.bowtie
if(params.bowtie2) summary['Bowtie2 indices'] = params.bowtie2
if(params.bwa) summary['BWA indices'] = params.bwa
if(params.fasta_fai) summary['SAMtools index'] = params.fasta_fai
if(params.hisat) summary['HISAT2 indices'] = params.hisat2
if(params.star) summary ['STAR indices'] = params.star
if(params.segemehl) summary ['Segemehl index'] = params.segemehl
summary['Save reference files'] = params.save_reference
summary['Save QC intermediates'] = params.save_qc_intermediates
summary['Save RNASeq intermediates'] = params.save_rnaseq_intermediates
summary['Save Quantification intermediates'] = params.save_quantification_intermediates
summary['Save miRNA predictions'] = params.save_mirna_predictions
summary['Skip BBDUK'] = params.trim_fastq
if(params.trim_fastq){
summary['BBDUK'] = "Enabled"
if(params.adapters) summary['Adapter file'] = params.adapters
if(params.k) summary['k'] = params.k
if(params.ktrim) summary['ktrim'] = params.ktrim
if(params.hdist) summary['hdist'] = params.hdist
if(params.trimq) summary['trimq'] = params.trimq
if(params.qtrim) summary['qtrim'] = params.qtrim
if(params.minlen) summary['minlen'] = params.minlen
}
if('circexplorer2' in tool || 'circrna_finder' in tool || 'dcc' in tool){
if(params.alignIntronMax) summary['alignIntronMax'] = params.alignIntronMax
if(params.alignIntronMin) summary['alignIntronMin'] = params.alignIntronMin
if(params.alignMatesGapMax) summary['alignMatesGapMax'] = params.alignMatesGapMax
if(params.alignSJDBoverhangMin) summary['alignSJDBoverhangMin'] = params.alignSJDBoverhangMin
if(params.alignSJoverhangMin) summary['alignSJoverhangMin'] = params.alignSJoverhangMin
if(params.alignSoftClipAtReferenceEnds) summary['alignSoftClipAtReferenceEnds'] = params.alignSoftClipAtReferenceEnds
if(params.alignTranscriptsPerReadNmax) summary['alignTranscriptsPerReadNmax'] = params.alignTranscriptsPerReadNmax
if(params.chimJunctionOverhangMin) summary['chimJunctionOverhangMin'] = params.chimJunctionOverhangMin
if(params.chimScoreMin) summary['chimScoreMin'] = params.chimScoreMin
if(params.chimScoreSeparation) summary['chimScoreSeparation'] = params.chimScoreSeparation
if(params.chimSegmentMin) summary['chimSegmentMin'] = params.chimSegmentMin
if(params.genomeLoad) summary['genomeLoad'] = params.genomeLoad
if(params.limitSjdbInsertNsj) summary['limitSjdbInsertNsj'] = params.limitSjdbInsertNsj
if(params.outFilterMatchNminOverLread) summary['outFilterMatchNminOverLread'] = params.outFilterMatchNminOverLread
if(params.outFilterMismatchNoverLmax) summary['outFilterMismatchNoverLmax'] = params.outFilterMismatchNoverLmax
if(params.outFilterMultimapNmax) summary['outFilterMultimapNmax'] = params.outFilterMultimapNmax
if(params.outFilterMultimapScoreRange) summary['outFilterMultimapScoreRange'] = params.outFilterMultimapScoreRange
if(params.outFilterScoreMinOverLread) summary['outFilterScoreMinOverLread'] = params.outFilterScoreMinOverLread
if(params.outSJfilterOverhangMin) summary['outSJfilterOverhangMin'] = params.outSJfilterOverhangMin
if(params.sjdbOverhang) summary['sjdbOverhang'] = params.sjdbOverhang
if(params.sjdbScore) summary['sjdbScore'] = params.sjdbScore
if(params.winAnchorMultimapNmax) summary['winAnchorMultimapNmax'] = params.winAnchorMultimapNmax
}
if(workflow.profile.contains('awsbatch')){
summary['AWS Region'] = params.awsregion
summary['AWS Queue'] = params.awsqueue
summary['AWS CLI'] = params.awscli
}
if(params.email || params.email_on_fail){
summary['E-mail Address'] = params.email
summary['E-mail on failure'] = params.email_on_fail
summary['MultiQC maxsize'] = params.max_multiqc_email_size
}
summary['Config Profile'] = workflow.profile
if (params.config_profile_description) summary['Config Profile Description'] = params.config_profile_description
if (params.config_profile_contact) summary['Config Profile Contact'] = params.config_profile_contact
if (params.config_profile_url) summary['Config Profile URL'] = params.config_profile_url
summary['Config Files'] = workflow.configFiles.join(', ')
// Check the hostnames against configured profiles
checkHostname()
Channel.from(summary.collect{ [it.key, it.value] })
.map { k,v -> "<dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }
.reduce { a, b -> return [a, b].join("\n ") }
.map { x -> """
id: 'nf-core-circrna-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'nf-core/circrna Workflow Summary'
section_href: 'https://github.com/nf-core/circrna'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
$x
</dl>
""".stripIndent() }
.set { ch_workflow_summary }
/*
================================================================================
Stage Parameters
================================================================================
*/
/* Note to reviewer:
* I get warning messages when the parameters are not used by the workflow (for e.g when tool that uses bowtie not used):
* 'WARN: Access to undefined parameter `bowtie` -- Initialise it to a default value eg. `params.bowtie = some_value`'
* Is there a way to stop these warnings from printing or is it ok to leave as is
*/
params.fasta = params.genome ? params.genomes[params.genome].fasta ?: false : false
//params.fasta_fai = params.genome ? params.genomes[params.genome].fasta_fai ?: false : false # I don't trust iGenomes has this for all species. Trivial to make in terms of run time.
params.gtf = params.genome ? params.genomes[params.genome].gtf ?: false : false
params.bwa = params.genome && 'ciriquant' in tool ? params.genomes[params.genome].bwa ?: false : false
params.star = params.genome && ('circexplorer2' || 'dcc' || 'circrna_finder' in tool) ? params.genomes[params.genome].star ?: false : false
params.bowtie = params.genome && 'mapsplice' in tool ? params.genomes[params.genome].bowtie ?: false : false
params.bowtie2 = params.genome && 'find_circ' in tool ? params.genomes[params.genome].bowtie2 ?: false : false
params.mature = params.genome && 'mirna_prediction' in module ? params.genomes[params.genome].mature ?: false : false
params.species = params.genome ? params.genomes[params.genome].species_id?: false : false
ch_fasta = params.fasta ? Channel.value(file(params.fasta)) : 'null'
ch_gtf = params.gtf ? Channel.value(file(params.gtf)) : 'null'
ch_mature = params.mature && 'mirna_prediction' in module ? Channel.value(file(params.mature)) : 'null'
ch_species = params.genome ? Channel.value(params.species) : Channel.value(params.species)
/*
================================================================================
SOFTWARE VERSIONS
================================================================================
*/
/*
Note to reviewer:
I struggled capturing tool versions, particularly with the regexes in 'scrape_software_versions.py'
For now, the process is hardcoded.
*/
process SOFTWARE_VERSIONS {
publishDir "${params.outdir}/pipeline_info", mode: params.publish_dir_mode,
saveAs: {filename ->
if (filename.indexOf(".tsv") > 0) filename
else null
}
output:
file 'software_versions_mqc.yaml' into software_versions_yaml
file "software_versions.tsv"
script:
"""
echo $workflow.manifest.version > v_pipeline.txt
echo $workflow.nextflow.version > v_nextflow.txt
echo "37.62" > v_bbduk.txt
echo "2.29.2" > v_bedtools.txt
echo "1.2.3" > v_bowtie.txt
echo "2.3.5.1" > v_bowtie2.txt
echo "0.7.17" > v_bwa.txt
echo "2.3.8" > v_circexplorer2.txt
echo "1.1.1" > v_ciriquant.txt
echo "8.0.92" > v_java.txt
echo "2.2.1" > v_mapsplice.txt
echo "3.3a" > v_miranda.txt
echo "5.26.2" > v_perl.txt
echo "3.6.3" > v_R.txt
echo "0.3.4" > v_segemehl.txt
echo "2.24.1" > v_picard.txt
echo "2.7.15" > v_python.txt
echo "1.10" > v_samtools.txt
echo "2.6.1d" > v_star.txt
echo "2.1.1" > v_stringtie.txt
scrape_software_versions.py > software_versions_mqc.yaml
"""
}
/*
================================================================================
BUILD INDICES
================================================================================
*/
process BWA_INDEX {
tag "${fasta}"
label 'proces_medium'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/${it}" : null }
when:
!params.bwa && !params.genome && params.fasta && 'ciriquant' in tool && 'circrna_discovery' in module
input:
file(fasta) from ch_fasta
output:
file("BWAIndex") into bwa_built
script:
"""
mkdir -p BWAIndex
bwa index $fasta -p BWAIndex/${fasta.baseName}
"""
}
/*
* Note to reviewer:
* I'll verbalise what I think I am doing here, please let me know if there are contradictions in the code.
* 1. If igenomes '--genome' param passed to script, use pre-built indices from igenomes.
* 2. If path to indices is provided && --genome is null, use the path.
* 3. If neither are available, last resort is to build the indices.
*
* Had to include '&& ciriquant' below or else it attempts to stage 'false' in file channel, breaks workflow.
* This does not happen with other index channels which is confusing.
*/
ch_bwa = params.genome && 'ciriquant' in tool ? Channel.value(file(params.bwa)) : params.bwa && 'ciriquant' in tool ? Channel.value(file(params.bwa)) : bwa_built
process SAMTOOLS_INDEX {
tag "${fasta}"
label 'process_low'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/SamtoolsIndex/${it}" : null }
when:
!params.fasta_fai && params.fasta
input:
file(fasta) from ch_fasta
output:
file("${fasta}.fai") into fai_built
script:
"""
samtools faidx ${fasta}
"""
}
ch_fai = params.fasta_fai ? Channel.value(file(params.fasta_fai)) : fai_built
process HISAT2_INDEX {
tag "${fasta}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/Hisat2Index/${it}" : null }
when:
!params.hisat && params.fasta && ('differential_expression' in module || 'ciriquant' in tool)
input:
file(fasta) from ch_fasta
output:
file("${fasta.baseName}.*.ht2") into hisat_built
val("${workflow.launchDir}/${params.outdir}/reference_genome/Hisat2Index") into hisat_path
script:
"""
hisat2-build \\
-p ${task.cpus} \\
$fasta \\
${fasta.baseName}
"""
}
// Hisat2 not available from igenomes so this is more straight forward, path or else build.
// CIRIquant only wants path to index files, does not need files symlinked in work dir hence path not built here.
ch_hisat = params.hisat ? Channel.value(file(params.hisat)) : hisat_path
process STAR_INDEX {
tag "${fasta}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/${it}" : null }
when:
!params.star && params.fasta && params.gtf && ('circexplorer2' in tool || 'circrna_finder' in tool || 'dcc' in tool) && 'circrna_discovery' in module
input:
file(fasta) from ch_fasta
file(gtf) from ch_gtf
output:
file("STARIndex") into star_built
script:
"""
wget "https://raw.githubusercontent.com/nf-core/test-datasets/circrna/reference/chrI.gtf"
mv "chrI.gtf.1" "${gtf}"
wget "https://raw.githubusercontent.com/nf-core/test-datasets/circrna/reference/chrI.fa"
mv "chrI.fa.1" "chrI.fa"
mkdir -p STARIndex
STAR \\
--runMode genomeGenerate \\
--runThreadN ${task.cpus} \\
--sjdbOverhang ${params.sjdbOverhang} \\
--sjdbGTFfile $gtf \\
--genomeDir STARIndex/ \\
--genomeFastaFiles $fasta
"""
}
ch_star = params.genome ? Channel.value(file(params.star)) : params.star ? Channel.value(file(params.star)) : star_built
process BOWTIE_INDEX {
tag "${fasta}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/BowtieIndex/${it}" : null }
when:
!params.bowtie && params.fasta && 'mapsplice' in tool && 'circrna_discovery' in module
input:
file(fasta) from ch_fasta
output:
file ("${fasta.baseName}.*") into bowtie_built
script:
"""
bowtie-build \\
--threads ${task.cpus} \\
$fasta \\
${fasta.baseName}
"""
}
ch_bowtie = params.genome ? Channel.fromPath("${params.bowtie}*") : params.bowtie ? Channel.fromPath("${params.bowtie}*", checkIfExists: true).ifEmpty { exit 1, "[nf-core/circrna] error: Bowtie index directory not found: ${params.bowtie}"} : bowtie_built
process BOWTIE2_INDEX {
tag "${fasta}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/Bowtie2Index/${it}" : null }
when:
!params.bowtie2 && params.fasta && 'find_circ' in tool && 'circrna_discovery' in module
input:
file(fasta) from ch_fasta
output:
file ("${fasta.baseName}.*") into bowtie2_built
script:
"""
bowtie2-build \\
--threads ${task.cpus} \\
$fasta \\
${fasta.baseName}
"""
}
ch_bowtie2 = params.genome ? Channel.fromPath("${params.bowtie2}*") : params.bowtie2 ? Channel.fromPath("${params.bowtie2}*", checkIfExists: true).ifEmpty { exit 1, "[nf-core/circrna] error: Bowtie2 index directory not found: ${params.bowtie2}"} : bowtie2_built
(ch_bowtie2_anchors, ch_bowtie2_find_circ) = ch_bowtie2.into(2)
process SEGEMEHL_INDEX{
tag "${fasta}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/SegemehlIndex/${it}" : null }
when:
!params.segemehl && params.fasta && 'segemehl' in tool && 'circrna_discovery' in module
input:
file(fasta) from ch_fasta
output:
file("${fasta.baseName}.idx") into segemehl_built
script:
"""
segemehl.x \\
-t ${task.cpus} \\
-d $fasta \\
-x "${fasta.baseName}.idx"
"""
}
ch_segemehl = params.segemehl ? Channel.fromPath("${params.segemehl}*.idx", checkIfExists: true) : segemehl_built
/*
================================================================================
Misc circRNA Requirements
================================================================================
*/
process FILTER_GTF{
tag"${gtf}"
when:
'circrna_discovery' in module
input:
file(gtf) from ch_gtf
output:
file("filt.gtf") into ch_gtf_filtered
script:
"""
grep -vf ${workflow.projectDir}/bin/unwanted_biotypes.txt $gtf > filt.gtf
"""
}
if(('mapsplice' in tool || 'find_circ' in tool) && 'circrna_discovery' in module){
file("${params.outdir}/reference_genome/chromosomes").mkdirs()
ch_fasta.splitFasta(record: [id:true])
.map{ record -> record.id.toString() }
.flatten()
.set{ ID }
ch_fasta.splitFasta(file: true)
.flatten()
.merge(ID).map{ it ->
file = it[0]
chr_id = it[1]
file.copyTo("${params.outdir}/reference_genome/chromosomes/${chr_id}.fa")
}
stage_chromosomes = Channel.value("${workflow.launchDir}/${params.outdir}/reference_genome/chromosomes")
}
ch_chromosomes = ('mapsplice' in tool || 'find_circ' in tool) ? stage_chromosomes : 'null'
/*
* DEBUG
* No signature of method: nextflow.util.BlankSeparatedList.toRealPath() is applicable for argument types: () values: []
* error in below YML process (--genome, no params passed to gtf/fasta/etc.. )
* I suspect this is because bwa_built is a directory (BWAIndex), whilst params.bwa from iGenomes is a collection of files
* (structure of bwa on iGenomes is frustrating)
* If iGenomes bwa used, place the files in a directory so it matches bwa_built and "path" method.
*/
if(params.genome && 'ciriquant' in tool){
file("${params.outdir}/reference_genome/BWAIndex").mkdirs()
ch_bwa.flatten().map{ it -> it.copyTo("${params.outdir}/reference_genome/BWAIndex")}
ch_bwa = Channel.value(file("${params.outdir}/reference_genome/BWAIndex"))
}
process CIRIQUANT_YML{
when:
'ciriquant' in tool && 'circrna_discovery' in module
input:
file(gtf) from ch_gtf
file(fasta) from ch_fasta
file(bwa) from ch_bwa
val(hisat) from ch_hisat
output:
file("travis.yml") into ch_ciriquant_yml
script:
bwa_prefix = fasta.toString() == 'genome.fa' ? fasta.toString() : fasta.toString() - ~/.(fa|fasta)$/
hisat_prefix = fasta.toString() - ~/.(fa|fasta)$/
fasta_path = fasta.toRealPath()
gtf_path = gtf.toRealPath()
bwa_path = bwa.toRealPath()
"""
BWA=`whereis bwa | cut -f2 -d':'`
HISAT2=`whereis hisat2 | cut -f2 -d':'`
STRINGTIE=`whereis stringtie | cut -f2 -d':'`
SAMTOOLS=`whereis samtools | cut -f2 -d':' | awk '{print \$1}'`
touch travis.yml
printf "name: ciriquant\n\
tools:\n\
bwa: \$BWA\n\
hisat2: \$HISAT2\n\
stringtie: \$STRINGTIE\n\
samtools: \$SAMTOOLS\n\n\
reference:\n\
fasta: ${fasta_path}\n\
gtf: ${gtf_path}\n\
bwa_index: ${bwa_path}/${bwa_prefix}\n\
hisat_index: ${hisat}/${hisat_prefix}" >> travis.yml
"""
}
process GENE_ANNOTATION{
tag "${gtf}"
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_reference ? "reference_genome/${it}" : null }
when:
!params.circexplorer2_annotation && params.gtf && ('circexplorer2' || 'mapsplice' in tool) && 'circrna_discovery' in module
input:
file(gtf) from ch_gtf
output:
file("${gtf.baseName}.txt") into ch_gene_txt
script:
"""
wget "https://raw.githubusercontent.com/nf-core/test-datasets/circrna/reference/chrI.gtf"
mv "chrI.gtf.1" "${gtf}"
gtfToGenePred -genePredExt -geneNameAsName2 ${gtf} ${gtf.baseName}.genepred
perl -alne '\$"="\t";print "@F[11,0..9]"' ${gtf.baseName}.genepred > ${gtf.baseName}.txt
"""
}
ch_gene = params.circexplorer2_annotation ? Channel.value(file(params.circexplorer2_annotation)) : ch_gene_txt
/*
================================================================================
Stage Input Data
================================================================================
*/
process BAM_TO_FASTQ{
tag "${base}"
label 'process_medium'
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_qc_intermediates ? "quality_control/SamToFastq/${it}" : null }
when:
params.input_type == 'bam'
input:
tuple val(base), file(bam) from bam_input
output:
tuple val(base), file('*.fq.gz') into fastq_built
script:
"""
picard \\
-Xmx${task.memory.toGiga()}g \\
SamToFastq \\
I=$bam \\
F=${base}_R1.fq.gz \\
F2=${base}_R2.fq.gz \\
VALIDATION_STRINGENCY=LENIENT
"""
}
// fastq_input staged on line 116
if(params.input_type == 'bam'){
(fastqc_reads, trimming_reads, raw_reads) = fastq_built.into(3)
}else if(params.input_type == 'fastq'){
(fastqc_reads, trimming_reads, raw_reads) = fastq_input.into(3)
}
process FASTQC_RAW {
tag "${base}"
label 'process_low'
label 'py3'
input:
tuple val(base), file(fastq) from fastqc_reads
output:
file("*.{html,zip}") into fastqc_raw
script:
"""
fastqc -q $fastq --threads ${task.cpus}
"""
}
/*
================================================================================
BBDUK
================================================================================
*/
process BBDUK {
tag "${base}"
label 'process_medium'
publishDir params.outdir, mode: params.publish_dir_mode, pattern: "*.fq.gz",
saveAs: { params.save_qc_intermediates ? "quality_control/BBDUK/${it}" : null }
when:
params.trim_fastq
input:
tuple val(base), file(fastq) from trimming_reads
path adapters from params.adapters
output:
tuple val(base), file('*.trim.fq.gz') into trim_reads_ch, fastqc_trim_reads
file("*BBDUK.txt") into bbduk_stats_ch
script:
def adapter = params.adapters ? "ref=${params.adapters}" : ''
def k = params.k ? "k=${params.k}" : ''
def ktrim = params.ktrim ? "ktrim=${params.ktrim}" : ''
def hdist = params.hdist ? "hdist=${params.hdist}" : ''
def trimq = params.trimq ? "trimq=${params.trimq}" : ''
def qtrim = params.qtrim ? "qtrim=${params.qtrim}" : ''
def minlen = params.minlen ? "minlen=${params.minlen}" : ''
"""
bbduk.sh \\
-Xmx${task.memory.toGiga()}g \\
threads=${task.cpus} \\
in1=${fastq[0]} \\
in2=${fastq[1]} \\
out1=${base}_R1.trim.fq.gz \\
out2=${base}_R2.trim.fq.gz \\
$adapter \\
$k \\
$ktrim \\
$trimq \\
$qtrim \\
$minlen \\
stats=${base}_BBDUK.txt
"""
}
aligner_reads = params.trim_fastq ? trim_reads_ch : raw_reads
process FASTQC_BBDUK {
tag "${base}"
label 'process_low'
label 'py3'
when:
params.trim_fastq
input:
tuple val(base), file(fastq) from fastqc_trim_reads
output:
file ("*.{html,zip}") into fastqc_trimmed
script:
"""
fastqc -q $fastq --threads ${task.cpus}
"""
}
(star_pass1_reads, star_pass2_reads, find_circ_reads, ciriquant_reads, mapsplice_reads, segemehl_reads, dcc_mate1_reads, dcc_mate2_reads, hisat_reads) = aligner_reads.into(9)
/*
================================================================================
circRNA quantification + annotation
================================================================================
*/
process CIRIQUANT{
tag "${base}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode, pattern: "${base}",
saveAs: { params.save_quantification_intermediates ? "circrna_discovery/CIRIquant/intermediates/${it}" : null }
when:
'ciriquant' in tool && 'circrna_discovery' in module
input:
tuple val(base), file(fastq) from ciriquant_reads
file(ciriquant_yml) from ch_ciriquant_yml
output:
tuple val(base), file("${base}") into ciriquant_intermediates
tuple val(base), val("CIRIquant"), file("${base}_ciriquant_circs.bed") into ciriquant_annotated
tuple val(base), file("${base}_ciriquant.bed") into ciriquant_results
script:
"""
CIRIquant \\
-t ${task.cpus} \\
-1 ${fastq[0]} \\
-2 ${fastq[1]} \\
--config $ciriquant_yml \\
--no-gene \\
-o ${base} \\
-p ${base}
## Apply Filtering
cp ${base}/${base}.gtf .
## extract counts (convert float/double to int [no loss of information])
grep -v "#" ${base}.gtf | awk '{print \$14}' | cut -d '.' -f1 > counts
grep -v "#" ${base}.gtf | awk -v OFS="\t" '{print \$1,\$4,\$5,\$7}' > ${base}.tmp
paste ${base}.tmp counts > ${base}_unfilt.bed
## filter bsj_reads
awk '{if(\$5 >= ${params.bsj_reads}) print \$0}' ${base}_unfilt.bed > ${base}_filt.bed
grep -v '^\$' ${base}_filt.bed > ${base}_ciriquant
## correct offset bp position
awk -v OFS="\t" '{\$2-=1;print}' ${base}_ciriquant > ${base}_ciriquant.bed
rm ${base}.gtf
## Re-work for Annotation
awk -v OFS="\t" '{print \$1, \$2, \$3, \$1":"\$2"-"\$3":"\$4, \$5, \$4}' ${base}_ciriquant.bed > ${base}_ciriquant_circs.bed
"""
}
process STAR_1PASS{
tag "${base}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode, pattern: "${base}",
saveAs: { params.save_quantification_intermediates ? "circrna_discovery/STAR/1st_Pass/${it}" : null }
when:
('circexplorer2' in tool || 'circrna_finder' in tool || 'dcc' in tool) && 'circrna_discovery' in module
input:
tuple val(base), file(reads) from star_pass1_reads
file(star_idx) from ch_star
output:
file("${base}/*SJ.out.tab") into sjdb_ch
file("${base}") into star_1st_pass_output
script:
def readFilesCommand = reads[0].toString().endsWith('.gz') ? "--readFilesCommand zcat" : ''
"""
mkdir -p ${base}
STAR \\
--alignIntronMax ${params.alignIntronMax} \\
--alignIntronMin ${params.alignIntronMin} \\
--alignMatesGapMax ${params.alignMatesGapMax} \\
--alignSJDBoverhangMin ${params.alignSJDBoverhangMin} \\
--alignSJoverhangMin ${params.alignSJoverhangMin} \\
--alignSoftClipAtReferenceEnds ${params.alignSoftClipAtReferenceEnds} \\
--alignTranscriptsPerReadNmax ${params.alignTranscriptsPerReadNmax} \\
--chimJunctionOverhangMin ${params.chimJunctionOverhangMin} \\
--chimOutType Junctions SeparateSAMold \\
--chimScoreMin ${params.chimScoreMin} \\
--chimScoreSeparation ${params.chimScoreSeparation} \\
--chimSegmentMin ${params.chimSegmentMin} \\
--genomeDir ${star_idx} \\
--genomeLoad ${params.genomeLoad} \\
--limitSjdbInsertNsj ${params.limitSjdbInsertNsj} \\
--outFileNamePrefix ${base}/${base}. \\
--outFilterMatchNminOverLread ${params.outFilterMatchNminOverLread} \\
--outFilterMismatchNoverLmax ${params.outFilterMismatchNoverLmax} \\
--outFilterMultimapNmax ${params.outFilterMultimapNmax} \\
--outFilterMultimapScoreRange ${params.outFilterMultimapScoreRange} \\
--outFilterScoreMinOverLread ${params.outFilterScoreMinOverLread} \\
--outFilterType BySJout \\
--outReadsUnmapped None \\
--outSAMtype BAM SortedByCoordinate \\
--outSAMunmapped Within \\
--outSJfilterOverhangMin ${params.outSJfilterOverhangMin} \\
${readFilesCommand} \\
--readFilesIn ${reads} \\
--runThreadN ${task.cpus} \\
--sjdbScore ${params.sjdbScore} \\
--winAnchorMultimapNmax ${params.winAnchorMultimapNmax}
"""
}
process SJDB_FILE{
tag "${sjdb}"
publishDir params.outdir, mode: params.publish_dir_mode,
saveAs: { params.save_quantification_intermediates ? "circrna_discovery/STAR/SJFile/${it}" : null }
when:
('circexplorer2' in tool || 'circrna_finder' in tool || 'dcc' in tool) && 'circrna_discovery' in module
input:
file(sjdb) from sjdb_ch
output:
file("*SJFile.tab") into sjdbfile_ch
shell:
'''
base=$(basename !{sjdb} .SJ.out.tab)
awk 'BEGIN {OFS="\t"; strChar[0]="."; strChar[1]="+"; strChar[2]="-";} {if($5>0){print $1,$2,$3,strChar[$4]}}' !{sjdb} > ${base}.SJFile.tab
'''
}
(sjdbfile_pass2, sjdbfile_mate1, sjdbfile_mate2) = sjdbfile_ch.into(3)
process STAR_2PASS{
tag "${base}"
label 'process_high'
publishDir params.outdir, mode: params.publish_dir_mode, pattern: "${base}",
saveAs: { params.save_quantification_intermediates ? "circrna_discovery/STAR/2nd_Pass/${it}" : null }
when:
('circexplorer2' in tool || 'circrna_finder' in tool || 'dcc' in tool) && 'circrna_discovery' in module
input:
tuple val(base), file(reads) from star_pass2_reads
file(sjdbfile) from sjdbfile_pass2.collect()
file(star_idx) from ch_star
output:
tuple val(base), file("${base}/${base}.Chimeric.out.junction") into circexplorer2_input
tuple val(base), file("${base}") into circrna_finder_input, dcc_pairs
script:
def readFilesCommand = reads[0].toString().endsWith('.gz') ? "--readFilesCommand zcat" : ''
"""
mkdir -p ${base}
STAR \\
--alignIntronMax ${params.alignIntronMax} \\