forked from nf-core/rnafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
760 lines (650 loc) · 25.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
#!/usr/bin/env nextflow
/*
========================================================================================
nf-core/rnafusion
========================================================================================
nf-core/rnafusion Analysis Pipeline.
#### Homepage / Documentation
https://github.com/nf-core/rnafusion
----------------------------------------------------------------------------------------
*/
nfcore_logo = """=======================================================
,--./,-.
___ __ __ __ ___ /,-._.--~\'
|\\ | |__ __ / ` / \\ |__) |__ } {
| \\| | \\__, \\__/ | \\ |___ \\`-._,-`-,
`._,._,\'
nf-core/rnafusion v${workflow.manifest.version}
======================================================="""
def helpMessage() {
nfcore_help = """
Usage:
The typical command for running the pipeline is as follows:
nextflow run nf-core/rnafusion --reads '*_R{1,2}.fastq.gz' -profile docker
Mandatory arguments:
--reads Path to input data (must be surrounded with quotes)
-profile Configuration profile to use. Can use multiple (comma separated)
Available: standard, conda, docker, singularity, awsbatch, test
Tool flags:
--star_fusion Run STAR-Fusion
--star_fusion_opt Extra parameter for STAR-Fusion
--fusioncatcher Run FusionCatcher
--fusioncatcher_opt Extra parameters for FusionCatcher
--ericscript Run Ericscript
--pizzly Run Pizzly
--squid Run Squid
--debug Flag to run only specific fusion tool/s and not the whole pipeline. Only works on tool flags.
--databases Database path for fusion-report
--fusion_report_opt fusion-report extra parameters
Visualization flags:
--fusion_inspector Run Fusion-Inspector
References If not specified in the configuration file or you wish to overwrite any of the references.
--fasta Path to Fasta reference
--gtf Path to GTF annotation
--star_index Path to STAR-Index reference
--star_fusion_ref Path to STAR-Fusion reference
--fusioncatcher_ref Path to Fusioncatcher reference
--ericscript_ref Path to Ericscript reference
--pizzly_fasta Path to Pizzly FASTA reference
--pizzly_gtf Path to Pizzly GTF annotation
Options:
--genome Name of iGenomes reference
--read_length Length of the reads. Default: 100
--singleEnd Specifies that the input is single end reads
Other Options:
--outdir The output directory where the results will be saved
--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()
log.info "${nfcore_logo}${nfcore_help}"
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help emssage
if (params.help){
helpMessage()
exit 0
}
// Configurable variables
params.name = false
params.fasta = params.genome ? params.genomes[ params.genome ].fasta ?: false : false
params.gtf = params.genome ? params.genomes[ params.genome ].gtf ?: false : false
params.running_tools = []
params.multiqc_config = "$baseDir/conf/multiqc_config.yaml"
params.email = false
params.plaintext_email = false
multiqc_config = file(params.multiqc_config)
output_docs = file("$baseDir/docs/output.md")
// Reference variables required by tools
// These are needed in order to run the pipeline
fasta = false
gtf = false
pizzly_fasta = false
pizzly_gtf = false
star_fusion_ref = false
fusioncatcher_ref = false
fusion_inspector_ref = false
ericscript_ref = false
// 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!"
}
// 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!"
}
// Validate pipeline variables
// These variable have to be defined in the profile configuration which is referenced in nextflow.config
if (params.fasta) {
fasta = file(params.fasta)
if(!fasta.exists()) exit 1, "Fasta file not found: ${params.fasta}"
}
if (params.gtf) {
gtf = file(params.gtf)
if(!gtf.exists()) exit 1, "GTF file not found: ${params.fasta}"
}
if (!params.star_index && (!params.fasta && !params.gtf)) {
exit 1, "Either specify STAR-INDEX or fasta and gtf file!"
}
if (!params.databases) {
exit 1, "Database path for fusion-report has to be specified!"
}
if (params.star_fusion) {
params.running_tools.add("STAR-Fusion")
if (!params.star_fusion_ref) {
exit 1, "Star-Fusion reference not specified!"
} else {
star_fusion_ref = Channel
.fromPath(params.star_fusion_ref)
.ifEmpty { exit 1, "Star-Fusion reference directory not found!" }
}
}
if (params.fusioncatcher) {
params.running_tools.add("Fusioncatcher")
if (!params.fusioncatcher_ref) {
exit 1, "Fusioncatcher data directory not specified!"
} else {
fusioncatcher_ref = Channel
.fromPath(params.fusioncatcher_ref)
.ifEmpty { exit 1, "Fusioncatcher data directory not found!" }
}
}
if (params.ericscript) {
params.running_tools.add("Ericscript")
if (!params.ericscript_ref) {
exit 1, "Reference not specified!"
} else {
ericscript_ref = Channel
.fromPath(params.ericscript_ref)
.ifEmpty { exit 1, "Ericscript reference not found" }
}
}
if (params.pizzly) {
params.running_tools.add("Pizzly")
if (params.pizzly_fasta) {
pizzly_fasta = Channel
.fromPath(params.pizzly_fasta)
.ifEmpty { exit 1, "Pizzly FASTA file not found!" }
}
if (params.pizzly_gtf) {
pizzly_gtf = Channel
.fromPath(params.pizzly_gtf)
.ifEmpty { exit 1, "Pizzly GTF file not found!" }
}
}
if (params.squid) {
params.running_tools.add("Squid")
if (!gtf) {
exit 1, "Missing GTF annotation file for squid!"
}
}
if (params.fusion_inspector) {
params.running_tools.add("FusionInspector")
if (!params.star_fusion_ref) {
exit 1, "Reference not specified (using star-fusion reference path)!"
} else {
fusion_inspector_ref = Channel
.fromPath(params.star_fusion_ref)
.ifEmpty { exit 1, "Fusion-Inspector reference not found" }
}
}
/*
* Create a channel for input read files
*/
Channel
.fromFilePairs( params.reads, size: params.singleEnd ? 1 : 2 )
.ifEmpty { exit 1, "Cannot find any reads matching: ${params.reads}\nNB: Path needs to be enclosed in quotes!\nIf this is single-end data, please specify --singleEnd on the command line." }
.into { read_files_fastqc; read_files_summary; read_files_multiqc; read_files_star_fusion; read_files_fusioncatcher;
read_files_gfusion; read_files_fusion_inspector; read_files_ericscript; read_files_pizzly; read_files_squid }
// Header log info
log.info nfcore_logo
def summary = [:]
summary['Pipeline Name'] = 'nf-core/rnafusion'
summary['Pipeline Version'] = workflow.manifest.version
summary['Run Name'] = custom_runName ?: workflow.runName
summary['Reads'] = params.reads
summary['Fasta Ref'] = params.fasta
summary['GTF Ref'] = params.gtf
summary['STAR Index'] = params.star_index ? params.star_index : 'Not specified, building'
summary['Tools'] = params.running_tools.size() == 0 ? 'None' : params.running_tools.join(", ")
summary['Data Type'] = params.singleEnd ? 'Single-End' : 'Paired-End'
summary['Max Memory'] = params.max_memory
summary['Max CPUs'] = params.max_cpus
summary['Max Time'] = params.max_time
summary['Output dir'] = params.outdir
summary['Working dir'] = workflow.workDir
summary['Container Engine'] = workflow.containerEngine
if(workflow.containerEngine) summary['Container'] = workflow.container
summary['Current home'] = "$HOME"
summary['Current user'] = "$USER"
summary['Current path'] = "$PWD"
summary['Working dir'] = workflow.workDir
summary['Output dir'] = params.outdir
summary['Script dir'] = workflow.projectDir
summary['Config Profile'] = workflow.profile
if(workflow.profile == 'awsbatch'){
summary['AWS Region'] = params.awsregion
summary['AWS Queue'] = params.awsqueue
}
if(params.email) summary['E-mail Address'] = params.email
log.info summary.collect { k,v -> "${k.padRight(15)}: $v" }.join("\n")
log.info "========================================="
def create_workflow_summary(summary) {
def yaml_file = workDir.resolve('workflow_summary_mqc.yaml')
yaml_file.text = """
id: 'nf-core-rnafusion-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'nf-core/rnafusion Workflow Summary'
section_href: 'https://github.com/nf-core/rnafusion'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
${summary.collect { k,v -> " <dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }.join("\n")}
</dl>
""".stripIndent()
return yaml_file
}
/*************************************************************
* PREPROCESSING
************************************************************/
/*
* Build STAR index
*/
if (params.star_index) {
Channel
.fromPath(params.star_index)
.ifEmpty { exit 1, "STAR index not found: ${params.star_index}" }
.into { star_index_squid; star_index_star_fusion }
} else {
process build_star_index {
tag "$fasta"
publishDir "${params.outdir}/star_index", mode: 'copy'
input:
file fasta
file gtf
output:
file "star" into star_index_squid, star_index_star_fusion
script:
def avail_mem = task.memory ? "--limitGenomeGenerateRAM ${task.memory.toBytes() - 100000000}" : ''
"""
mkdir star
STAR \\
--runMode genomeGenerate \\
--runThreadN ${task.cpus} \\
--sjdbGTFfile ${gtf} \\
--sjdbOverhang ${params.read_length - 1} \\
--genomeDir star/ \\
--genomeFastaFiles ${fasta} \\
$avail_mem
"""
}
}
/*************************************************************
* Fusion pipeline
************************************************************/
/*
* STAR-Fusion
*/
process star_fusion {
tag "$name"
publishDir "${params.outdir}/tools/StarFusion", mode: 'copy'
when:
params.star_fusion || (params.star_fusion && params.debug)
input:
set val(name), file(reads) from read_files_star_fusion
file star_index_star_fusion
file reference from star_fusion_ref
output:
file '*fusion_predictions.tsv' into star_fusion_fusions
file '*.{tsv,txt}' into star_fusion_output
script:
def avail_mem = task.memory ? "--limitBAMsortRAM ${task.memory.toBytes() - 100000000}" : ''
option = params.singleEnd ? "--left_fq ${reads[0]}" : "--left_fq ${reads[0]} --right_fq ${reads[1]}"
def extra_params = params.star_fusion_opt ? "${params.star_fusion_opt}" : ''
"""
STAR \\
--genomeDir ${star_index_star_fusion} \\
--readFilesIn ${reads} \\
--twopassMode Basic \\
--outReadsUnmapped None \\
--chimSegmentMin 12 \\
--chimJunctionOverhangMin 12 \\
--alignSJDBoverhangMin 10 \\
--alignMatesGapMax 100000 \\
--alignIntronMax 100000 \\
--chimSegmentReadGapMax 3 \\
--alignSJstitchMismatchNmax 5 -1 5 5 \\
--runThreadN ${task.cpus} \\
--outSAMstrandField intronMotif ${avail_mem} \\
--readFilesCommand zcat \\
--chimOutJunctionFormat 1
STAR-Fusion \\
--genome_lib_dir ${reference} \\
-J Chimeric.out.junction \\
${option} \\
--CPU ${task.cpus} \\
--examine_coding_effect \\
--output_dir . ${extra_params}
"""
}
/*
* Fusioncatcher
*/
process fusioncatcher {
tag "$name"
publishDir "${params.outdir}/tools/Fusioncatcher", mode: 'copy'
when:
params.fusioncatcher || (params.fusioncatcher && params.debug)
input:
set val(name), file(reads) from read_files_fusioncatcher
file data_dir from fusioncatcher_ref
output:
file 'final-list_candidate-fusion-genes.txt' into fusioncatcher_fusions
file '*.{txt,zip,log}' into fusioncatcher_output
script:
option = params.singleEnd ? reads[0] : "${reads[0]},${reads[1]}"
def extra_params = params.fusioncatcher_opt ? "${params.fusioncatcher_opt}" : ''
"""
fusioncatcher \\
-d ${data_dir} \\
-i ${option} \\
--threads ${task.cpus} \\
-o . \\
--skip-blat ${extra_params}
"""
}
/*
* Ericscript
*/
process ericscript {
tag "$name"
publishDir "${params.outdir}/tools/Ericscript", mode: 'copy'
when:
params.ericscript && (!params.singleEnd || params.debug)
input:
set val(name), file(reads) from read_files_ericscript
file reference from ericscript_ref
output:
file './tmp/fusions.results.filtered.tsv' into ericscript_fusions
file './tmp/fusions.results.total.tsv' into ericscript_output
script:
"""
ericscript.pl \\
-db ${reference} \\
-name fusions \\
-p ${task.cpus} \\
-o ./tmp \\
${reads[0]} \\
${reads[1]}
"""
}
/*
* Pizzly
*/
process pizzly {
tag "$name"
publishDir "${params.outdir}/tools/Pizzly", mode: 'copy'
when:
params.pizzly && (!params.singleEnd || params.debug)
input:
set val(name), file(reads) from read_files_pizzly
file fasta from pizzly_fasta
file gtf from pizzly_gtf
output:
file 'pizzly_fusions.txt' into pizzly_fusions
file '*.{json,txt}' into pizzly_output
script:
"""
kallisto index -i index.idx -k ${params.pizzly_k} ${fasta}
kallisto quant -t ${task.cpus} -i index.idx --fusion -o output ${reads[0]} ${reads[1]}
pizzly -k ${params.pizzly_k} \\
--gtf ${gtf} \\
--cache index.cache.txt \\
--align-score 2 \\
--insert-size 400 \\
--fasta ${fasta} \\
--output pizzly_fusions output/fusion.txt
pizzly_flatten_json.py pizzly_fusions.json pizzly_fusions.txt
"""
}
/*
* Squid
*/
process squid {
tag "$name"
publishDir "${params.outdir}/tools/Squid", mode: 'copy'
when:
params.squid && (!params.singleEnd || params.debug)
input:
set val(name), file(reads) from read_files_squid
file star_index_squid
file gtf
output:
file '*_annotated.txt' into squid_fusions
file '*.txt' into squid_output
script:
def avail_mem = task.memory ? "--limitBAMsortRAM ${task.memory.toBytes() - 100000000}" : ''
"""
STAR \\
--genomeDir ${star_index_squid} \\
--sjdbGTFfile ${gtf} \\
--runThreadN ${task.cpus} \\
--readFilesIn ${reads[0]} ${reads[1]} \\
--twopassMode Basic \\
--chimOutType SeparateSAMold --chimSegmentMin 20 --chimJunctionOverhangMin 12 --alignSJDBoverhangMin 10 --outReadsUnmapped Fastx --outSAMstrandField intronMotif \\
--outSAMtype BAM SortedByCoordinate ${avail_mem} \\
--readFilesCommand zcat
mv Aligned.sortedByCoord.out.bam ${name}Aligned.sortedByCoord.out.bam
samtools view -bS Chimeric.out.sam > ${name}Chimeric.out.bam
squid -b ${name}Aligned.sortedByCoord.out.bam -c ${name}Chimeric.out.bam -o fusions
AnnotateSQUIDOutput.py ${gtf} fusions_sv.txt fusions_annotated.txt
"""
}
/*************************************************************
* Summarizing results from tools
************************************************************/
process summary {
tag "$name"
publishDir "${params.outdir}/Report-${name}", mode: 'copy'
when:
!params.debug && (params.fusioncatcher || params.star_fusion || params.ericscript || params.pizzly || params.squid)
input:
set val(name), file(reads) from read_files_summary
file fusioncatcher from fusioncatcher_fusions.ifEmpty('')
file starfusion from star_fusion_fusions.ifEmpty('')
file ericscript from ericscript_fusions.ifEmpty('')
file pizzly from pizzly_fusions.ifEmpty('')
file squid from squid_fusions.ifEmpty('')
output:
file 'fusions_list.txt' into fusion_inspector_input_list
file 'fusion_genes_mqc.json' into summary_fusions_mq
file '*' into report
script:
def extra_params = params.fusion_report_opt ? "${params.fusion_report_opt}" : ''
def tools = params.fusioncatcher ? "--fusioncatcher ${fusioncatcher} " : ''
tools += params.star_fusion ? "--starfusion ${starfusion} " : ''
tools += params.ericscript ? "--ericscript ${ericscript} " : ''
tools += params.pizzly ? "--pizzly ${pizzly} " : ''
tools += params.squid ? "--squid ${squid} " : ''
"""
fusion_report run ${name} . ${params.databases} \\
${tools} ${extra_params}
"""
}
/*************************************************************
* Visualization
************************************************************/
/*
* Fusion Inspector
*/
process fusion_inspector {
tag "$name"
publishDir "${params.outdir}/tools/FusionInspector", mode: 'copy'
when:
params.fusion_inspector && (!params.singleEnd || params.debug)
input:
set val(name), file(reads) from read_files_fusion_inspector
file reference from fusion_inspector_ref
file fusion_inspector_input_list
output:
file '*.{fa,gtf,bed,bam,bai,txt}' into fusion_inspector_output
script:
"""
FusionInspector \\
--fusions ${fusion_inspector_input_list} \\
--genome_lib ${reference} \\
--left_fq ${reads[0]} \\
--right_fq ${reads[1]} \\
--CPU ${task.cpus} \\
--out_dir . \\
--out_prefix finspector \\
--prep_for_IGV
"""
}
/*************************************************************
* Building report
************************************************************/
/*
* Parse software version numbers
*/
process get_software_versions {
when:
!params.debug
output:
file 'software_versions_mqc.yaml' into software_versions_yaml
script:
"""
echo $workflow.manifest.version > v_pipeline.txt
echo $workflow.nextflow.version > v_nextflow.txt
fastqc --version > v_fastqc.txt
multiqc --version > v_multiqc.txt
cat $baseDir/tools/fusioncatcher/environment.yml > v_fusioncatcher.txt
cat $baseDir/tools/fusion-inspector/environment.yml > v_fusion_inspector.txt
cat $baseDir/tools/star-fusion/environment.yml > v_star_fusion.txt
cat $baseDir/tools/ericscript/environment.yml > v_ericscript.txt
cat $baseDir/tools/pizzly/environment.yml > v_pizzly.txt
cat $baseDir/tools/squid/environment.yml > v_squid.txt
cat $baseDir/environment.yml > v_fusion_report.txt
scrape_software_versions.py > software_versions_mqc.yaml
"""
}
/*
* FastQC
*/
process fastqc {
tag "$name"
publishDir "${params.outdir}/fastqc", mode: 'copy',
saveAs: {filename -> filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename"}
when:
!params.debug
input:
set val(name), file(reads) from read_files_fastqc
output:
file "*_fastqc.{zip,html}" into fastqc_results
script:
"""
fastqc -q $reads
"""
}
/*
* MultiQC
*/
process multiqc {
tag "$name"
publishDir "${params.outdir}/MultiQC", mode: 'copy'
when:
!params.debug
input:
set val(name), file(reads) from read_files_multiqc
file multiqc_config
file ('fastqc/*') from fastqc_results.collect()
file ('software_versions/*') from software_versions_yaml
file workflow_summary from create_workflow_summary(summary)
file fusions_mq from summary_fusions_mq.ifEmpty('')
output:
file "*multiqc_report.html" into multiqc_report
file "*_data"
script:
rtitle = custom_runName ? "--title \"$custom_runName\"" : ''
rfilename = custom_runName ? "--filename " + custom_runName.replaceAll('\\W','_').replaceAll('_+','_') + "_multiqc_report" : ''
"""
multiqc -f $rtitle $rfilename --config $multiqc_config .
"""
}
/*
* Output Description HTML
*/
process output_documentation {
publishDir "${params.outdir}/Documentation", mode: 'copy'
when:
!params.debug
input:
file output_docs
output:
file "results_description.html"
script:
"""
markdown_to_html.r $output_docs results_description.html
"""
}
/*
* Completion e-mail notification
*/
workflow.onComplete {
// Set up the e-mail variables
def subject = "[nf-core/rnafusion] Successful: $workflow.runName"
if(!workflow.success){
subject = "[nf-core/rnafusion] FAILED: $workflow.runName"
}
def email_fields = [:]
email_fields['version'] = workflow.manifest.version
email_fields['runName'] = custom_runName ?: workflow.runName
email_fields['success'] = workflow.success
email_fields['dateComplete'] = workflow.complete
email_fields['duration'] = workflow.duration
email_fields['exitStatus'] = workflow.exitStatus
email_fields['errorMessage'] = (workflow.errorMessage ?: 'None')
email_fields['errorReport'] = (workflow.errorReport ?: 'None')
email_fields['commandLine'] = workflow.commandLine
email_fields['projectDir'] = workflow.projectDir
email_fields['summary'] = summary
email_fields['summary']['Date Started'] = workflow.start
email_fields['summary']['Date Completed'] = workflow.complete
email_fields['summary']['Pipeline script file path'] = workflow.scriptFile
email_fields['summary']['Pipeline script hash ID'] = workflow.scriptId
if(workflow.repository) email_fields['summary']['Pipeline repository Git URL'] = workflow.repository
if(workflow.commitId) email_fields['summary']['Pipeline repository Git Commit'] = workflow.commitId
if(workflow.revision) email_fields['summary']['Pipeline Git branch/tag'] = workflow.revision
email_fields['summary']['Nextflow Version'] = workflow.nextflow.version
email_fields['summary']['Nextflow Build'] = workflow.nextflow.build
email_fields['summary']['Nextflow Compile Timestamp'] = workflow.nextflow.timestamp
// Render the TXT template
def engine = new groovy.text.GStringTemplateEngine()
def tf = new File("$baseDir/assets/email_template.txt")
def txt_template = engine.createTemplate(tf).make(email_fields)
def email_txt = txt_template.toString()
// Render the HTML template
def hf = new File("$baseDir/assets/email_template.html")
def html_template = engine.createTemplate(hf).make(email_fields)
def email_html = html_template.toString()
// Render the sendmail template
def smail_fields = [ email: params.email, subject: subject, email_txt: email_txt, email_html: email_html, baseDir: "$baseDir" ]
def sf = new File("$baseDir/assets/sendmail_template.txt")
def sendmail_template = engine.createTemplate(sf).make(smail_fields)
def sendmail_html = sendmail_template.toString()
// Send the HTML e-mail
if (params.email) {
try {
if( params.plaintext_email ){ throw GroovyException('Send plaintext e-mail, not HTML') }
// Try to send HTML e-mail using sendmail
[ 'sendmail', '-t' ].execute() << sendmail_html
log.info "[nf-core/rnafusion] Sent summary e-mail to $params.email (sendmail)"
} catch (all) {
// Catch failures and try with plaintext
[ 'mail', '-s', subject, params.email ].execute() << email_txt
log.info "[nf-core/rnafusion] Sent summary e-mail to $params.email (mail)"
}
}
// Write summary e-mail HTML to a file
def output_d = new File( "${params.outdir}/Documentation/" )
if( !output_d.exists() ) {
output_d.mkdirs()
}
def output_hf = new File( output_d, "pipeline_report.html" )
output_hf.withWriter { w -> w << email_html }
def output_tf = new File( output_d, "pipeline_report.txt" )
output_tf.withWriter { w -> w << email_txt }
log.info "[nf-core/rnafusion] Pipeline Complete"
}