generated from marchoeppner/nf-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
129 lines (103 loc) · 4.15 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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
/**
===============================
GABI Pipeline
===============================
This Pipeline performs assembly of bacterial isolates from NGS reads and performs typing
### Homepage / git
git@github.com:marchoeppner/gabi.git
**/
// Pipeline version
params.version = workflow.manifest.version
summary = [:]
run_name = (params.run_name == false) ? "${workflow.sessionId}" : "${params.run_name}"
WorkflowMain.initialise(workflow, params, log)
WorkflowPipeline.initialise(params, log)
include { GABI } from './workflows/gabi'
include { BUILD_REFERENCES } from './workflows/build_references'
multiqc_report = Channel.from([])
workflow {
if (params.build_references) {
BUILD_REFERENCES()
} else {
GABI()
multiqc_report = multiqc_report.mix(GABI.out.qc).toList()
}
}
workflow.onComplete {
hline = '========================================='
log.info hline
log.info "Duration: $workflow.duration"
log.info hline
emailFields = [:]
emailFields['version'] = workflow.manifest.version
emailFields['session'] = workflow.sessionId
emailFields['runName'] = run_name
emailFields['success'] = workflow.success
emailFields['dateStarted'] = workflow.start
emailFields['dateComplete'] = workflow.complete
emailFields['duration'] = workflow.duration
emailFields['exitStatus'] = workflow.exitStatus
emailFields['errorMessage'] = (workflow.errorMessage ?: 'None')
emailFields['errorReport'] = (workflow.errorReport ?: 'None')
emailFields['commandLine'] = workflow.commandLine
emailFields['projectDir'] = workflow.projectDir
emailFields['script_file'] = workflow.scriptFile
emailFields['launchDir'] = workflow.launchDir
emailFields['user'] = workflow.userName
emailFields['Pipeline script hash ID'] = workflow.scriptId
emailFields['manifest'] = workflow.manifest
emailFields['summary'] = summary
email_info = ''
for (s in emailFields) {
email_info += "\n${s.key}: ${s.value}"
}
outputDir = new File("${params.outdir}/pipeline_info/")
if (!outputDir.exists()) {
outputDir.mkdirs()
}
outputTf = new File(outputDir, 'pipeline_report.txt')
outputTf.withWriter { w -> w << email_info }
// make txt template
engine = new groovy.text.GStringTemplateEngine()
tf = new File("$baseDir/assets/email_template.txt")
txtTemplate = engine.createTemplate(tf).make(emailFields)
emailText = txtTemplate.toString()
// make email template
hf = new File("$baseDir/assets/email_template.html")
htmlTemplate = engine.createTemplate(hf).make(emailFields)
emailHtml = htmlTemplate.toString()
subject = "Pipeline finished ($run_name)."
if (params.email) {
mqcReport = null
try {
if (workflow.success && !params.skip_multiqc) {
mqcReport = multiqc_report.getVal()
if (mqcReport.getClass() == ArrayList) {
// TODO: Update name of pipeline
log.warn "[Pipeline] Found multiple reports from process 'multiqc', will use only one"
mqcReport = mqcReport[0]
}
}
} catch (all) {
// TODO: Update name of pipeline
log.warn '[PipelineName] Could not attach MultiQC report to summary email'
}
smailFields = [ email: params.email, subject: subject, emailText: emailText,
emailHtml: emailHtml, baseDir: "$baseDir", mqcFile: mqcReport,
mqcMaxSize: params.maxMultiqcEmailFileSize.toBytes()
]
sf = new File("$baseDir/assets/sendmailTemplate.txt")
sendmailTemplate = engine.createTemplate(sf).make(smailFields)
sendmailHtml = sendmailTemplate.toString()
try {
if (params.plaintext_email) { throw GroovyException('Send plaintext e-mail, not HTML') }
// Try to send HTML e-mail using sendmail
[ 'sendmail', '-t' ].execute() << sendmailHtml
} catch (all) {
// Catch failures and try with plaintext
[ 'mail', '-s', subject, params.email ].execute() << emailText
}
}
}