-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.nf
1148 lines (929 loc) · 38.7 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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nextflow
/*
========================================================================================
nf-core/diaproteomics
========================================================================================
nf-core/diaproteomics Analysis Pipeline.
#### Homepage / Documentation
https://github.com/nf-core/diaproteomics
----------------------------------------------------------------------------------------
*/
log.info Headers.nf_core(workflow, params.monochrome_logs)
////////////////////////////////////////////////////
/* -- PRINT HELP -- */
////////////////////////////////////////////////////+
def json_schema = "$projectDir/nextflow_schema.json"
if (params.help) {
def command = "nextflow run nf-core/diaproteomics --input sample_sheet.tsv --input_spectral_library library_sheet.tsv --irts irt_sheet.tsv"
log.info NfcoreSchema.params_help(workflow, params, json_schema, command)
exit 0
}
////////////////////////////////////////////////////
/* -- VALIDATE PARAMETERS -- */
////////////////////////////////////////////////////+
if (params.validate_params) {
NfcoreSchema.validateParameters(params, json_schema, log)
}
////////////////////////////////////////////////////
/* -- Collect configuration parameters -- */
////////////////////////////////////////////////////
// Check AWS batch settings
if (workflow.profile.contains('awsbatch')) {
// AWSBatch sanity checking
if (!params.awsqueue || !params.awsregion) exit 1, 'Specify correct --awsqueue and --awsregion parameters on AWSBatch!'
// Check outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
if (!params.outdir.startsWith('s3:')) exit 1, 'Outdir not on S3 - specify S3 Bucket to run on AWSBatch!'
// Prevent trace files to be stored on S3 since S3 does not support rolling files.
if (params.tracedir.startsWith('s3:')) exit 1, 'Specify a local tracedir or run without trace! S3 cannot be used for tracefiles.'
}
// Stage config files
projectDir=workflow.projectDir
ch_output_docs = file("$projectDir/docs/output.md", checkIfExists: true)
ch_output_docs_images = file("$projectDir/docs/images/", checkIfExists: true)
sample_sheet = file(params.input)
Channel
.from( sample_sheet )
.into { input_exp_design; input_exp_design_mztab}
params.outdir = params.outdir ?: { log.warn "No output directory provided. Will put the results into './results'"; return "./results" }()
// DIA MS input
Channel
.from( sample_sheet )
.splitCsv(header: true, sep:'\t')
.map { col -> tuple("${col.Sample}", "${col.BatchID}", "${col.MSstats_Condition}", file("${col.Spectra_Filepath}", checkifExists: true))}
.flatMap{it -> [tuple(it[0],it[1].toString(),it[2],it[3])]}
.into { input_branch; check_dia }
// Check file extension
def hasExtension(it, extension) {
it.toString().toLowerCase().endsWith(extension.toLowerCase())
}
input_branch.branch {
raw: hasExtension(it[3], 'raw')
mzml: hasExtension(it[3], 'mzml')
mzxml: hasExtension(it[3], 'mzxml')
other: true
}.set{input_dia_ms_files}
input_dia_ms_files.other.subscribe { row -> log.warn("unknown format for entry " + row[3] + " in provided sample sheet. ignoring line."); exit 1 }
check_dia_n = check_dia.map{it[1]}.unique().toList().size().val
// Validate inputs
sample_sheet = file(params.input)
if( params.irts_from_outer_quantiles){
quant_flag = '--quantiles True'
} else {
quant_flag = ''
}
if( params.align_libraries) {
align_flag = '--align True'
} else {
align_flag = ''
}
/*
* Create a channel for input spectral library
*/
if( params.generate_spectral_library) {
// Spectral library input
dda_sheet = file(params.input_sheet_dda)
Channel.from( dda_sheet )
.splitCsv(header: true, sep:'\t')
.map { col -> tuple("${col.Sample}", "${col.BatchID}", file("${col.Spectra_Filepath}", checkifExists: true), file("${col.Id_Filepath}", checkifExists: true))}
.flatMap{it -> [tuple(it[0],it[1],it[2],it[3])]}
.into {input_dda;input_check;input_check_samples}
check_n = input_check.toList().size().val
check_n_sample = input_check_samples.map{it[1]}.unique().toList().size().val
if ((check_n > 1) & (check_n != check_n_sample) & (!params.merge_libraries)) {
print('You specified multiple DDA files to generate spectral libraries, but library merging is not set \n')
print('Set --merge_libraries and possibly --align_libraries to align them in the same RT space \n')
exit 1
}
if ((check_n_sample != check_dia_n)) {
print('The number of batches in the sample input does not match the number of batches of the spectral library input \n')
exit 1
}
input_dda.branch {
raw: hasExtension(it[2], 'raw')
mzml: hasExtension(it[2], 'mzML')
mzxml: hasExtension(it[2], 'mzXML')
other: true
}.set{input_dda_ms_files}
Channel
.fromPath( params.unimod )
.ifEmpty { exit 1, "params.unimod was empty - no unimod.xml supplied" }
.set { input_unimod }
input_lib = Channel.empty()
input_lib_1 = Channel.empty()
input_lib_nd = Channel.empty()
input_lib_nd_1 = Channel.empty()
params.input_spectral_library = "generate spectral library from DDA data"
} else if( params.skip_decoy_generation) {
// Spectral library input
library_sheet = file(params.input_spectral_library)
Channel.from( library_sheet )
.splitCsv(header: true, sep:'\t')
.map { col -> tuple("${col.Sample}", "${col.BatchID}", file("${col.Library_Filepath}", checkifExists: true))}
.flatMap{ it -> [tuple(it[0],it[1],it[2])] }
.into { input_lib_nd; check_decoy; check_decoy_2 }
check_decoy_n2 = check_decoy_2.toList().size().val
check_decoy_n = check_decoy.map{it[1]}.unique().toList().size().val
if ((check_decoy_n > 1) & (check_decoy_n2 != check_decoy_n)) {
print('You specified multiple spectral libraries including decoys for one batch \n')
print('This is not possible yet, merging and aligning would be possible without decoys\n')
exit 1
}
if ((check_decoy_n != check_dia_n)) {
print('The number of batches in the sample input do not match the number of batches of the spectral library input \n')
exit 1
}
input_lib = Channel.empty()
input_lib_1 = Channel.empty()
input_dda = Channel.empty()
input_dda.branch {
raw: hasExtension(it[2], 'raw')
mzml: hasExtension(it[2], 'mzML')
mzxml: hasExtension(it[2], 'mzXML')
other: true
}.set { input_dda_ms_files }
input_unimod = Channel.empty()
} else {
// Spectral library input
library_sheet = file(params.input_spectral_library)
Channel.from( library_sheet )
.splitCsv(header: true, sep:'\t')
.map { col -> tuple("${col.Sample}", "${col.BatchID}", file("${col.Library_Filepath}", checkifExists: true))}
.flatMap{it -> [tuple(it[0],it[1],it[2])]}
.into {input_lib; input_lib_1; input_lib_n; input_lib_n2 }
check_lib_n2 = input_lib_n2.toList().size().val
check_lib_n = input_lib_n.map{it[1]}.unique().toList().size().val
if ((check_lib_n > 1) & (check_lib_n2 != check_lib_n) & (!params.merge_libraries)) {
print('You specified multiple spectral libraries for one batch \n')
print('Set --merge_libraries and possibly --align_libraries to align them in the same RT space \n')
exit 1
}
if ((check_lib_n != check_dia_n)) {
print('The number of batches in the sample input does not match the number of batches of the spectral library input \n')
exit 1
}
input_lib_nd = Channel.empty()
input_lib_nd_1 = Channel.empty()
input_dda = Channel.empty()
input_dda.branch {
raw: hasExtension(it[2], 'raw')
mzml: hasExtension(it[2], 'mzML')
mzxml: hasExtension(it[2], 'mzXML')
other: true
}.set { input_dda_ms_files }
input_unimod = Channel.empty()
}
if( !params.generate_pseudo_irts){
// iRT library input
irt_sheet = file(params.irts)
Channel.from( irt_sheet )
.splitCsv(header: true, sep:'\t')
.map { col -> tuple("${col.BatchID}", file("${col.irt_Filepath}", checkifExists: true))}
.flatMap{it -> [tuple(it[0],it[1])]}
.into {input_irts; input_irts_check; input_irts_check_2}
check_irts_n = input_irts_check.toList().size().val
check_irts_n2 = input_irts_check_2.map{it[0]}.unique().toList().size().val
if ((check_irts_n > 1) & (check_irts_n != check_irts_n2)) {
print('You specified multiple DDA files to generate spectral libraries, but library merging is not set \n')
print('Set --merge_libraries and possibly --align_libraries to align them in the same RT space \n')
exit 1
}
if ((check_irts_n2 != check_dia_n)) {
print('The number of batches in the sample input does not match the number of batches of the irt input \n')
exit 1
}
} else {
input_irts = Channel.empty()
}
// MS1 option
if (params.use_ms1){
ms1_option = '-use_ms1_traces'
ms1_scoring = '-Scoring:Scores:use_ms1_mi'
ms1_mi = '-Scoring:Scores:use_mi_score'
} else {
ms1_option = ''
ms1_scoring = ''
ms1_mi = ''
}
// Force option
if (params.force_option){
force_option = '-force'
} else {
force_option = ''
}
// DIAlignR multithreading
if (params.dialignr_parallelization){
dialignr_parallel='parallel'
} else {
dialignr_parallel=''
}
////////////////////////////////////////////////////
/* -- PRINT PARAMETER SUMMARY -- */
////////////////////////////////////////////////////
log.info NfcoreSchema.params_summary_log(workflow, params, json_schema)
// Header log info
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Spectral Library'] = params.input_spectral_library
summary['Run Name'] = workflow.runName
summary['Input'] = params.input
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['Script dir'] = workflow.projectDir
summary['User'] = workflow.userName
if (workflow.profile.contains('awsbatch')) {
summary['AWS Region'] = params.awsregion
summary['AWS Queue'] = params.awsqueue
summary['AWS CLI'] = params.awscli
}
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
}
// 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: 'nf-core-diaproteomics-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'nf-core/diaproteomics Workflow Summary'
section_href: 'https://github.com/nf-core/diaproteomics'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
$x
</dl>
""".stripIndent() }
.set { ch_workflow_summary }
/*
* Parse software version numbers
*/
process get_software_versions {
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
FileInfo --help &> v_openms.txt
pyprophet --version &> v_pyprophet.txt
scrape_software_versions.py &> software_versions_mqc.yaml
"""
}
/*
* STEP 0 - Raw File Conversion
*/
process dda_raw_file_conversion {
input:
set val(id), val(sample), file(raw_file), file(dda_id_file) from input_dda_ms_files.raw
output:
set val(id), val(sample), file("${raw_file.baseName}.mzML"), file(dda_id_file) into converted_dda_input_mzmls
when:
params.generate_spectral_library
script:
"""
ThermoRawFileParser.sh -i=${raw_file} -f=2 -b=${raw_file.baseName}.mzML
"""
}
/*
* STEP 1 - Convert IDs for Spectral Library Generation using EasyPQP
*/
process dda_id_format_conversion {
input:
set val(id), val(sample), file(dda_mzml), file(dda_id_file) from input_dda_ms_files.mzml.mix(input_dda_ms_files.mzxml).mix(converted_dda_input_mzmls)
output:
set val(id), val(sample), file(dda_mzml), file("${id}_${sample}_peptide_ids.idXML") into input_dda_converted
when:
params.generate_spectral_library
script:
"""
IDFileConverter -in ${dda_id_file} -out ${id}_${sample}_peptide_ids.idXML -threads ${task.cpus}
"""
}
/*
* STEP 2 - Spectral Library Generation using EasyPQP
*/
process dda_library_generation {
input:
set val(id), val(sample), file(dda_mzml_file), file(idxml_file) from input_dda_converted
file unimod_file from input_unimod.first()
output:
set val(id), val(sample), file("${id}_${sample}_library.tsv") into input_lib_dda_nd
when:
params.generate_spectral_library
script:
"""
easypqp convert \\
--unimod ${unimod_file} \\
--pepxml ${idxml_file} \\
--spectra ${dda_mzml_file}
easypqp library \\
--out ${dda_mzml_file.baseName}_run_peaks.tsv \\
--rt_psm_fdr_threshold ${params.library_rt_fdr} \\
--nofdr \\
${dda_mzml_file.baseName}.psmpkl \\
${dda_mzml_file.baseName}.peakpkl
mv ${dda_mzml_file.baseName}_run_peaks.tsv ${id}_${sample}_library.tsv
"""
}
/*
* STEP 3 - Assay Generation for Spectral Library
*/
process assay_generation {
input:
set val(id), val(sample), file(lib_file_na) from input_lib.mix(input_lib_dda_nd)
output:
set val(id), val(sample), file("${id}_${sample}_assay.tsv") into (input_lib_assay, input_lib_assay_for_irt, input_lib_assay_for_merging)
when:
!params.skip_decoy_generation
script:
"""
TargetedFileConverter \\
-in ${lib_file_na} \\
-out ${lib_file_na.baseName}.tsv \\
-threads ${task.cpus}
OpenSwathAssayGenerator \\
-in ${lib_file_na.baseName}.tsv \\
-min_transitions ${params.min_transitions} \\
-max_transitions ${params.max_transitions} \\
-out ${id}_${sample}_assay.tsv \\
-threads ${task.cpus}
"""
}
if(params.merge_libraries) {
input_lib_assay = Channel.empty()
input_lib_assay_for_irt = Channel.empty()
}
/*
* STEP 4 - Merge and align spectral Libraries
*/
process library_merging_and_alignment {
publishDir "${params.outdir}/spectral_library_files"
input:
set val(id), val(sample), file(lib_files_for_merging) from input_lib_assay_for_merging.groupTuple(by:1)
output:
set val(id), val(sample), file("${sample}_library_merged.tsv") into (input_lib_assay_merged, input_lib_assay_merged_for_irt)
set val(id), val(sample), file("*.png") optional true
when:
params.merge_libraries
script:
"""
merge_and_align_libraries_from_easypqp.py \\
--input_libraries ${lib_files_for_merging} \\
--min_overlap ${params.min_overlap_for_merging} \\
--rsq_threshold 0.75 \\
--output ${sample}_library_merged.tsv \\
${align_flag}
"""
}
/*
* STEP 5 - Pseudo iRT Library Generation
*/
process pseudo_irt_generation {
publishDir "${params.outdir}/spectral_library_files"
input:
set val(id), val(sample), file(lib_file_assay_irt) from input_lib_assay_for_irt.mix(input_lib_assay_merged_for_irt)
output:
set val(sample), file("${lib_file_assay_irt.baseName}_pseudo_irts.pqp") into input_lib_assay_irt_2
when:
params.generate_pseudo_irts
script:
"""
select_pseudo_irts_from_lib.py \\
--input_libraries ${lib_file_assay_irt} \\
--min_rt 0 \\
--n_irts ${params.n_irts} \\
--max_rt 100 \\
--output ${lib_file_assay_irt.baseName}_pseudo_irts.tsv \\
${quant_flag}
TargetedFileConverter \\
-in ${lib_file_assay_irt.baseName}_pseudo_irts.tsv \\
-out ${lib_file_assay_irt.baseName}_pseudo_irts.pqp \\
-threads ${task.cpus}
"""
}
/*
* STEP 6 - Decoy Generation for Spectral Library
*/
process decoy_generation {
publishDir "${params.outdir}/spectral_library_files"
input:
set val(id), val(sample), file(lib_file_nd) from input_lib_assay.mix(input_lib_assay_merged)
output:
set val(id), val(sample), file("${lib_file_nd.baseName}_decoy.pqp") into input_lib_decoy
when:
!params.skip_decoy_generation
script:
"""
TargetedFileConverter \\
-in ${lib_file_nd} \\
-out ${lib_file_nd.baseName}.pqp \\
-threads ${task.cpus}
OpenSwathDecoyGenerator \\
-in ${lib_file_nd.baseName}.pqp \\
-method ${params.decoy_method} \\
-out ${lib_file_nd.baseName}_decoy.pqp \\
-threads ${task.cpus}
"""
}
/*
* STEP 7 - DIA Raw File Conversion
*/
process dia_raw_file_conversion {
input:
set val(id), val(sample), val(condition), file(raw_file) from input_dia_ms_files.raw
output:
set val(id), val(sample), val(condition), file("${raw_file.baseName}.mzML") into converted_dia_input_mzmls
when:
!params.skip_dia_processing
script:
"""
ThermoRawFileParser.sh -i=${raw_file} -f=2 -b=${raw_file.baseName}.mzML
"""
}
/*
* STEP 8 - DIA library search with OpenSwathWorkFlow
*/
process dia_spectral_library_search {
publishDir "${params.outdir}/openswathworkflow_output"
label 'process_medium'
input:
set val(sample), val(id), val(condition), file(mzml_file), val(dummy_id), file(lib_file), file(irt_file) from converted_dia_input_mzmls.mix(input_dia_ms_files.mzml.mix(input_dia_ms_files.mzxml)).combine(input_lib_decoy.mix(input_lib_nd), by:1).combine(input_irts.mix(input_lib_assay_irt_2), by:0)
output:
set val(id), val(sample), val(condition), file("${mzml_file.baseName}_chrom.mzML") into chromatogram_files
set val(id), val(sample), val(condition), file("${mzml_file.baseName}.osw") into osw_files
set val(id), val(sample), file("${lib_file.baseName}.pqp") into (input_lib_used, input_lib_used_I, input_lib_used_I_mztab)
when:
!params.skip_dia_processing
script:
"""
mkdir tmp
TargetedFileConverter \\
-in ${lib_file} \\
-out ${lib_file.baseName}.pqp \\
-threads ${task.cpus}
TargetedFileConverter \\
-in ${irt_file} \\
-out ${irt_file.baseName}.pqp \\
-threads ${task.cpus}
OpenSwathWorkflow \\
-in ${mzml_file} \\
-tr ${lib_file.baseName}.pqp \\
-sort_swath_maps \\
-tr_irt ${irt_file.baseName}.pqp \\
-min_rsq ${params.irt_min_rsq} \\
-out_osw ${mzml_file.baseName}.osw \\
-out_chrom ${mzml_file.baseName}_chrom.mzML \\
-mz_extraction_window ${params.mz_extraction_window} \\
-mz_extraction_window_ms1 ${params.mz_extraction_window_ms1} \\
-mz_extraction_window_unit ${params.mz_extraction_window_unit} \\
-mz_extraction_window_ms1_unit ${params.mz_extraction_window_ms1_unit} \\
-rt_extraction_window ${params.rt_extraction_window} \\
-min_upper_edge_dist ${params.min_upper_edge_dist} \\
-RTNormalization:alignmentMethod ${params.irt_alignment_method} \\
-RTNormalization:estimateBestPeptides \\
-RTNormalization:outlierMethod none \\
-RTNormalization:NrRTBins ${params.irt_n_bins} \\
-RTNormalization:MinBinsFilled ${params.irt_min_bins_covered} \\
-mz_correction_function quadratic_regression_delta_ppm \\
-Scoring:stop_report_after_feature 5 \\
-Scoring:TransitionGroupPicker:compute_peak_quality false \\
-Scoring:TransitionGroupPicker:peak_integration 'original' \\
-Scoring:TransitionGroupPicker:background_subtraction 'none' \\
-Scoring:TransitionGroupPicker:PeakPickerMRM:sgolay_frame_length 11 \\
-Scoring:TransitionGroupPicker:PeakPickerMRM:sgolay_polynomial_order 3 \\
-Scoring:TransitionGroupPicker:PeakPickerMRM:gauss_width 30 \\
-Scoring:TransitionGroupPicker:PeakPickerMRM:use_gauss 'false' \\
-Scoring:TransitionGroupPicker:PeakIntegrator:integration_type 'intensity_sum' \\
-Scoring:TransitionGroupPicker:PeakIntegrator:baseline_type 'base_to_base' \\
-Scoring:TransitionGroupPicker:PeakIntegrator:fit_EMG 'false' \\
-batchSize 1000 \\
-readOptions ${params.cache_option} \\
-tempDirectory tmp \\
-Scoring:DIAScoring:dia_nr_isotopes 3 \\
-enable_uis_scoring \\
-Scoring:uis_threshold_sn -1 \\
-threads ${task.cpus} \\
${force_option} ${ms1_option} ${ms1_scoring} ${ms1_mi}
"""
}
/*
* STEP 9 - Pyprophet merging of OpenSwath results
*/
process dia_search_output_merging {
input:
set val(sample), val(id), val(condition), file(all_osws), val(dummy_id), file(lib_file_template) from osw_files.groupTuple(by:1).join(input_lib_used, by:1)
output:
set val(id), val(sample), val(condition), file("${sample}_osw_file_merged.osw") into merged_osw_file_for_global
when:
!params.skip_dia_processing
script:
"""
pyprophet merge \\
--template=${lib_file_template} \\
--out=${sample}_osw_file_merged.osw \\
--no-same_run \\
${all_osws}
"""
}
/*
* STEP 10 - Pyprophet global FDR Scoring
*/
process global_false_discovery_rate_estimation {
publishDir "${params.outdir}/pyprophet_output"
label 'process_high_mem'
input:
set val(id), val(sample), val(condition), file(scored_osw) from merged_osw_file_for_global
output:
set val(id), val(sample), val(condition), file("${scored_osw.baseName}_global_merged.osw") into merged_osw_scored_global_for_pyprophet
set val(id), val(sample), val(condition), file("*.pdf") into target_decoy_global_score_plots
when:
!params.skip_dia_processing
script:
if (params.pyprophet_classifier=='LDA'){
"""
pyprophet score \\
--in=${scored_osw} \\
--level=${params.pyprophet_fdr_ms_level} \\
--out=${scored_osw.baseName}_scored.osw \\
--classifier=${params.pyprophet_classifier} \\
--pi0_lambda ${params.pyprophet_pi0_start} ${params.pyprophet_pi0_end} ${params.pyprophet_pi0_steps} \\
--threads=${task.cpus}
pyprophet peptide \\
--in=${scored_osw.baseName}_scored.osw \\
--out=${scored_osw.baseName}_global_merged.osw \\
--context=run-specific
pyprophet peptide --in=${scored_osw.baseName}_global_merged.osw --context=experiment-wide
pyprophet peptide --in=${scored_osw.baseName}_global_merged.osw --context=global
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=run-specific
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=experiment-wide
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=global
"""
} else {
"""
pyprophet score \\
--in=${scored_osw} \\
--level=${params.pyprophet_fdr_ms_level} \\
--out=${scored_osw.baseName}_scored.osw \\
--classifier=${params.pyprophet_classifier} \\
--threads=${task.cpus}
pyprophet peptide \\
--in=${scored_osw.baseName}_scored.osw \\
--out=${scored_osw.baseName}_global_merged.osw \\
--context=run-specific
pyprophet peptide --in=${scored_osw.baseName}_global_merged.osw --context=experiment-wide
pyprophet peptide --in=${scored_osw.baseName}_global_merged.osw --context=global
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=run-specific
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=experiment-wide
pyprophet ${params.pyprophet_global_fdr_level} --in=${scored_osw.baseName}_global_merged.osw --context=global
"""
}
}
/*
* STEP 11 - Pyprophet Export
*/
process export_of_scoring_results {
publishDir "${params.outdir}/pyprophet_output"
input:
set val(id), val(sample), val(condition), file(global_osw) from merged_osw_scored_global_for_pyprophet
output:
set val(id), val(sample), val(condition), file("*.tsv") into pyprophet_results
set val(id), val(sample), val(condition), file(global_osw) into osw_for_dialignr
when:
!params.skip_dia_processing
script:
"""
pyprophet export \\
--in=${global_osw} \\
--max_rs_peakgroup_qvalue=${params.pyprophet_peakgroup_fdr} \\
--max_global_peptide_qvalue=${params.pyprophet_peptide_fdr} \\
--max_global_protein_qvalue=${params.pyprophet_protein_fdr} \\
--out=legacy.tsv
"""
}
/*
* STEP 12 - Index Chromatogram mzMLs
*/
process chromatogram_indexing {
label 'process_high'
input:
set val(id), val(sample), val(condition), file(chrom_file_noindex) from chromatogram_files
output:
set val(id), val(sample), val(condition), file("${chrom_file_noindex.baseName.split('_chrom')[0]}.chrom.sqMass") into chromatogram_files_indexed
when:
!params.skip_dia_processing
script:
"""
FileConverter \\
-in ${chrom_file_noindex} \\
-process_lowmemory \\
-out ${chrom_file_noindex.baseName.split('_chrom')[0]}.chrom.mzML
OpenSwathMzMLFileCacher \\
-in ${chrom_file_noindex.baseName.split('_chrom')[0]}.chrom.mzML \\
-lossy_compression false \\
-process_lowmemory \\
-lowmem_batchsize 50000 \\
-out ${chrom_file_noindex.baseName.split('_chrom')[0]}.chrom.sqMass
"""
}
// Combine channels of osw files and osw chromatograms
osw_for_dialignr
.transpose()
.join(chromatogram_files_indexed, by:1)
.groupTuple(by:0)
// Channel contains now the following elements:
// ([id, [samples], [conditions], [osw_files], id_2, condition_2, [chromatogram_files]])
.flatMap{it -> [tuple(it[0],it[1].unique()[0],it[2].unique()[0],it[3].unique()[0],it[4],it[5],it[6])]}
.set{osw_and_chromatograms_combined_by_condition}
/*
* STEP 13 - Align DIA Chromatograms using DIAlignR
*/
process chromatogram_alignment {
publishDir "${params.outdir}/"
label 'process_high_mem'
input:
set val(sample), val(id), val(condition), file(pyresults), val(id_dummy), val(condition_dummy), file(chrom_files_index) from osw_and_chromatograms_combined_by_condition
output:
set val(id), val(sample), val(condition), file("${sample}_peptide_quantities.csv") into (DIALignR_result, DIALignR_result_I, DIALignR_result_mztab)
when:
!params.skip_dia_processing
script:
"""
mkdir osw
mv ${pyresults} osw/
mkdir xics
mv *.chrom.sqMass xics/
DIAlignR.R \\
${params.dialignr_global_align_fdr} \\
${params.dialignr_analyte_fdr} \\
${params.dialignr_unalign_fdr} \\
${params.dialignr_align_fdr} \\
${params.dialignr_query_fdr} \\
${params.pyprophet_global_fdr_level} \\
${params.dialignr_xicfilter} \\
${dialignr_parallel} \\
${task.cpus}
mv DIAlignR.tsv ${sample}_peptide_quantities.csv
"""
}
/*
* STEP 14 - Reformat output for MSstats: Combine with experimental design and missing columns from input library
*/
process reformatting {
publishDir "${params.outdir}/"
input:
set val(id), val(sample), val(condition), file(dialignr_file) from DIALignR_result
file exp_design from input_exp_design.first()
set val(id), val(sample_lib), file(lib_file) from input_lib_used_I.first()
output:
set val(id), val(sample), val(condition), file("${sample}_${condition}.csv") into msstats_file
when:
params.run_msstats
script:
if (params.pyprophet_global_fdr_level==''){
"""
TargetedFileConverter \\
-in ${lib_file} \\
-out ${lib_file.baseName}.tsv
reformat_output_for_msstats.py \\
--input ${dialignr_file} \\
--exp_design ${exp_design} \\
--library ${lib_file.baseName}.tsv \\
--fdr_level "none" \\
--output "${sample}_${condition}.csv"
"""
} else {
"""
TargetedFileConverter -in ${lib_file} -out ${lib_file.baseName}.tsv
reformat_output_for_msstats.py \\
--input ${dialignr_file} \\
--exp_design ${exp_design} \\
--library ${lib_file.baseName}.tsv \\
--fdr_level ${params.pyprophet_global_fdr_level} \\
--output "${sample}_${condition}.csv"
"""
}
}
/*
* STEP 14.5 - export_mztab
*/
process mztab_export {
publishDir "${params.outdir}/"
input:
set val(id), val(sample), val(condition), file(dialignr_file) from DIALignR_result_mztab
file exp_design from input_exp_design_mztab.first()
set val(id), val(sample_lib), file(lib_file) from input_lib_used_I_mztab.first()
output:
set val(id), val(sample), val(condition), file("${sample}_${condition}.mzTab") into mztab_file
when:
params.mztab_export
script:
"""
TargetedFileConverter -in ${lib_file} -out ${lib_file.baseName}.tsv
mztab_output.py \\
--input ${dialignr_file} \\
--exp_design ${exp_design} \\
--library ${lib_file.baseName}.tsv \\
--fdr_level ${params.pyprophet_global_fdr_level} \\
--fdr_threshold_pep ${params.pyprophet_peptide_fdr} \\
--fdr_threshold_prot ${params.pyprophet_protein_fdr} \\
--ms1_scoring ${params.use_ms1} \\
--rt_extraction_window ${params.rt_extraction_window} \\
--mz_extraction_window ${params.mz_extraction_window} \\
--mz_extraction_window_ms1 ${params.mz_extraction_window_ms1} \\
--mz_extraction_unit ${params.mz_extraction_window_unit} \\
--mz_extraction_unit_ms1 ${params.mz_extraction_window_ms1_unit} \\
--dialignr_global_align_fdr ${params.dialignr_global_align_fdr} \\
--dialignr_analyte_fdr ${params.dialignr_analyte_fdr} \\
--dialignr_unalign_fdr ${params.dialignr_unalign_fdr} \\
--dialignr_align_fdr ${params.dialignr_align_fdr} \\
--dialignr_query_fdr ${params.dialignr_query_fdr} \\
--workflow_version $workflow.manifest.version \\
--output "${sample}_${condition}.mzTab"
"""
}
/*
* STEP 15 - Run MSstats
*/
process statistical_post_processing {
publishDir "${params.outdir}/"
label 'process_low'
input:
set val(id), val(sample), val(condition), file(csv) from msstats_file.groupTuple(by:1)
output:
file "*.pdf" optional true // Output plots: 1) Comparative plots across pairwise conditions, 2) VolcanoPlot
file "*.csv" // Csv of normalized differential protein abundancies calculated by msstats
file "*.log" // logfile of msstats run
when:
params.run_msstats
script:
"""
msstats.R > msstats.log || echo "Optional MSstats step failed. Please check logs and re-run or do a manual statistical analysis."
"""
}
/*
* STEP 16 - Generate plots describing output:
* 1) BarChartProtein/Peptide Counts
* 2) Pie Chart: Peptide Charge distribution
* 3) Density Scatter: Library vs run RT deviations for all identifications
* 4) Heatmap: Peptide quantities across MS runs
* 5) Pyprophet score plots
*/
process output_visualization {
publishDir "${params.outdir}/"
label 'process_high'
input:
set val(sample), val(id), val(condition), file(quantity_csv_file), val(dummy_id), val(dummy_condition), file(pyprophet_tsv_file) from DIALignR_result_I.transpose().join(pyprophet_results, by:1)
output:
file "*.pdf" into output_plots
when:
params.generate_plots
script:
"""
plot_quantities_and_counts.R ${sample}