-
Notifications
You must be signed in to change notification settings - Fork 2
/
MTXQCvX_part3_template_params.Rmd
264 lines (205 loc) · 8.38 KB
/
MTXQCvX_part3_template_params.Rmd
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
---
title: "MTXQCvX - Part3: ManualValidation template"
thanks: "Template MTXQCvX part3 written by Christin Zasada, Kempa Lab"
author:
- affiliation: LABNAME
name: NAME
- affiliation: LABNAME
name: NAME
biblio-style: apsr
output:
pdf_document:
citation_package: natbib
fig_caption: yes
keep_tex: yes
toc: yes
latex_engine: pdflatex
template: config_files/textemplate.tex
html_document: default
fontsize: 9pt
geometry: margin=1in
keywords: MTXQCvX, manual validation
date: "`r format(Sys.time(), '%V %d, %Y')`"
fontfamily: mathpazo
params:
spath:
input: text
label: "Run on MTXQC-subfolder:"
value: "test_metmax"
folder:
input: text
label: "Define folder where to export and import files."
value: "manval"
prep:
choices:
- none
- PeakArea
- Incorporation
input: select
label: "Prepare data for manual validation:"
value: none
eval:
choices: [none, PeakArea, Incorporation]
input: select
label: "Integration of manually validated data:"
value: Incorporation
inputformat:
input: select
label: "Choose the kind of input format of your data."
choices: [maui, metmax]
value: metmax
abstract: This document provides the manual validation of GC-MS derived data (MTXQC part 3). Thats has been processed through MTXQCvX part1 before. It transforms your MAUI exports into easily modifiable tables (PrepData) and re-transform them after manual validation into csv-files usable for another round of MTXQC (EvalQuant; EvalInc). In case of Metmax input files run MTXQC part 4 first.
---
# Data transformation for convenient manual validation
```{r quitknitting_immediately, echo=FALSE}
#if (params$inputformat != "maui") {
# message("This input format is currently not integrated in this module! Sorry!")
# knitr::knit_exit()
#}
if ((params$prep != "none") & (params$eval != "none")) {
message("Please select only one action at a time - eiter data transformation or data integration!")
knitr::knit_exit()
}
```
```{r init_directory, warning=FALSE, echo=FALSE}
#MOD!
set_input = "input/"
set_output = "output/"
## subfolder for postprocessing
set_val = paste0(params$folder, "/")
if (set_val == "") {
message("Please define a folder!")
knitr::knit_exit()
}
#directory definition and figure_name definition
if (params$spath == "") {
path_setup = ""
set_fig = paste0(path_setup, 'figure/MTXQCp3-')
} else {
path_setup = paste0(params$spath, "/")
set_fig = paste0(path_setup, 'figure/MTXQCp3-')
}
knitr::opts_chunk$set(fig.width = 5, fig.align = 'center', fig.height = 4,
fig.path = set_fig,
echo = FALSE, #TRUE - show R code
warning = FALSE, #show warnings
message = TRUE) #show messages
#Create a folder and stop processing if it is already present performing PrepData
if (params$prep != "none") {
if (!dir.exists(file.path(paste0(path_setup, set_output, set_val)))) {
dir.create(paste0(path_setup, set_output, set_val))
} else {
message("Folder already exists! Please define a new folder where to save transformed data.")
}
}
```
# Choose the mode of the document!
```{r modeofdoc}
message("Data transformation performed for: ", params$prep)
message("Data integration perfomed for: ", params$eval)
```
# Input files
```{r init_project}
#MOD!
library(reshape2)
library(ggplot2)
library(plyr)
source('R/MTXQC_config.R')
source("R/MTXQC_fcn.R")
source("R/MTXQC_fcn_part3.R")
source("R/MTXQC_fcn_incorp.R")
source("R/MTXQC_fcn_absQ.R")
#import parameter: MTXQCsetup
if (file.exists(paste0(path_setup, "MTXQC_params.csv"))) {
setup_params <- read.csv(paste0(path_setup, "MTXQC_params.csv"), TRUE)
message("MTXQCparams.csv imported!")
} else {
message("Please run MTXQCvX_ExperimentalSetup in order to create MTXQC_params.csv")
knitr::knit_exit()
}
inp_format = as.character(setup_params[which(setup_params$Parameter == "inputformat"), "Value"])
#import parameter for input files:
if (inp_format == "metmax") {
if (file.exists(paste0(path_setup, "Metmax_params.csv"))) {
id_settings = read.csv(paste0(path_setup, "Metmax_params.csv"))
message("Metmax_params.csv imported.")
} else {
message("Metmax_params.csv not detected! Check defined input format!")
knitr::knit_exit()
}
} else {
if (file.exists(paste0(path_setup, "Maui_params.csv"))) {
id_settings = read.csv(paste0(path_setup, "Maui_params.csv"))
message("Maui_params.csv imported.")
} else {
message("Maui_params.csv not detected! Check defined input format!")
knitr::knit_exit()
}
}
```
```{r prepdata}
if (params$prep == "PeakArea") {
## (1) Absolute Quantification ##
#PeakArea (derived from: MAUI or Metmax (after processed by MTXQC part 4))
if (inp_format == "maui") {
nick_peakarea = as.character(id_settings[which(id_settings$Parameter == "matrix"), "Value"])
data_quant = read.csv(paste0(path_setup, set_input, "quant/", nick_peakarea), T)
message("PeakAreaMatrix imported: ", nick_peakarea)
} else {
data_quant = read.csv(paste0(path_setup, set_input, "quant/quantMassAreasMatrix.csv"), T)
message("PeakAreaMatrix imported: quant/quantMassAreasMatrix.csv")
}
#PeakAreaMatrix
transform_quant(data_quant)
}
if (params$prep == "Incorporation") {
## (2) Isotope Incorporation ##
# (i) SpectraExport (MAUI or Metmax & MTXQC part 4), (ii) calculated isotope
# incorporation rates (MAUI, Metmax), (iii) MTXQCp1 generated output file
# evaluation MID quality
#nick_mid = as.character(id_settings[which(id_settings$Parameter == "mid"), "Value"])
#independent import of pSIRM_SpectraData.csv of input format
data_mid = read.csv(paste0(path_setup, set_input, "inc/pSIRM_SpectraData.csv"), TRUE)
message("Checked: MIDs imported: inc/pSIRM_SpectraData.csv")
#nick_inc = as.character(id_settings[which(id_settings$Parameter == "inc_data"), "Value"])
#data_original = read.csv(paste0(path_setup, set_input, "inc/", nick_inc), T)
#message("Imported Incorporation data: ", nick_inc)
se_val = read.csv(paste0(path_setup, set_output,
"inc/SE_classification.csv"), T)
message("Imported SE_classification.csv generated by MTXQC_part1.")
#Incorporation
transform_inc(df_se_val = se_val, df_mid = data_mid, conversion_table = con_se)
}
```
```{r evalQuant, tidy = TRUE, results='asis'}
if (params$eval == 'PeakArea') {
## quantities
quant_man = read.csv(paste0(path_setup, set_output, set_val, 'ManVal_PeakAreas.csv'), T)
evaluate_peakareas(quant_man)
}
```
```{r evalInc, tidy = TRUE, results='asis', fig.width=5}
if (params$eval == 'Incorporation') {
ifelse(!dir.exists(file.path(paste0(path_setup, set_output, set_val, 'inc'))),
dir.create(paste0(path_setup, set_output, set_val, 'inc')),
FALSE)
#MID import of manual validated values
table_mid = read.csv(paste0(path_setup, set_output, set_val,
'MID_validation_values.csv'), T)
#Extraction of updated values
cor_mids = evaluate_modified_mids(df_check = table_mid)
#Original MID-File
orig_mids = read.csv(paste0(path_setup, set_input, "inc/pSIRM_SpectraData.csv"), T)
#Integration updated MIDs into original table
pSIRM_manVal <- integrate_manVal_MIDs(dataframe = table_mid, #all MIDs including updated values
corrected_mids = cor_mids, #extracted unique entries manVal
original_mids = orig_mids) #original MID data
#Calculate corrected isotope incorporation
table_sel = merge(table_mid, cor_mids)
inc_calc_updated = calculate_isotope_incorporation(table_sel, backup_mids, mass_li, manval = TRUE)
#integration new values into original file -> DataMatrix.csv
nick_inc = as.character(id_settings[which(id_settings$Parameter == "inc_data"), "Value"])
data_original = read.csv(paste0(path_setup, set_input, "inc/", nick_inc), T)
integrate_calc_inc(data_original, inc_calc_updated)
}
```