-
Notifications
You must be signed in to change notification settings - Fork 1
/
submissions.nf
484 lines (374 loc) · 17.6 KB
/
submissions.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
#!/usr/bin/env nextflow
/*
========================================================================================
bigbio/pride-molecules-indexer
========================================================================================
bigbio/pride-molecules-indexer Analysis Pipeline.
#### Homepage / Documentation
https://github.com/bigbio/pride-molecules-indexer
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl = 1
def helpMessage() {
log.info nfcoreHeader()
log.info"""
Usage:
The typical command for running the pipeline is as follows:
nextflow run submissions.nf -c nextflow.config --project_accession "PXD029360" -profile conda
Main arguments:
--project_accession Project accession to convert the identifications to json files.
--outdir Output directory containing the information (json) of the project
Advanced Options:
--pride_production_folder (Optional) Local folder that contains the submitted files for PRIDE
Other options:
--outdir [file] The output directory where the results will be saved
--publish_dir_mode [str] Mode for publishing results in the output directory. Available: symlink, rellink, link, copy, copyNoFollow, move (Default: copy)
--email [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
--email_on_fail [email] Same as --email, except only send mail if the workflow is not successful
-name [str] Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic
""".stripIndent()
}
// Show help message
if (params.help) {
helpMessage()
exit 0
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// 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
}
// Stage config files
ch_output_docs = file("$baseDir/docs/output.md", checkIfExists: true)
ch_output_docs_images = file("$baseDir/docs/images/", checkIfExists: true)
// Validate input
if (isCollectionOrArray(params.project_accession)){
tocheck = params.project_accession[0]
} else {
tocheck = params.project_accession
}
params.project_accession = params.project_accession ?: { log.error "No project accession provided. Make sure you have used the '--project_accession' option."; exit 1 }()
params.outdir = params.outdir ?: { log.warn "No output directory provided. Will put the results into './results'"; return "./results" }()
// Get the results files for one project.
process project_get_result_files{
label 'downloading_thread'
publishDir "${params.outdir}/related_files", mode: 'copy', pattern: '*.tsv'
input:
output:
file "*.tsv" into result_file_summary, result_file_summary_str
script:
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar get-result-files --app.project-accession=${params.project_accession} \
--app.file-output="${params.project_accession}-result_files.tsv"
"""
}
result_file_summary_str.subscribe{ println "result file: $it"}
// Translate from ftp urls to https
result_file_summary.splitCsv(skip: 1, sep: '\t')
.multiMap{ row -> id = row[0]
result_files: tuple(id, !params.root_folder ? row[3].replace("ftp://", "https://") :params.root_folder + "/" + row[0])
}
.set{ch_result_files}
//ch_result_files.subscribe { println "value: $it" }
// Download with wget and Uncompress result files
process uncompress_result_files{
label 'downloading_thread'
input:
tuple result_id, result_file_path from ch_result_files.result_files
output:
tuple result_id, file("*") into ch_result_uncompress, ch_result_uncompress_process, ch_result_uncompress_process_str
script:
"""
wget --tries=80 '${result_file_path}'
gunzip -f '${result_id}'
"""
}
ch_result_uncompress_process_str.subscribe { println "value: $it" }
// Get the related spectra for each result file.
process project_get_related_spectra{
label 'process_medium'
publishDir "${params.outdir}/related_files", mode: 'copy', pattern: '*.tsv'
input:
tuple result_id, file(uncompress_result) from ch_result_uncompress
output:
tuple result_id, file("*.tsv") into ch_spectra_summary
script:
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar get-related-files --app.project-accession=${params.project_accession} \
--app.file-output="${params.project_accession}-${result_id}-result_spectra.tsv" --app.result-file="${uncompress_result}"
"""
}
// ch_spectra_summary.subscribe { println "value: $it" }
ch_spectra_summary.map { tuple_summary ->
def key = tuple_summary[0]
def summary_file = tuple_summary[1]
def list_spectra = tuple_summary[1].splitCsv(skip: 1, sep: '\t')
.collect{"'" + it[5] + "'"}
.flatten()
return tuple(key.toString(), list_spectra.findAll{ it != "'null'"}
.collect{ it-> it.replace("ftp://", "http://")})
}
.groupTuple()
.into { ch_spectra_tuple_results; ch_spectra_pride_xml; ch_spectra_files_str}
ch_spectra_files_str.subscribe { println "value: $it" }
//Download the spectra files related to the files.
process download_spectra_files{
label 'downloading_thread'
input:
tuple val(result_id), spectra from ch_spectra_tuple_results
output:
tuple val(result_id), path("*") into ch_spectra_files, spectra_file_view, spectra_file_str
when:
!spectra.flatten().isEmpty()
script:
"""
wget --tries=80 ${spectra.flatten().join(" ")}
find . -type f -name '*.gz' -exec gzip -d {} \\;
"""
}
ch_spectra_files_process = ch_spectra_files.map { id, files ->
files instanceof List ? [ id, files.collect{ it } ]
: [ id, [ files ] ] }
spectra_file_view.ifEmpty{ ch_spectra_files_process = ch_spectra_pride_xml}
spectra_file_str.subscribe { println "spectra value: $it" }
ch_result_uncompress_process.combine(ch_spectra_files_process, by:0).into{ch_final_map; ch_result_uncompress_process_str}
ch_result_uncompress_process_str.subscribe { println "value-2: $it" }
process generate_json_index_files{
label 'process_high'
input:
val(result_id) from ch_final_map
output:
file("**_ArchiveSpectrum_Total.json") optional true into final_spectrum_total_json
script:
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar generate-index-files --app.result-file="${result_id[1]}" --app.folder-output=`pwd` --app.spectra-files="${result_id[2].join(",")}" --app.project-accession=${params.project_accession} --app.minPSMs=${params.minPSMs} --app.qValueThreshold=${params.qValueThreshold} --app.qFilterProteinFDR=${params.qFilterProteinFDR} --app.peptideLength=${params.peptideLength} --app.uniquePeptides=${params.uniquePeptides}
"""
}
total_spectrum_file = final_spectrum_total_json.collectFile(
name: "${params.project_accession}_ArchiveSpectrum_Total_NonFilter.json",
storeDir: "${params.outdir}/${params.project_accession}")
process json_check_validator{
label 'process_high'
publishDir "${params.outdir}/${params.project_accession}", mode: 'copy', pattern: '**.json'
input:
file(result_id) from total_spectrum_file
output:
file("**_ArchiveSpectrum_Total_NonFilter_Validated.json") into final_spectrum_total_validated_json, total_spectrum_file_final
script:
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar spectra-json-check --app.archive-spectra="${result_id}" --app.validated-spectra="${result_id.baseName}_Validated.json"
"""
}
process convert_to_mgf{
label 'process_high'
publishDir "${params.outdir}/${params.project_accession}", mode: 'copy', pattern: '**.mgf'
input:
file(total_spectra) from final_spectrum_total_validated_json
output:
file "*.mgf" into mgf_files
script:
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar generate-mgf-files --app.archive-spectra="${total_spectra}" --app.mgf-file=${params.project_accession}.mgf
"""
}
process maracluster_clustering{
label 'process_high'
publishDir "${params.outdir}/${params.project_accession}", mode: 'copy', pattern: '**.tsv'
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://containers.biocontainers.pro/s3/SingImgsRepo/maracluster/1.02.1_cv1/maracluster_1.02.1_cv1.sif"
} else {
container "biocontainers/maracluster:1.02.1_cv1"
}
input:
file(total_spectra) from mgf_files
output:
file "maracluster_output/*.clusters_p${params.clusterpvalue}.tsv" into maracluster_results
script:
"""
echo ${total_spectra} > bash_files.txt
maracluster batch -b bash_files.txt
"""
}
process final_inference_after_clustering{
label 'process_high'
publishDir "${params.outdir}", mode: 'copy', pattern: '**_ArchiveSpectrum.json'
input:
file(clustering_file) from maracluster_results
file(total_spectrum) from total_spectrum_file_final
output:
file("**_ArchiveSpectrum.json") optional true into final_batch_json_inference
file("**_ArchiveProteinEvidence.json") optional true into final_protein_json_inference, final_protein_json_view_inference
file("**_ArchiveSpectrum_Total.json") optional true into final_spectrum_total_json_inference
file("**_SummaryArchiveSpectrum.json") optional true into final_summary_json_inference, final_summary_json_view_inference
script:
java_mem = "-Xmx" + (task.memory.toGiga() - 4) + "G"
"""
java -jar ${baseDir}/bin/pride-molecules-indexer-1.0.0-SNAPSHOT-bin.jar perform-inference --app.output-folder=`pwd` --app.archive-spectra="${total_spectrum}" --app.cluster-file="${clustering_file}" --app.project-accession="${params.project_accession}"
"""
}
final_protein_json_inference.collectFile(
name: "${params.project_accession}_ArchiveProteinEvidence.json",
storeDir: "${params.outdir}/${params.project_accession}")
final_spectrum_total_json_inference.collectFile(
name: "${params.project_accession}_ArchiveSpectrum_Total.json",
storeDir: "${params.outdir}/${params.project_accession}")
final_summary_json_inference.collectFile(
name: "${params.project_accession}_SummaryArchiveSpectrum.json",
storeDir: "${params.outdir}/${params.project_accession}")
//--------------------------------------------------------------- //
//---------------------- Nextflow specifics --------------------- //
//--------------------------------------------------------------- //
// Header log info
log.info nfcoreHeader()
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Run Name'] = custom_runName ?: workflow.runName
summary['Max Resources'] = "$params.max_memory memory, $params.max_cpus cpus, $params.max_time time per job"
if (workflow.containerEngine) summary['Container'] = "$workflow.containerEngine - $workflow.container"
summary['Output dir'] = params.outdir
summary['Launch dir'] = workflow.launchDir
summary['Working dir'] = workflow.workDir
summary['User'] = workflow.userName
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(', ')
if (params.email || params.email_on_fail) {
summary['E-mail Address'] = params.email
summary['E-mail on failure'] = params.email_on_fail
}
log.info summary.collect { k,v -> "${k.padRight(18)}: $v" }.join("\n")
log.info "-\033[2m--------------------------------------------------\033[0m-"
// 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: 'pride-molecules-indexer-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'bigbio/pride-molecules-indexer Workflow Summary'
section_href: 'https://github.com/bigbio/pride-molecules-indexer'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
$x
</dl>
""".stripIndent() }
.set { ch_workflow_summary }
/*
* Parse software version numbers
*/
process get_software_versions {
label 'downloading_thread'
publishDir "${params.outdir}/pipeline_info", mode: params.publish_dir_mode,
saveAs: { filename ->
if (filename.indexOf(".csv") > 0) filename
else null
}
output:
file 'software_versions_mqc.yaml' into ch_software_versions_yaml
file "software_versions.csv"
script:
"""
echo $workflow.manifest.version > v_pipeline.txt
echo $workflow.nextflow.version > v_nextflow.txt
echo $workflow.manifest.version &> v_msstats_plfq.txt
scrape_software_versions.py &> software_versions_mqc.yaml
"""
}
/*
* STEP 3 - Output Description HTML
*/
process output_documentation {
label 'downloading_thread'
publishDir "${params.outdir}/pipeline_info", mode: params.publish_dir_mode
input:
file output_docs from ch_output_docs
file images from ch_output_docs_images
output:
file "results_description.html"
script:
"""
markdown_to_html.py $output_docs -o results_description.html
"""
}
/*
* Completion e-mail notification
*/
workflow.onComplete {
// Set up the e-mail variables
def subject = "[bigbio/pride-molecules-indexer] Successful: $workflow.runName ${params.project_accession}"
if (!workflow.success) {
subject = "[bigbio/pride-molecules-indexer] FAILED: $workflow.runName ${params.project_accession}"
}
def msg = """\
Pipeline execution summary: bigbio/pride-molecules-indexer
---------------------------
Completed at: ${workflow.complete}
Duration : ${workflow.duration}
Success : ${workflow.success}
workDir : ${workflow.workDir}
exit status : ${workflow.exitStatus}
Error message: ${workflow.errorMessage}
"""
.stripIndent()
sendMail(to: params.email, subject: subject, body: msg)
}
def nfcoreHeader() {
// Log colors ANSI codes
c_black = params.monochrome_logs ? '' : "\033[0;30m";
c_blue = params.monochrome_logs ? '' : "\033[0;34m";
c_cyan = params.monochrome_logs ? '' : "\033[0;36m";
c_dim = params.monochrome_logs ? '' : "\033[2m";
c_green = params.monochrome_logs ? '' : "\033[0;32m";
c_purple = params.monochrome_logs ? '' : "\033[0;35m";
c_reset = params.monochrome_logs ? '' : "\033[0m";
c_white = params.monochrome_logs ? '' : "\033[0;37m";
c_yellow = params.monochrome_logs ? '' : "\033[0;33m";
return """ -${c_dim}--------------------------------------------------${c_reset}-
${c_green},--.${c_black}/${c_green},-.${c_reset}
${c_blue} ___ __ __ __ ___ ${c_green}/,-._.--~\'${c_reset}
${c_blue} |\\ | |__ __ / ` / \\ |__) |__ ${c_yellow}} {${c_reset}
${c_blue} | \\| | \\__, \\__/ | \\ |___ ${c_green}\\`-._,-`-,${c_reset}
${c_green}`._,._,\'${c_reset}
${c_purple} bigbio/pride-molecules-indexer v${workflow.manifest.version}${c_reset}
-${c_dim}--------------------------------------------------${c_reset}-
""".stripIndent()
}
def checkHostname() {
def c_reset = params.monochrome_logs ? '' : "\033[0m"
def c_white = params.monochrome_logs ? '' : "\033[0;37m"
def c_red = params.monochrome_logs ? '' : "\033[1;91m"
def c_yellow_bold = params.monochrome_logs ? '' : "\033[1;93m"
if (params.hostnames) {
def hostname = "hostname".execute().text.trim()
params.hostnames.each { prof, hnames ->
hnames.each { hname ->
if (hostname.contains(hname) && !workflow.profile.contains(prof)) {
log.error "====================================================\n" +
" ${c_red}WARNING!${c_reset} You are running with `-profile $workflow.profile`\n" +
" but your machine hostname is ${c_white}'$hostname'${c_reset}\n" +
" ${c_yellow_bold}It's highly recommended that you use `-profile $prof${c_reset}`\n" +
"============================================================"
}
}
}
}
}
//--------------------------------------------------------------- //
//---------------------- Utility functions --------------------- //
//--------------------------------------------------------------- //
// Check file extension
def hasExtension(it, extension) {
it.toString().toLowerCase().endsWith(extension.toLowerCase())
}
// Check class of an Object for "List" type
boolean isCollectionOrArray(object) {
[Collection, Object[]].any { it.isAssignableFrom(object.getClass()) }
}