-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.nf
271 lines (216 loc) · 10.3 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
#!/usr/bin/env nextflow
/*
* Copyright (c) 2020-2021 Centre for Genomic Regulation (CRG)
* and the authors, Jose Espinosa-Carrasco, Paolo Di Tommaso.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
========================================================================================
nf-benchmark
========================================================================================
nf-benchmark Benchmarking Pipeline.
Authors:
Jose Espinosa-Carrasco <[email protected]>
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl = 2
////////////////////////////////////////////////////
/* -- PRINT HELP -- */
////////////////////////////////////////////////////
def json_schema = "$projectDir/nextflow_schema.json"
if (params.help) {
def command = "nextflow run nf-benchmark --pipeline tcoffee profile docker,test_nfb"
log.info Schema.params_help(workflow, params, json_schema, command)
exit 0
}
////////////////////////////////////////////////////
/* -- PRINT PARAMETER SUMMARY -- */
////////////////////////////////////////////////////
def summary_params = Schema.params_summary_map(workflow, params, json_schema)
log.info Schema.params_summary_log(workflow, params, json_schema)
// Check whether pipeline profiles are called
ChecksNfb.check_profiles(params, workflow, log)
ChecksNfb.check_pipeline_config(params, log)
////////////////////////////////////////////////////
/* -- PARAMETER CHECKS -- */
////////////////////////////////////////////////////
// Check that conda channels are set-up correctly
if (params.enable_conda) {
Checks.check_conda_channels(log)
}
// Check AWS batch settings
Checks.aws_batch(workflow, params)
// Check the hostnames against configured profiles
Checks.hostname(workflow, params, log)
// Check genome key exists if provided
// Checks.genome_exists(params, log)
////////////////////////////////////////////////////
/* -- VALIDATE INPUTS -- */
////////////////////////////////////////////////////
// checkPathParamList = [ params.input, params.multiqc_config, params.fasta ]
// for (param in checkPathParamList) { if (param) { file(param, checkIfExists: true) } }
// Check mandatory parameters
// if (params.input) { ch_input = file(params.input) } else { exit 1, 'Input samplesheet not specified!' }
// if (params.fasta) { ch_fasta = file(params.fasta) } else { exit 1, 'Genome fasta file not specified!' }
pipeline_module = file( "${params.pipeline_path}/main.nf" )
if( !pipeline_module.exists() ) exit 1, "ERROR: The selected pipeline is not correctly included in nf-benchmark: ${params.pipeline}"
// Include functions
path_functions = "${workflow.projectDir}/modules/assets/functions.nf"
include { setBenchmark; setInputParam; getData } from path_functions
// Pipeline meta-information from the pipeline
yamlPathPipeline = "${params.pipeline_path}/meta.yml" //TODO check if exists
csvPathMethods = "${workflow.projectDir}/assets/methods2benchmark.csv"
csvPathBenchmarker = "${workflow.projectDir}/assets/dataFormat2benchmark.csv"
csvPathReference = "${workflow.projectDir}/assets/referenceData.csv"
// Dictionary?? //TODO
// Think on cases where it might be more than one input (described on the YAML) //TODO
input_pipeline_param = setInputParam(yamlPathPipeline)
infoBenchmark = setBenchmark(yamlPathPipeline, csvPathMethods, params.pipeline, input_pipeline_param)
// log.info (infoBenchmark) // [benchmarker:bali_score, operation:operation_0492, input_data:data_1233, input_format:format_1929, output_data:data_1384, output_format:format_1984]
/*
* Get name of the input parameter of pipeline
*/
// include setReference from './resources/functions.nf'
benchmark_module = ""
input_benchmark_param = ""
if (!params.skip_benchmark) {
benchmark_path = "${params.benchmarker_path}/${infoBenchmark.benchmarker}"
benchmark_module = file( "${benchmark_path}/main.nf" )
if( !benchmark_module.exists() ) exit 1, "[ERROR]: The selected benchmark is not correctly included in nf-benchmark: ${infoBenchmark.benchmarker}"
// yamlPathBenchmark = "${baseDir}/modules/benchmarkers/${infoBenchmark.benchmarker}/meta.yml"
yamlPathBenchmark = "${benchmark_path}/meta.yml"
input_benchmark_param = setInputParam(yamlPathBenchmark)
}
else {
log.info "INFO: Skip benchmark set to true\n"
}
// Set input and reference data sets
(input_data, ref_data) = getData (infoBenchmark,
csvPathReference,
params.skip_benchmark,
params.path_to_refData)
println (input_data)
println (ref_data)
// return
params[input_pipeline_param] = input_data
if (!params.skip_benchmark) {
params[input_benchmark_param] = ref_data
}
////////////////////////////////////////////////////
/* -- CONFIG FILES -- */
////////////////////////////////////////////////////
ch_multiqc_config = file("$projectDir/assets/multiqc_config.yaml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config) : Channel.empty()
////////////////////////////////////////////////////
/* -- IMPORT MODULES / SUBWORKFLOWS -- */
////////////////////////////////////////////////////
// pipeline is the generic name
// hacer un wrapper por encima?
include { PIPELINE } from pipeline_module params(params)
if (!params.skip_benchmark) {
include { BENCHMARK } from benchmark_module params(params)
}
include { MEAN_BENCHMARK_SCORE } from "${projectDir}/modules/benchmarkers/mean_benchmark_score/main.nf" //TODO make it generic
//The previous include should be a module included in the benchmark pipeline
////////////////////////////////////////////////////
/* -- RUN MAIN WORKFLOW -- */
////////////////////////////////////////////////////
params.pipeline_output_name = false
// params.pipeline_output_name = 'alignment_regressive'
// params.pipeline_output_name = 'alignment_progressive'
// TODO move to the correct place
// Header log info
def summary = [:]
// Info required for completion email and summary
def multiqc_report = []
// Run the workflow
workflow {
PIPELINE()
// By default take ".out" if provided (or exists) then used the named output (params.pipeline_output_name)
if (!params.skip_benchmark) {
// By default take ".out" if provided (or exists) then used the named output (params.pipeline_output_name)
if (!params.pipeline_output_name) {
output_to_benchmark = PIPELINE.out[1]
// PIPELINE.out[0].view() //tcoffee
}
else {
output_to_benchmark = PIPELINE.out."$params.pipeline_output_name"
}
log.info """
Benchmark: ${infoBenchmark.benchmarker}
""".stripIndent()
BENCHMARK (output_to_benchmark)
BENCHMARK.out \
| map { it.text } \
| collectFile (name: 'scores.csv', newLine: false) \
| set { scores }
// TODO: output sometimes could be more than just a single score, refactor to be compatible with these cases
MEAN_BENCHMARK_SCORE(scores) | view
emit:
BENCHMARK.out
}
/*
* MultiQC
*/
if (!params.skip_multiqc) {
workflow_summary = Schema.params_summary_multiqc(workflow, summary_params)
ch_workflow_summary = Channel.value(workflow_summary)
ch_multiqc_files = Channel.empty()
ch_multiqc_files = ch_multiqc_files.mix(Channel.from(ch_multiqc_config))
ch_multiqc_files = ch_multiqc_files.mix(ch_multiqc_custom_config.collect().ifEmpty([]))
ch_multiqc_files = ch_multiqc_files.mix(ch_workflow_summary.collectFile(name: 'workflow_summary_mqc.yaml'))
ch_multiqc_files = ch_multiqc_files.mix(GET_SOFTWARE_VERSIONS.out.yaml.collect())
ch_multiqc_files = ch_multiqc_files.mix(FASTQC.out.zip.collect{it[1]}.ifEmpty([]))
MULTIQC (
ch_multiqc_files.collect()
)
multiqc_report = MULTIQC.out.report.toList()
ch_software_versions = ch_software_versions.mix(MULTIQC.out.version.ifEmpty(null))
}
}
////////////////////////////////////////////////////
/* -- COMPLETION EMAIL -- */
////////////////////////////////////////////////////
// Before uncomment include Completion.groovy into lib folder!!!
workflow.onComplete {
Completion.email(workflow, params, summary_params, projectDir, log, multiqc_report)
Completion.summary(workflow, params, log)
}
////////////////////////////////////////////////////
/* -- THE END -- */
////////////////////////////////////////////////////
/*
'tower' {
params.path_to_refData = 's3://cbcrg-eu/nf-benchmark-test-data'
aws.batch.cliPath = '/usr/local/bin/aws'
params.outdir = 's3://cbcrg-eu/results_nf-benchmark'
params.tracedir = "${params.outdir}/pipeline_info"
}
'batch' {
params.path_to_refData = 's3://cbcrg-eu/nf-benchmark-test-data'
process.container = 'quay.io/nextflow/rnaseq-nf:latest'
process.executor = 'awsbatch'
process.queue = 'jose_batch_test'
workDir = 's3://cbcrg-eu/work'
aws.region = 'eu-west-1'
aws.batch.cliPath = '/usr/local/bin/aws'
params.outdir = 's3://cbcrg-eu/results_nf-benchmark'
params.tracedir = "${params.outdir}/pipeline_info"
}
*/