-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrequantification.smk
216 lines (192 loc) · 9.83 KB
/
requantification.smk
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
# Re-quantify the features in all data (missing values only)
import glob
from os.path import join
# 1) Split the consensus map to features with no missing values (complete) and features with missing values (missing) and re-load the complete consensus to individual feature maps
rule split_consensus:
input:
in_cmap= join("results", "Interim", "Preprocessing", "consenus_features.consensusXML"),
output:
out_complete= join("results", "Interim", "Requantification", "Complete.consensusXML"),
out_missing= join("results", "Interim", "Requantification", "Missing.consensusXML")
log: join("workflow", "report", "logs", "Requantification", "split_consensus.log")
threads: config["system"]["threads"]
conda:
join("..", "envs", "pyopenms.yaml")
shell:
"""
python workflow/scripts/split.py {input.in_cmap} {output.out_complete} {output.out_missing} > /dev/null 2>> {log}
"""
rule reload_maps:
input:
in_aligned= join("results", "Interim", "Preprocessing", "MapAligned_{samples}.featureXML"),
in_complete= join("results", "Interim", "Requantification", "Complete.consensusXML")
output:
out_complete= join("results", "Interim", "Requantification", "Complete_{samples}.featureXML")
log: join("workflow", "report", "logs", "Requantification", "reload_maps_{samples}.log")
threads: config["system"]["threads"]
conda:
join("..", "envs", "pyopenms.yaml")
shell:
"""
python workflow/scripts/reloadmaps.py {input.in_aligned} {input.in_complete} {output.out_complete} > /dev/null 2>> {log}
"""
# 2) Build a library of features from the consensus with missing values
rule text_export:
input:
join("results", "Interim", "Requantification", "Missing.consensusXML")
output:
join("results", "Interim", "Requantification", "FeatureQuantificationTable.txt")
log: join("workflow", "report", "logs", "Requantification", "text_export.log")
conda:
join("..", "envs", "openms.yaml")
shell:
"""
TextExporter -in {input} -out {output} -no_progress -log {log} 2>> {log}
"""
rule build_library:
input:
matrix= join("results", "Interim", "Requantification", "FeatureQuantificationTable.txt")
output:
lib= join("results", "Interim", "Requantification", "MetaboliteNaN.tsv")
log: join("workflow", "report", "logs", "Requantification", "build_library.log")
threads: config["system"]["threads"]
conda:
join("..", "envs", "pyopenms.yaml")
params:
script = ("workflow/scripts/metaboliteNaN_pos.py"
if config["adducts"]["ion_mode"] == "positive" else
"workflow/scripts/metaboliteNaN_neg.py")
shell:
"""
python {params.script} {input.matrix} {output.lib} > /dev/null 2>> {log}
"""
# 3) Re-quantify all the raw files to cover missing values (missing value imputation can be avoided with that step)
rule requantify:
input:
var1= join("results", "Interim", "Requantification", "MetaboliteNaN.tsv"),
var2= join("results", "Interim", "mzML", "Aligned_{samples}.mzML")
output:
join("results", "Interim", "Requantification", "FFMID_{samples}.featureXML")
log: join("workflow", "report", "logs", "Requantification", "requantify_{samples}.log")
conda:
join("..", "envs", "openms.yaml")
params:
mz_window= config["requantification"]["mz_window"],
rt_window= config["requantification"]["RT_window"],
threads: config["system"]["threads"]
shell:
"""
FeatureFinderMetaboIdent -id {input.var1} -in {input.var2} -out {output} -extract:mz_window {params.mz_window} -extract:rt_window {params.rt_window} -threads {threads} -no_progress -log {log} 2>> {log}
"""
# 4) Merge the re-quantified with the complete feature files
rule merge:
input:
in_complete= join("results", "Interim", "Requantification", "Complete_{samples}.featureXML"),
in_requant= join("results", "Interim", "Requantification", "FFMID_{samples}.featureXML")
output:
out_merged= join("results", "Interim", "Requantification", "Merged_{samples}.featureXML")
log: join("workflow", "report", "logs", "Requantification", "merge_{samples}.log")
threads: config["system"]["threads"]
conda:
join("..", "envs", "pyopenms.yaml")
shell:
"""
python workflow/scripts/merge.py {input.in_complete} {input.in_requant} {output.out_merged} > /dev/null 2>> {log}
"""
# 5) Decharger: Decharging algorithm for adduct assignment
rule adduct_annotations_FFMident:
input:
join("results", "Interim", "Requantification", "Merged_{sample}.featureXML")
output:
join("results", "Interim", "Requantification", "MFD_{sample}.featureXML")
log:
join("workflow", "report", "logs", "Requantification", "adduct_annotations_FFMident_{sample}.log")
conda:
join("..", "envs", "openms.yaml")
params:
adducts = config["adducts"]["adducts_pos"] if config["adducts"]["ion_mode"] == "positive" else config["adducts"]["adducts_neg"],
ion_mode_flag = "" if config["adducts"]["ion_mode"] == "positive" else "-algorithm:MetaboliteFeatureDeconvolution:negative_mode",
charge_params = ("-algorithm:MetaboliteFeatureDeconvolution:charge_max 1 "
"-algorithm:MetaboliteFeatureDeconvolution:charge_span_max 1 "
"-algorithm:MetaboliteFeatureDeconvolution:max_neutrals 1")
if config["adducts"]["ion_mode"] == "positive" else
("-algorithm:MetaboliteFeatureDeconvolution:charge_max 0 "
"-algorithm:MetaboliteFeatureDeconvolution:charge_min -2 "
"-algorithm:MetaboliteFeatureDeconvolution:charge_span_max 3 "
"-algorithm:MetaboliteFeatureDeconvolution:max_neutrals 1")
shell:
"""
MetaboliteAdductDecharger -in {input} -out_fm {output} {params.ion_mode_flag} -algorithm:MetaboliteFeatureDeconvolution:potential_adducts {params.adducts} {params.charge_params} -algorithm:MetaboliteFeatureDeconvolution:retention_max_diff "3.0" -algorithm:MetaboliteFeatureDeconvolution:retention_max_diff_local "3.0" -no_progress -log {log} 2>> {log}
"""
# 6) Introduce the features to a protein identification file (idXML)- the only way to annotate MS2 spectra for GNPS FBMN
rule IDMapper_FFMident:
input:
var1= join("resources", "emptyfile.idXML"),
var2= join("results", "Interim", "Requantification", "MFD_{samples}.featureXML"),
var3= join("results", "Interim", "mzML", "Aligned_{samples}.mzML")
output:
join("results", "Interim", "Requantification", "IDMapper_{samples}.featureXML")
log: join("workflow", "report", "logs", "Requantification", "IDMapper_FFMident_{samples}.log")
conda:
join("..", "envs", "openms.yaml")
shell:
"""
IDMapper -id {input.var1} -in {input.var2} -spectra:in {input.var3} -out {output} -no_progress -log {log} 2>> {log}
"""
# 7) The FeatureLinkerUnlabeledKD is used to aggregate the feature information (from single files) into a ConsensusFeature, linking features from different sfiles together, which have a smiliar m/z and RT (MS1 level).
rule FeatureLinker_FFMident:
input:
expand(join("results", "Interim", "Requantification", "IDMapper_{samples}.featureXML"), samples=SUBSAMPLES)
output:
join("results", "Interim", "Requantification", "consenus_features_unfiltered.consensusXML")
log: join("workflow", "report", "logs", "Requantification", "FeatureLinker_FFMident.log")
conda:
join("..", "envs", "openms.yaml")
params:
mz_tol= config["featurelink"]["mz_tol"],
rt_tol= config["featurelink"]["rt_tol"],
threads: config["system"]["threads"]
shell:
"""
FeatureLinkerUnlabeledKD -in {input} -out {output} -algorithm:warp:enabled false -algorithm:link:rt_tol {params.rt_tol} -algorithm:link:mz_tol {params.mz_tol} -threads {threads} -no_progress -log {log} 2>> {log}
"""
# 8) Filter out consensus features with too many missing values (skipped unless min_frac value changes).
rule missing_values_filter_req:
input:
join("results", "Interim", "Requantification", "consenus_features_unfiltered.consensusXML")
output:
join("results", "Interim", "Requantification", "consenus_features.consensusXML")
log: join("workflow", "report", "logs", "Requantification", "MissingValuesFilter.log")
conda:
join("..", "envs", "pyopenms.yaml")
threads: config["system"]["threads"]
shell:
"""
python workflow/scripts/missing_values_filter.py {input} {output} 0.0 > /dev/null 2>> {log}
"""
# 9) Export the consensusXML file to a tsv file to produce a single feature matrix for downstream processing.
rule FFMident_matrix:
input:
input_cmap= join("results", "Interim", "Requantification", "consenus_features.consensusXML")
output:
output_tsv= join("results", "Interim", "Requantification", "FeatureMatrix.tsv")
log: join("workflow", "report", "logs", "Requantification", "FFMident_matrix.log")
conda:
join("..", "envs", "pyopenms.yaml")
shell:
"""
python workflow/scripts/export_consensus.py {input.input_cmap} {output.output_tsv} > /dev/null 2>> {log}
"""
# 10) Clean-up Feature Matrix.
rule FFMID_cleanup:
input:
join("results", "Interim", "Requantification", "FeatureMatrix.tsv")
output:
join("results", "Requantification", "FeatureMatrix.tsv")
log: join("workflow", "report", "logs", "Requantification", "cleanup_feature_matrix.log")
conda:
join("..", "envs", "pyopenms.yaml")
shell:
"""
python workflow/scripts/cleanup_feature_matrix.py {input} {output} > /dev/null 2>> {log}
"""