-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
559 lines (483 loc) · 22.1 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
#!/usr/bin/env nextflow
/*
Copyright Institut Curie 2024
This software is a computer program whose purpose is to
predict 3D structure of proteins.
You can use, modify and/ or redistribute the software under the terms
of license (see the LICENSE file for more details).
The software is distributed in the hope that it will be useful,
but "AS IS" WITHOUT ANY WARRANTY OF ANY KIND.
Users are therefore encouraged to test the software's suitability as regards
their requirements in conditions enabling the security of their systems and/or data.
The fact that you are presently reading this means that you have had knowledge
of the license and that you accept its terms.
*/
/*
========================================================================================
@git_repo_name@
========================================================================================
@git_repo_name@ analysis Pipeline.
#### Homepage / Documentation
@git_url@
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl=2
// Note that several functions used in the main.nf scripts
// are defined in the 'lib' folder
// Initialize lintedParams and paramsWithUsage
NFTools.welcome(workflow, params)
// Use lintedParams as default params object
paramsWithUsage = NFTools.readParamsFromJsonSettings("${projectDir}/parameters.settings.json")
params.putAll(NFTools.lint(params, paramsWithUsage))
// Run name
customRunName = NFTools.checkRunName(workflow.runName, params.name)
// Custom functions/variables
include { checkInput4Docking } from './lib/functions'
include { printFileContent } from './lib/functions'
include { elementsNotPresent } from './lib/functions'
include { createFromCh as createMsasCh } from './lib/functions'
include { createFromCh as createPredictionsCh } from './lib/functions'
include { createFromCh as createRankingCh } from './lib/functions'
include { createFromCh as createPdbFileCh } from './lib/functions'
include { buildFastaPathCh } from './lib/functions'
/*
===================================
SET UP CONFIGURATION VARIABLES
===================================
*/
// Define a variable to test whether the pipeline has been launched with -stub-run
// or -stub
Boolean isStubRun = false
if ( workflow.commandLine.contains('-stub')) {
isStubRun = true
}
// Define a variable to track settings for which the fastaPath can be null
Boolean allowFastaPathNull = false
// Check that any option to print the help of a tool has been set to true
Boolean printToolHelp = false
if (params.collect().join(' ').find('Help=true')) {
printToolHelp = true
allowFastaPathNull = true
}
// DynamicBind, DiffDock do not require fastaPath
// but they require a proteinLigandFile
if(params.launchDynamicBind || params.launchDiffDock) {
allowFastaPathNull = true
if(params.proteinLigandFile == null) {
exit 1, "The option --proteinLigandFile has not been set"
}
}
// AlphaFold3 does not take fasta file as input
if(params.launchAlphaFold3) {
allowFastaPathNull = true
}
// DynamicBind works only with GPU
if(params.launchDynamicBind) {
if (!params.useGpu && !isStubRun){
exit 1, "DynamicBind works only using GPU. Launch the pipeline with the '--useGpu true' option."
}
}
// If the option --fastaPath has been provided, check that it contains a valid path
if (params.fastaPath != null ) {
File fastaPath = new File(params.fastaPath)
if (!fastaPath.exists()){
exit 1, "The path to the fasta file(s) '" + params.fastaPath + "' does not exist."
}
if (!fastaPath.isDirectory()){
exit 1, "The path to the fasta file(s) '" + params.fastaPath + "' is not a directory."
}
} else {
if (!allowFastaPathNull) {
exit 1, "The fastaPath options is 'null'. Provide a value using the --fastaPath option."
}
}
// If the option --proteinLigandFile has been provided, check that the file is correctly formatted
if (params.proteinLigandFile != null) {
if (checkInput4Docking(params.proteinLigandFile)) {
proteinLigandCh = Channel
.fromPath(params.proteinLigandFile)
.splitCsv(header: true)
.unique()
.map {
tuple(file(it.protein).getBaseName(), file(it.protein), file(it.ligand).getBaseName(), file(it.ligand))
}
}
}
// Check that alphaFoldOptions defines max_template_date=YYYY-MM-DD
if (!params.alphaFoldOptions.find("--max_template_date=(?:\\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])")){
exit 1, "'params.alphaFoldOptions' must define '--max_template_date=YYYY-MM-DD', e.g.: '--max_template_date=2024-01-01'"
}
// Get realpath for the annotations to avoid symlink issues in bindings with apptainer
if (params.launchAfMassive){
File afMassiveDB = new File(params.genomes.afmassive.database)
params.afMassiveDatabase = afMassiveDB.getCanonicalPath()
if(params.numberOfModels > 5) {
exit 1, "the option numberOfModels must not be greater than 5."
}
}
if (params.launchAlphaFill){
File alphaFillDB = new File(params.genomes.alphafill.database)
params.alphaFillDatabase = alphaFillDB.getCanonicalPath()
}
if (params.launchAlphaFold){
File alphaFoldDB = new File(params.genomes.alphafold.database)
params.alphaFoldDatabase = alphaFoldDB.getCanonicalPath()
}
if (params.launchAlphaFold3){
File alphaFold3DB = new File(params.genomes.alphafold3.database)
params.alphaFold3Database = alphaFold3DB.getCanonicalPath()
}
if (params.launchColabFold){
if (!params.useGpu && !isStubRun){
exit 1, "ColabFold works only using GPU. Launch the pipeline with the '--useGpu true' option."
}
File colabFoldDB = new File(params.genomes.colabfold.database)
params.colabFoldDatabase = colabFoldDB.getCanonicalPath()
}
if (params.launchDiffDock){
File diffDockDB = new File(params.genomes.diffdock.database)
params.diffDockDatabase = diffDockDB.getCanonicalPath()
}
if (params.launchDynamicBind){
File dynamicBindDB = new File(params.genomes.dynamicbind.database)
params.dynamicBindDatabase = dynamicBindDB.getCanonicalPath()
}
if (params.launchOpenFold){
File openFoldDB = new File(params.genomes.openfold.database)
params.openFoldDatabase = openFoldDB.getCanonicalPath()
}
if (params.launchNanoBert){
File nanoBertDB = new File(params.genomes.nanobert.database)
params.nanoBertDatabase = nanoBertDB.getCanonicalPath()
}
if (params.onlyMsas && params.fromMsas != null){
exit 1, "The --fromMsas option is set with '" + params.fromMsas + "' and --onlyMsas is set to true. Choose either one of these two options."
}
/*
==========================
BUILD CHANNELS
==========================
*/
// The fastaPathCh contains:
// /path/to/protein.fasta
// or in the case of AlphaFold3
// /path/to/protein.json
// example:
// /proteinfold/test/data/fasta/monomer2/MRLN.fasta
// /proteinfold/test/data/fasta/monomer2/MISFA.fasta
// In the fastaPath we want either json or fasta but not both
fastaPathCh = buildFastaPathCh("${params.fastaPath}/*.{json,fasta}")
// The fastaFilesCh contains:
// [protein, /path/to/protein.fasta]
// or in the case of AlphaFold3
// [protein, /path/to/protein.json]
// example:
// [MRLN, /proteinfold/test/data/fasta/monomer2/MRLN.fasta]
// [MISFA, /proteinfold/test/data/fasta/monomer2/MISFA.fasta]
fastaFilesCh = fastaPathCh
.map { fastaFile ->
String protein = fastaFile.toString()
.replaceAll(".*/", "")
.replaceFirst('\\.fasta$', "")
.replaceFirst('\\.json$', "")
tuple(protein, file(fastaFile))
}
// The fastaChainCh allows the processing of msas chain by chain
// in the multimer mode to speedup computation.
// The fastaChainCh contains:
// [protein, /path/to/protein.fasta, chainIdNum]
// example:
// [BTB-domain, /proteinfold/test/data/fasta/multimer/alphafold/BTB-domain.fasta, 1]
// [BTB-domain, /proteinfold/test/data/fasta/multimer/alphafold/BTB-domain.fasta, 2]
fastaChainsCh = fastaFilesCh
.map { protein, fastaFile ->
int nbChain = 1 // this will be the default for Alphafold3 as the parallelisation by chain is not implemeted in the nextflow pipeline
if(fastaFile.toString().endsWith('.fasta')) {
nbChain = fastaFile.countFasta()
}
(1..nbChain).collect { chainIdNum ->
tuple(protein, file(fastaFile), chainIdNum)
}
}.collect()
.flatten()
.collate(3)
// Set the msasCh when the pipeline is launched using existing msas.
// The msasCh contains:
// [protein, [/path/to/msas/protein/file1, ... , /path/to/msas/protein/fileX]]
// example:
// [MISFA, [/proteinfold/test/data/msas/monomer2/alphafold/MISFA/uniref90_hits.sto, /proteinfold/test/data/msas/monomer2/alphafold/MISFA/pdb_hits.hhr, /proteinfold/test/data/msas/monomer2/alphafold/MISFA/bfd_uniref_hits.a3m, /proteinfold/test/data/msas/monomer2/alphafold/MISFA/mgnify_hits.sto]]
// [MRLN, [/proteinfold/test/data/msas/monomer2/alphafold/MRLN/uniref90_hits.sto, /proteinfold/test/data/msas/monomer2/alphafold/MRLN/pdb_hits.hhr, /proteinfold/test/data/msas/monomer2/alphafold/MRLN/bfd_uniref_hits.a3m, /proteinfold/test/data/msas/monomer2/alphafold/MRLN/mgnify_hits.sto]]
msasCh = Channel.empty()
if(params.fromMsas != null){
msasCh = createMsasCh('fromMsas', fastaFilesCh)
}
// Set the predictionsCh when the pipeline is launched using existing predicted structures
predictionsCh = Channel.empty()
if(params.fromPredictions != null){
// The predictionsCh contains:
// [protein, toolFold, /path/to/predictions/results/protein]
// The toolFold is empty as we don't knowd what was used hen using the fromPredictions option
// example:
// [MISFA, , /home/phupe/git/gitlab/data-analysis/proteinfold/test/data/afmassive/monomer2/MISFA]
// [MRLN, , /home/phupe/git/gitlab/data-analysis/proteinfold/test/data/afmassive/monomer2/MRLN]
predictionsCh = createPredictionsCh('fromPredictions', fastaFilesCh)
.map { tuple(it[0], '', file(file(it[1][0]).getParent())) }
// rankingCh is not needed if we only launch AlphaFill
if(!params.launchAlphaFill){
rankingCh = createRankingCh('fromPredictions', fastaFilesCh)
.map {
def rankingTsvMonomer = it[1]
.findAll { fileName ->
fileName.toString().endsWith('ranking_debug.tsv')
}
def rankingTsvMultimer = it[1]
.findAll { fileName ->
fileName.toString().endsWith('ranking_debug_multimer.tsv')
}
def rankingTsvAF3 = it[1]
.findAll { fileName ->
fileName.toString().endsWith('ordered_ranking_scores.tsv')
}
def rankingTsv
if (rankingTsvMultimer) {
rankingTsv = rankingTsvMultimer
} else if (rankingTsvMonomer) {
rankingTsv = rankingTsvMonomer
} else if (rankingTsvAF3) {
rankingTsv = rankingTsvAF3
} else {
error("ERROR: there is no 'ranking_debug.tsv' (AlphaFold2), nor 'ranking_debug_multimer.tsv' (AlphaFold2), nor 'ordered_ranking_scores.tsv' (AlphaFold3) file for protein: " + it[0])
}
tuple(it[0], file(rankingTsv[0]))
}
}
pdbFileCh = createPdbFileCh('fromPredictions', fastaFilesCh)
.map { def pdbFile = it[1]
.findAll { fileName ->
fileName.toString().matches(/.*ranked_.*\.pdb$|.*ranked_.*\.cif$/)
}
if (!pdbFile) {
error("ERROR: there is no pdb files nor cif files for protein: " + it[0])
}
tuple(it[0], pdbFile)
}
}
/*
===========================
SUMMARY
===========================
*/
summary = [
'Pipeline' : workflow.manifest.name ?: null,
'Version': workflow.manifest.version ?: null,
'DOI': workflow.manifest.doi ?: null,
'Run Name': customRunName,
'Inputs' : params.fastaPath ?: null,
'AfMassive Database' : params.launchAfMassive ? params.afMassiveDatabase : null,
'AfMassive Options' : params.launchAfMassive ? params.afMassiveOptions : null,
'AlphaFill Database' : params.launchAlphaFill ? params.alphaFillDatabase : null,
'AlphaFold Database' : params.launchAlphaFold ? params.alphaFoldDatabase : null,
'AlphaFold Options' : params.launchAlphaFold || params.launchAfMassive ? params.alphaFoldOptions : null,
'AlphaFold3 Database' : params.launchAlphaFold3 ? params.alphaFold3Database : null,
'AlphaFold3 Options' : params.launchAlphaFold3 ? params.alphaFold3Options : null,
'ColabFold Database' : params.launchColabFold ? params.colabFoldDatabase : null,
'ColabFold Options' : params.launchColabFold ? params.colabFoldOptions : null,
'DiffDock Database' : params.launchDiffDock ? params.diffDockDatabase : null,
'DiffDock Options' : params.launchDiffDock ? params.diffDockArgsYamlFile : null,
'DynamicBind Database' : params.launchDynamicBind ? params.dynamicBindDatabase : null,
'DynamicBind Options' : params.launchDynamicBind ? params.dynamicBindOptions : null,
'Use existing msas' : params.fromMsas != null ? params.fromMsas : null,
'Use existing predictions' : params.fromPredictions != null ? params.fromPredictions : null,
'Perform only msas' : params.onlyMsas ? "True" : "False",
'Use GPU' : params.useGpu ? "True" : "False",
'Max Resources': "${params.maxMemory} memory, ${params.maxCpus} cpus, ${params.maxTime} time per job",
'Container': workflow.containerEngine && workflow.container ? "${workflow.containerEngine} - ${workflow.container}" : null,
'Profile' : workflow.profile,
'OutDir' : params.outDir,
'WorkDir': workflow.workDir,
'CommandLine': workflow.commandLine
].findAll{ it.value != null }
workflowSummaryCh = NFTools.summarize(summary, workflow, params)
.collectFile(name: "workflow_summary_mqc.yaml", sort: true)
/*
==================================
INCLUDE
==================================
*/
// Processes
include { afMassive } from './nf-modules/local/process/afMassive'
include { afMassiveSearch } from './nf-modules/local/process/afMassiveSearch'
include { afMassiveHelp } from './nf-modules/local/process/afMassiveHelp'
include { alphaFillHelp } from './nf-modules/local/process/alphaFillHelp'
include { alphaFoldHelp } from './nf-modules/local/process/alphaFoldHelp'
include { alphaFold3Help } from './nf-modules/local/process/alphaFold3Help'
include { colabFold } from './nf-modules/local/process/colabFold'
include { colabFoldHelp } from './nf-modules/local/process/colabFoldHelp'
include { colabFoldSearch } from './nf-modules/local/process/colabFoldSearch'
include { dynamicBind } from './nf-modules/local/process/dynamicBind'
include { dynamicBindHelp } from './nf-modules/local/process/dynamicBindHelp'
include { fastaChecker } from './nf-modules/local/process/fastaChecker'
include { getSoftwareOptions } from './nf-modules/common/process/utils/getSoftwareOptions'
include { getSoftwareVersions } from './nf-modules/common/process/utils/getSoftwareVersions'
include { massiveFoldPlots } from './nf-modules/local/process/massiveFoldPlots'
include { metricsMultimer } from './nf-modules/local/process/metricsMultimer'
include { pymolPng } from './nf-modules/local/process/pymolPng'
// Subworkflows
include { alphaFillWkfl } from './nf-modules/local/subworkflow/alphaFillWkfl'
include { alphaFoldWkfl } from './nf-modules/local/subworkflow/alphaFoldWkfl'
include { alphaFold3Wkfl } from './nf-modules/local/subworkflow/alphaFold3Wkfl'
include { afMassiveWkfl } from './nf-modules/local/subworkflow/afMassiveWkfl'
include { colabFoldWkfl } from './nf-modules/local/subworkflow/colabFoldWkfl'
include { diffDockWkfl } from './nf-modules/local/subworkflow/diffDockWkfl'
include { dynamicBindWkfl } from './nf-modules/local/subworkflow/dynamicBindWkfl'
include { mqcProteinStructWkfl } from './nf-modules/local/subworkflow/mqcProteinStructWkfl'
include { nanoBertWkfl } from './nf-modules/local/subworkflow/nanoBertWkfl'
/*
=====================================
WORKFLOW
=====================================
*/
workflow {
versionsCh = Channel.empty()
optionsCh = Channel.empty()
plotsCh = Channel.empty()
main:
// ********************************** //
// * Prediction models * //
// ********************************** //
// Launch the prediction of the protein 3D structure with AfMassive
if (params.launchAfMassive){
afMassiveWkfl(
fastaChainsCh,
fastaFilesCh,
fastaPathCh,
msasCh,
workflowSummaryCh
)
}
// Launch the prediction of the protein 3D structure with AlphaFold
if (params.launchAlphaFold){
alphaFoldWkfl(
fastaChainsCh,
fastaFilesCh,
fastaPathCh,
msasCh,
workflowSummaryCh
)
}
// Launch the prediction of the protein 3D structure with AlphaFold3
if (params.launchAlphaFold3){
alphaFold3Wkfl(
fastaFilesCh,
fastaPathCh,
msasCh,
workflowSummaryCh
)
}
// Launch the prediction of the protein 3D structure with ColabFold
if (params.launchColabFold){
colabFoldWkfl(
fastaChainsCh,
fastaFilesCh,
fastaPathCh,
msasCh,
workflowSummaryCh
)
}
// Launch the molecular docking with DiffDock
if (params.launchDiffDock){
diffDockWkfl(proteinLigandCh, params.diffDockDatabase, params.diffDockArgsYamlFile)
}
// Launch the molecular docking with DynamicBind
if (params.launchDynamicBind){
dynamicBindWkfl(proteinLigandCh, params.dynamicBindDatabase)
}
// Launch AlphaFill using existing predicted structure
if (params.launchAlphaFill && params.fromPredictions != null ){
alphaFillWkfl(predictionsCh)
}
// Launch the nanoBERT predictions
if (params.launchNanoBert){
nanoBertWkfl(
fastaFilesCh,
fastaPathCh
)
}
// **************************************************************** //
// * Generate HTML reports from existing predicted pdb structures * //
// **************************************************************** //
// Launch the generation of multiqc ProteinStruct HTML reports
// using existing predicted structure
// yaml files for multiqc are set to empty
if (params.htmlProteinStruct && params.fromPredictions != null ){
massiveFoldPlots(predictionsCh)
pymolPng(pdbFileCh)
mqcProteinStructWkfl(
Channel.of('').collectFile(name: 'software_options_mqc.yaml'),
Channel.of('').collectFile(name: 'software_versions_mqc.yaml'),
massiveFoldPlots.out.plots,
rankingCh,
pymolPng.out.png,
fastaFilesCh,
Channel.of('').collectFile(name: 'empty.txt')
)
}
// *********************************** //
// * Generate help of different tool * //
// *********************************** //
// Generate the help for each tool
if(params.afMassiveHelp){
afMassiveHelp()
}
if(params.alphaFillHelp){
alphaFillHelp()
}
if(params.alphaFoldHelp){
alphaFoldHelp()
}
if(params.alphaFold3Help){
alphaFold3Help()
}
if(params.colabFoldHelp){
colabFoldHelp()
}
if(params.dynamicBindHelp){
dynamicBindHelp()
}
}
workflow.onComplete {
if(printToolHelp){
if (params.alphaFillHelp) {
NFTools.printGreenText("\n\n=====================================\nAlphaFill help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/alphaFillHelp.txt")
NFTools.printGreenText("\n\n=====================================\nAlphaFill help, see options above.\n=====================================\n")
}
if (params.afMassiveHelp) {
NFTools.printGreenText("\n\n=====================================\nAfMassive help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/afMassiveHelp.txt")
NFTools.printGreenText("\n\n=====================================\nAfMassive help, see options above.\n=====================================\n")
}
if (params.alphaFoldHelp) {
NFTools.printGreenText("\n\n=====================================\nAlphaFold help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/alphaFoldHelp.txt")
NFTools.printGreenText("\n\n=====================================\nAlphaFold help, see options above.\n=====================================\n")
}
if (params.alphaFold3Help) {
NFTools.printGreenText("\n\n=====================================\nAlphaFold3 help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/alphaFold3Help.txt")
NFTools.printGreenText("\n\n=====================================\nAlphaFold3 help, see options above.\n=====================================\n")
}
if (params.colabFoldHelp) {
NFTools.printGreenText("\n\n=====================================\nColabFold help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/colabFoldHelp.txt")
NFTools.printGreenText("\n\n=====================================\nColabFold help, see options above.\n=====================================\n")
}
if (params.dynamicBindHelp) {
NFTools.printGreenText("\n\n=====================================\nDynamicBind help, list of options:\n=====================================\n")
printFileContent("${params.outDir}/dynamicBindHelp.txt")
NFTools.printGreenText("\n\n=====================================\nDynamicBind help, see options above.\n=====================================\n")
}
} else {
NFTools.makeReports(workflow, params, summary, customRunName, mqcReport)
}
}