-
Notifications
You must be signed in to change notification settings - Fork 120
/
main.nf
268 lines (225 loc) · 9.99 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
//
// Subworkflow with functionality specific to the nf-core/atacseq pipeline
//
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT FUNCTIONS / MODULES / SUBWORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
include { UTILS_NFVALIDATION_PLUGIN } from '../../nf-core/utils_nfvalidation_plugin'
include { paramsSummaryMap } from 'plugin/nf-validation'
include { UTILS_NEXTFLOW_PIPELINE } from '../../nf-core/utils_nextflow_pipeline'
include { completionEmail } from '../../nf-core/utils_nfcore_pipeline'
include { completionSummary } from '../../nf-core/utils_nfcore_pipeline'
include { dashedLine } from '../../nf-core/utils_nfcore_pipeline'
include { nfCoreLogo } from '../../nf-core/utils_nfcore_pipeline'
include { imNotification } from '../../nf-core/utils_nfcore_pipeline'
include { UTILS_NFCORE_PIPELINE } from '../../nf-core/utils_nfcore_pipeline'
include { workflowCitation } from '../../nf-core/utils_nfcore_pipeline'
/*
========================================================================================
SUBWORKFLOW TO INITIALISE PIPELINE
========================================================================================
*/
workflow PIPELINE_INITIALISATION {
take:
version // boolean: Display version and exit
help // boolean: Display help text
validate_params // boolean: Boolean whether to validate parameters against the schema at runtime
monochrome_logs // boolean: Do not use coloured log outputs
nextflow_cli_args // array: List of positional nextflow CLI args
outdir // string: The output directory where the results will be saved
main:
//
// Print version and exit if required and dump pipeline parameters to JSON file
//
UTILS_NEXTFLOW_PIPELINE (
version,
true,
outdir,
workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1
)
//
// Validate parameters and generate parameter summary to stdout
//
pre_help_text = nfCoreLogo(monochrome_logs)
post_help_text = '\n' + workflowCitation() + '\n' + dashedLine(monochrome_logs)
def String workflow_command = "nextflow run ${workflow.manifest.name} -profile <docker/singularity/.../institute> --input samplesheet.csv --genome GRCh37 --outdir <OUTDIR>"
UTILS_NFVALIDATION_PLUGIN (
help,
workflow_command,
pre_help_text,
post_help_text,
validate_params,
"nextflow_schema.json"
)
//
// Check config provided to the pipeline
//
UTILS_NFCORE_PIPELINE (
nextflow_cli_args
)
//
// Custom validation for pipeline parameters
//
validateInputParameters()
}
/*
========================================================================================
SUBWORKFLOW FOR PIPELINE COMPLETION
========================================================================================
*/
workflow PIPELINE_COMPLETION {
take:
email // string: email address
email_on_fail // string: email address sent on pipeline failure
plaintext_email // boolean: Send plain-text email instead of HTML
outdir // path: Path to output directory where results will be published
monochrome_logs // boolean: Disable ANSI colour codes in log output
hook_url // string: hook URL for notifications
multiqc_report // string: Path to MultiQC report
main:
summary_params = paramsSummaryMap(workflow, parameters_schema: "nextflow_schema.json")
//
// Completion email and summary
//
workflow.onComplete {
if (email || email_on_fail) {
completionEmail(summary_params, email, email_on_fail, plaintext_email, outdir, monochrome_logs, multiqc_report.toList())
}
completionSummary(monochrome_logs)
if (hook_url) {
imNotification(summary_params, hook_url)
}
}
workflow.onError {
log.error "Pipeline failed. Please refer to troubleshooting docs: https://nf-co.re/docs/usage/troubleshooting"
}
}
/*
========================================================================================
FUNCTIONS
========================================================================================
*/
//
// Check and validate pipeline parameters
//
def validateInputParameters() {
genomeExistsError()
if (!params.fasta) {
error("Genome fasta file not specified with e.g. '--fasta genome.fa' or via a detectable config file.")
}
if (!params.gtf && !params.gff) {
error("No GTF or GFF3 annotation specified! The pipeline requires at least one of these files.")
}
if (params.gtf && params.gff) {
gtfGffWarn(log)
}
if (!params.macs_gsize) {
macsGsizeWarn(log)
}
if (!params.read_length && !params.macs_gsize) {
error ("Both '--read_length' and '--macs_gsize' not specified! Please specify either to infer MACS2 genome size for peak calling.")
}
}
//
// Get attribute from genome config file e.g. fasta
//
def getGenomeAttribute(attribute) {
if (params.genomes && params.genome && params.genomes.containsKey(params.genome)) {
if (params.genomes[ params.genome ].containsKey(attribute)) {
return params.genomes[ params.genome ][ attribute ]
}
}
return null
}
//
// Exit pipeline if incorrect --genome key provided
//
def genomeExistsError() {
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
def error_string = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome '${params.genome}' not found in any config files provided to the pipeline.\n" +
" Currently, the available genome keys are:\n" +
" ${params.genomes.keySet().join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
error(error_string)
}
}
//
// Get macs genome size (macs_gsize)
//
def getMacsGsize(params) {
def val = null
if (params.genomes && params.genome && params.genomes.containsKey(params.genome)) {
if (params.genomes[ params.genome ].containsKey('macs_gsize')) {
if (params.genomes[ params.genome ][ 'macs_gsize' ].containsKey(params.read_length.toString())) {
val = params.genomes[ params.genome ][ 'macs_gsize' ][ params.read_length.toString() ]
}
}
}
return val
}
//
// Generate methods description for MultiQC
//
def toolCitationText() {
// TODO nf-core: Optionally add in-text citation tools to this list.
// Can use ternary operators to dynamically construct based conditions, e.g. params["run_xyz"] ? "Tool (Foo et al. 2023)" : "",
// Uncomment function in methodsDescriptionText to render in MultiQC report
def citation_text = [
"Tools used in the workflow included:",
"FastQC (Andrews 2010),",
"MultiQC (Ewels et al. 2016)",
"."
].join(' ').trim()
return citation_text
}
def toolBibliographyText() {
// TODO nf-core: Optionally add bibliographic entries to this list.
// Can use ternary operators to dynamically construct based conditions, e.g. params["run_xyz"] ? "<li>Author (2023) Pub name, Journal, DOI</li>" : "",
// Uncomment function in methodsDescriptionText to render in MultiQC report
def reference_text = [
"<li>Andrews S, (2010) FastQC, URL: https://www.bioinformatics.babraham.ac.uk/projects/fastqc/).</li>",
"<li>Ewels, P., Magnusson, M., Lundin, S., & Käller, M. (2016). MultiQC: summarize analysis results for multiple tools and samples in a single report. Bioinformatics , 32(19), 3047–3048. doi: /10.1093/bioinformatics/btw354</li>"
].join(' ').trim()
return reference_text
}
def methodsDescriptionText(mqc_methods_yaml) {
// Convert to a named map so can be used as with familar NXF ${workflow} variable syntax in the MultiQC YML file
def meta = [:]
meta.workflow = workflow.toMap()
meta["manifest_map"] = workflow.manifest.toMap()
// Pipeline DOI
meta["doi_text"] = meta.manifest_map.doi ? "(doi: <a href=\'https://doi.org/${meta.manifest_map.doi}\'>${meta.manifest_map.doi}</a>)" : ""
meta["nodoi_text"] = meta.manifest_map.doi ? "": "<li>If available, make sure to update the text to include the Zenodo DOI of version of the pipeline used. </li>"
// Tool references
meta["tool_citations"] = ""
meta["tool_bibliography"] = ""
// TODO nf-core: Only uncomment below if logic in toolCitationText/toolBibliographyText has been filled!
// meta["tool_citations"] = toolCitationText().replaceAll(", \\.", ".").replaceAll("\\. \\.", ".").replaceAll(", \\.", ".")
// meta["tool_bibliography"] = toolBibliographyText()
def methods_text = mqc_methods_yaml.text
def engine = new groovy.text.SimpleTemplateEngine()
def description_html = engine.createTemplate(methods_text).make(meta)
return description_html.toString()
}
//
// Print a warning if both GTF and GFF have been provided
//
def gtfGffWarn(log) {
log.warn "=============================================================================\n" +
" Both '--gtf' and '--gff' parameters have been provided.\n" +
" Using GTF file as priority.\n" +
"==================================================================================="
}
//
// Print a warning if macs_gsize parameter has not been provided
//
def macsGsizeWarn(log) {
log.warn "=============================================================================\n" +
" --macs_gsize parameter has not been provided.\n" +
" It will be auto-calculated by 'khmer unique-kmers.py' using the '--read_length' parameter.\n" +
" Explicitly provide '--macs_gsize macs2_genome_size' to change this behaviour.\n" +
"==================================================================================="
}