-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDeepRescore.nf
497 lines (381 loc) · 13.8 KB
/
DeepRescore.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
#!/usr/bin/env nextflow
params.help = false
params.id_file = null
params.ms_file = "-" //
params.se = "msgf" // msgf, xtandem, comet or maxquant
params.ms_instrument = "Lumos"
params.ms_energy = 0.34
params.decoy_prefix = "XXX_"
params.prefix = "test"
params.out_dir = "work"
params.cpu = 0
params.mem = 8 // unit is G
/* Prints help when asked for and exits */
def helpMessage() {
log.info"""
=========================================
DeepRescore => Rescore PSMs
=========================================
Usage:
nextflow run DeepRescore.nf
Arguments:
--id_file Identification result.
--ms_file MS/MS data in MGF format. If the search engine is MaxQuant, this parameter is not useful.
--se The name of search engine, msgf:MS-GF+, xtandem:X!Tandem, comet:Comet or maxquant:MaxQuant.
Default is "msgf" (MS-GF+).
--ms_instrument The MS instrument used to generate the MS/MS data. This is used by pDeep2 for MS/MS spectrum prediction.
Default is "Lumos".
--ms_energy The energy used in MS/MS data generation. This is used by pDeep2 for MS/MS spectrum prediction.
Default is 0.34.
--out_dir Output folder, default is "./output"
--prefix The prefix of output file(s).
--decoy_prefix The prefix of decoy proteins. Default is "XXX_".
--cpu The number of CPUs
--mem The memory for processing the data, default is 4. The unit is G.
--help Print help message
""".stripIndent()
}
// Show help emssage
if (params.help){
helpMessage()
exit 0
}
result_file = file(params.id_file)
software = params.se
output_path = file(params.out_dir)
instrument = params.ms_instrument
energy = params.ms_energy
threads = params.cpu
memory = params.mem
sample = params.prefix
decoy_prefix= params.decoy_prefix
if (software == "msgf") {
result_type = 1
spectrum_file = file(params.ms_file)
} else if (software == "xtandem") {
result_type = 1
spectrum_file = file(params.ms_file)
} else if (software == "comet") {
result_type = 2
spectrum_file = file(params.ms_file)
} else if (software == "maxquant") {
result_type = 5
spectrum_file = "-"
} else {
println "Search engine ${software} is not supported!\n"
helpMessage()
exit 0
}
if (software == "maxquant"){
spectrum_file = result_file + "/generatesMGF"
process calc_basic_features_mq {
tag "$sample"
publishDir "$output_path", mode: "copy", overwrite: true
input:
file result_file
output:
file("features.txt") into all_features_ch1
file("features.txt") into all_features_ch2
file("features.txt") into all_features_ch3
file("features.txt") into all_features_ch4
script:
"""
java -Xmx${memory}g -jar ${baseDir}/bin/PDV-1.6.1.beta.features/PDV-1.6.1.beta.features-jar-with-dependencies.jar \
-r $result_file \
-rt $result_type \
-s "${result_file}/generatesMGF/" \
-st 1 \
-i * \
-k s \
-o ./ \
-a 0.05 \
-c 0 \
-decoy "XXX_" \
-ft pdf \
--features
"""
}
} else {
if (software == "xtandem"){
process xml2mzid{
tag "${sample}"
container "bzhanglab/neoflow:1.0"
input:
file result_file
output:
file("${res_file}") into mzid_file
script:
res_file = "${sample}.mzid"
"""
#!/bin/sh
## convert xml to mzid
java -Xmx${memory}g -jar /opt/mzidlib-1.7/mzidlib-1.7.jar Tandem2mzid \
${result_file} \
${res_file} \
-outputFragmentation false \
-decoyRegex ${decoy_prefix} \
-databaseFileFormatID MS:1001348 \
-massSpecFileFormatID MS:1001062 \
-idsStartAtZero false \
-compress false \
-proteinCodeRegex "\\S+"
"""
}
process calc_basic_features_xt {
tag "$sample"
publishDir "$output_path", mode: "copy", overwrite: true
input:
file mzid_file
file spectrum_file
output:
file("features.txt") into all_features_ch1
file("features.txt") into all_features_ch2
file("features.txt") into all_features_ch3
file("features.txt") into all_features_ch4
script:
"""
java -Xmx${memory}g -jar ${baseDir}/bin/PDV-1.6.1.beta.features/PDV-1.6.1.beta.features-jar-with-dependencies.jar \
-r $mzid_file \
-rt $result_type \
-s $spectrum_file \
-st 1 \
-i * \
-k s \
-o ./ \
-a 0.05 \
-c 0 \
-decoy ${decoy_prefix} \
-ft pdf \
--features
"""
}
}else {
process calc_basic_features {
tag "$sample"
publishDir "$output_path", mode: "copy", overwrite: true
input:
file result_file
file spectrum_file
output:
file("features.txt") into all_features_ch1
file("features.txt") into all_features_ch2
file("features.txt") into all_features_ch3
file("features.txt") into all_features_ch4
script:
"""
java -Xmx${memory}g -jar ${baseDir}/bin/PDV-1.6.1.beta.features/PDV-1.6.1.beta.features-jar-with-dependencies.jar \
-r $result_file \
-rt $result_type \
-s $spectrum_file \
-st 1 \
-i * \
-k s \
-o ./ \
-a 0.05 \
-c 0 \
-decoy ${decoy_prefix} \
-ft pdf \
--features
"""
}
}
}
process pga_fdr_control {
tag "$sample"
container "proteomics/pga:latest"
publishDir "$output_path", mode: "copy", overwrite: true
input:
file feature_file from all_features_ch1
output:
set file("${sample}-rawPSMs.txt"), file("./peptide_level/"), file("./psm_level/") into pga_results_ch
file("${sample}-rawPSMs.txt") into pga_results_ch2
file("${sample}-rawPSMs.txt") into pga_results_ch3
script:
"""
mkdir peptide_level psm_level
Rscript ${baseDir}/bin/got_pga_input.R $feature_file $software ./${sample}-rawPSMs.txt
Rscript ${baseDir}/bin/calculate_fdr.R ./ $sample ${baseDir}/bin/protein.pro-ref.fasta
"""
}
process generate_train_prediction_data {
tag "$sample"
container "proteomics/pga:latest"
publishDir "$output_path", mode: "copy", overwrite: true
input:
file feature_file from all_features_ch2
set file(rawPSMs_file), file(peptide_pga_results_file), file(psm_pga_results_file) from pga_results_ch
output:
file("./pDeep2_prediction/") into pDeep2_prediction_ch
file("./autoRT_train/") into autoRT_train_ch
file("./autoRT_prediction/") into autoRT_prediction_ch
script:
"""
mkdir autoRT_train autoRT_prediction pDeep2_prediction
Rscript ${baseDir}/bin/got_train_prediction.R ${peptide_pga_results_file}/pga-peptideSummary.txt \
${psm_pga_results_file}/pga-peptideSummary.txt $feature_file ./autoRT_train/ ./autoRT_prediction/ \
./pDeep2_prediction/${sample}_pdeep2_prediction $rawPSMs_file
"""
}
process run_pdeep2 {
tag "$sample"
cpus "$params.cpu"
container "proteomics/pdeep2:latest"
publishDir "${output_path}/pDeep2_prediction/", mode: "copy", overwrite: true
input:
//file pdeep2_folder
file(pdeep2_folder) from pDeep2_prediction_ch
output:
set file("${sample}_pdeep2_prediction_results.txt"), file{"${pdeep2_folder}/${sample}_pdeep2_prediction.txt"} into pDeep2_results_ch
script:
"""
#export CUDA_VISIBLE_DEVICES=0
python /opt/pDeep2/predict.py -e $energy -i $instrument -in ${pdeep2_folder}/${sample}_pdeep2_prediction_unique.txt -out ./${sample}_pdeep2_prediction_results.txt
"""
}
process process_pDeep2_results {
tag "$sample"
cpus "$params.cpu"
container "proteomics/pga:latest"
publishDir "${output_path}/pDeep2_prediction/", mode: "copy", overwrite: true
input:
file (rawPSMs_file) from pga_results_ch2
file (spectrum_file)
set file(pDeep2_results), file(pDeep2_prediction) from pDeep2_results_ch
output:
set file("./${sample}_format_titles.txt"), file("./${sample}_spectrum_pairs.txt"), file("./${sample}_similarity_SA.txt") into similarity_ch
file ("./${sample}_similarity_SA.txt") into pDee2_next_ch
script:
"""
#!/bin/sh
mv $pDeep2_results ${pDeep2_results}.mgf
Rscript ${baseDir}/bin/format_pDeep2_titile.R $pDeep2_prediction $rawPSMs_file ./${sample}_format_titles.txt
java -Xmx${memory}g -cp ${baseDir}/bin/PDV-1.6.1.beta.features/PDV-1.6.1.beta.features-jar-with-dependencies.jar PDVGUI.GenerateSpectrumTable \
./${sample}_format_titles.txt $spectrum_file ${pDeep2_results}.mgf ./${sample}_spectrum_pairs.txt $software
mkdir sections sections_results
Rscript ${baseDir}/bin/similarity/devide_file.R ./${sample}_spectrum_pairs.txt $threads ./sections/
for file in ./sections/*
do
name=`basename \$file`
Rscript ${baseDir}/bin/similarity/calculate_similarity_SA.R \$file ./sections_results/\${name}_results.txt &
done
wait
awk 'NR==1 {header=\$_} FNR==1 && NR!=1 { \$_ ~ \$header getline; } {print}' ./sections_results/*_results.txt > ./${sample}_similarity_SA.txt
"""
}
process train_autoRT {
tag "$sample"
cpus "$params.cpu"
container "proteomics/autort:latest"
publishDir "${output_path}/autoRT_train/", mode: "copy", overwrite: true
input:
//file autoRT_train_folder
//file autoRT_prediction_folder
file(sa_file) from pDee2_next_ch
file(autoRT_train_folder) from autoRT_train_ch
output:
file ("./autoRT_models/") into model_prediction_ch
script:
"""
#!/bin/sh
set -e
mkdir -p ./autoRT_models
for file in ${autoRT_train_folder}/*.txt
do
fraction=`basename \${file} .txt`
mkdir -p ./autoRT_models/\${fraction}
python /opt/AutoRT/autort.py train \
-i \$file \
-o ./autoRT_models/\${fraction} \
-e 40 \
-b 64 \
-u m \
-m /opt/AutoRT/models/general_base_model/model.json \
-rlr \
-n 10
done
wait
"""
}
process predicte_autoRT {
tag "$sample"
cpus "$params.cpu"
container "proteomics/autort:latest"
publishDir "${output_path}/", mode: "copy", overwrite: true
input:
file autoRT_prediction_folder from autoRT_prediction_ch
file (autoRT_models_folder)from model_prediction_ch
output:
file("./autoRT_prediction/") into autoRT_results_ch
script:
"""
#!/bin/sh
set -e
mkdir -p ./autoRT_prediction
mkdir -p ./autoRT_prediction/results
for file in ${autoRT_prediction_folder}/*.txt
do
fraction=`basename \${file} .txt`
mkdir -p ./autoRT_prediction/\${fraction}
python /opt/AutoRT/autort.py predict \
-t \$file \
-s ${autoRT_models_folder}/\${fraction}/model.json \
-o ./autoRT_prediction/\${fraction} \
-p \${fraction}
done
wait
for file in ${autoRT_prediction_folder}/*.txt
do
fraction=`basename \${file} .txt`
cp ./autoRT_prediction/\${fraction}/\${fraction}.tsv ./autoRT_prediction/results/
done
awk 'NR==1 {header=\$_} FNR==1 && NR!=1 { \$_ ~ \$header getline; } {print}' ./autoRT_prediction/results/*.tsv \
> ./autoRT_prediction/results/${sample}_results.txt
"""
}
process generate_percolator_input {
tag "$sample"
container "proteomics/pga:latest"
publishDir "${output_path}/percolator_input/", mode: "copy", overwrite: true
input:
file (feature_file) from all_features_ch3
file (rawPSMs_file) from pga_results_ch3
file (autoRT_results_folder) from autoRT_results_ch
set file(similarity_title_file), file(similarity_pair_file), file(similarity_SA_file) from similarity_ch
output:
file ("./format.pin") into percolator_input_ch
file ("./format.pin") into percolator_input_ch2
script:
"""
Rscript ${baseDir}/bin/percolator/format_percolator_input.R $feature_file $rawPSMs_file \
${autoRT_results_folder}/results/${sample}_results.txt $similarity_SA_file ./format.pin $software
"""
}
process run_percolator {
tag "$sample"
cpus "$params.cpu"
container "bzhanglab/percolator:3.4"
publishDir "${output_path}/percolator_results/", mode: "copy", overwrite: true
input:
file (percolator_input_file) from percolator_input_ch
output:
set file("${sample}_pep.txt"), file("${sample}_psms.txt") into percolator_output_ch
script:
"""
percolator -r ${sample}_pep.txt -m ${sample}_psms.txt format.pin
"""
}
process generate_pdv_input {
tag "$sample"
container "proteomics/pga:latest"
publishDir "${output_path}/DeepRescore_results/", mode: "copy", overwrite: true
input:
set file(pep_level_result), file(psm_level_result) from percolator_output_ch
file (features_file) from all_features_ch4
file (percolator_input_file) from percolator_input_ch2
output:
set file("${sample}_pep_final*.tsv"), file("${sample}_psm_final*.tsv") into pdv_input_ch
script:
"""
Rscript ${baseDir}/bin/PDV/generate_pdv_input.R ./ $sample $features_file $percolator_input_file
"""
}