-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathraw_data_processing.Rmd
More file actions
executable file
·360 lines (271 loc) · 10.9 KB
/
Copy pathraw_data_processing.Rmd
File metadata and controls
executable file
·360 lines (271 loc) · 10.9 KB
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
---
title: "Raw MS data processing using massprocesser"
author:
- name: Xiaotao Shen (https://www.shenxt.info/)
date: "Created on 2020-04-01 and updated on `r Sys.Date()`"
output:
html_document:
df_print: paged
toc: no
pdf_document:
toc: no
vignette: >
%\VignetteIndexEntry{raw_data_processing}
%\VignettePackage{massprocesser}
% \VignetteEngine{knitr::rmarkdown}
% \usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
# fig.width = 7,
# fig.height = 5,
warning = FALSE,
message = TRUE,
out.width = "100%"
)
```
***
---
# **Download demo data**
---
Raw data can be downloaded from the Google drive. [Link is here](https://drive.google.com/file/d/15OheYiPbqK7Bq8hdEvP9hdA0ER20P-xm/view?usp=sharing)
---
# **Data preparation**
---
*massprocesser* can used to processed the raw MS data for peak detection and alignment, and generate a peak table for next analysis.
The MS raw data from Mass Spectrometry should be converted to `mzXML` or `mzML`format and then placed in different folders according to their class, for example `Subject`, `QC`, and `Blank` samples.

You can convert raw MS data to `mzXML` or `mzML` format using [`ProteoWizard` software](http://proteowizard.sourceforge.net/). And the parameter setting is shown the below figure:

---
# **Data organization**
---
All the `mzXML` format files should be placed in different folder according to sample type, such as `QC`, `Subject`, `Control`, `Case`, and `Blank`.

---
# **Run `process_data()`** function
---
This function is used to peak picking and peak alignment.
```{r,eval=FALSE,warning=FALSE, R.options="", message=FALSE}
library(massprocesser)
library(tidyverse)
library(xcms)
library(MSnbase)
library(mzR)
```
## **Data processing**
Next, we use the `process_data()` function for peak detection and alignment.
We first do the positive mode.
```{r,eval=TRUE,warning=FALSE, message=FALSE,R.options="",cache=TRUE, message=FALSE}
massprocesser::process_data(
path = "massprocesser_demo_data/POS/",
polarity = "positive",
ppm = 15,
peakwidth = c(10, 60),
snthresh = 5,
noise = 500,
threads = 6,
output_tic = TRUE,
output_bpc = TRUE,
output_rt_correction_plot = TRUE,
min_fraction = 0.5,
fill_peaks = FALSE,
group_for_figure = "QC"
)
```
Some important arguments:
* `ppm`: Peak detection ppm. See the `xcms` package.
* `peakwidth`: Peak width. It is dependent on your column and LC system. See the `xcms` package.
* `snthresh`: Signal to noise threshold. See the `xcms` package.
* `noise`: Noise cutoff. See the `xcms` package.
* `threads`: The core number for performing.
* `output_tic`, `output_bpc`, and `group_for_figure`: Do you want to output the TIC or BPC of samples? Some times there are a lot of samples, so you can set the `group_for_figure` as the group name, for example, you can set it as `QC`.
* `min_fraction`: If one peak appears more than `min.fraction` sample in at least one group samples it will be kept.
* `fill_peaks`: Do you want to fill the missing values (NA)?
Other parameters you can find here: `process_data()`.
---
# **Output results**
---
After all done, all the results are placed in a new folder named as `Result`.

## `object`
`object` is a `mass_dataset` class object which can be used for next analysis. See more about [`mass_dataset` class here](https://tidymass.github.io/massdataset/).
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
load("massprocesser_demo_data/POS/Result/object")
library(massdataset)
object
```
## `Peak_table.csv`
The peak table for next analysis.
```{r,eval=TRUE, echo=FALSE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
data = readr::read_csv("massprocesser_demo_data/POS/Result/Peak_table.csv")
library(kableExtra)
library(magrittr)
kbl(data[1:500,]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "600px")
```
> Only top 500 features show.
## `Peak_table_for_cleaning.csv`
Some usefulness columns are deleted from the `Peak_table.csv`, this can be directory used for next data cleaning.
```{r,eval=TRUE, echo=FALSE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
data = readr::read_csv("massprocesser_demo_data/POS/Result/Peak_table_for_cleaning.csv")
library(kableExtra)
library(magrittr)
kbl(data[1:500,]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "600px")
```
> Only top 500 features show.
## `BPC.pdf`
Base peak chromatogram.

Default it only shows the samples which are in the group you set in `group_for_figure`. If you want to show other samples, you can try to do use the below script.
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set threads
if(tinytools::get_os() == "windows") {
bpparam <-
BiocParallel::SnowParam(workers = 4,
progressbar = TRUE)
} else{
bpparam <- BiocParallel::MulticoreParam(workers = 4,
progressbar = TRUE)
}
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
###extract bpc plot object
bpc.plot <- xcms::chromatogram(object = xdata2,
aggregationFun = "max",
BPPARAM = bpparam)
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
####plot_chromatogram to show the plot
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot <- plot_chromatogram(object = bpc.plot,
title = "BPC",
group_for_figure = c("Case", "QC"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
plot <- plot_chromatogram(object = bpc.plot,
title = "BPC",
group_for_figure = c("all"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
##if you want to show specific samples, set the `sample_for_figure` parameter
plot <- plot_chromatogram(object = bpc.plot,
title = "BPC",
sample_for_figure = c("sample_11", "sample_78"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
##set `interactive` as TRUE to get interactive plot
plot <- plot_chromatogram(object = bpc.plot,
title = "BPC",
sample_for_figure = c("sample_11", "sample_78"),
interactive = TRUE
)
plot
```
## `TIC.pdf`
Total ion peak chromatogram

Default it only shows the samples which are in the group you set in `group_for_figure`. If you want to show other samples, you can try to do use the below script.
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set threads
if(tinytools::get_os() == "windows") {
bpparam <-
BiocParallel::SnowParam(workers = 4,
progressbar = TRUE)
} else{
bpparam <- BiocParallel::MulticoreParam(workers = 4,
progressbar = TRUE)
}
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
###extract tic plot object
tic.plot <- xcms::chromatogram(object = xdata2,
aggregationFun = "sum",
BPPARAM = bpparam)
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
####plot_chromatogram to show the plot
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot <- plot_chromatogram(object = tic.plot,
title = "TIC",
group_for_figure = c("Case", "QC"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
plot <- plot_chromatogram(object = tic.plot,
title = "TIC",
group_for_figure = c("all"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
##if you want to show specific samples, set the `sample_for_figure` parameter
plot <- plot_chromatogram(object = tic.plot,
title = "TIC",
sample_for_figure = c("sample_11", "sample_78"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
##set `interactive` as TRUE to get interactive plot
plot <- plot_chromatogram(object = tic.plot,
title = "TIC",
sample_for_figure = c("sample_11", "sample_78"),
interactive = TRUE
)
plot
```
## `RT correction plot.pdf`
RT correction.

Default it only shows the samples which are in the group you set in `group_for_figure`. If you want to show other samples, you can try to do use the below script.
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot =
plot_adjusted_rt(object = xdata2,
group_for_figure = c("Case", "QC"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
plot =
plot_adjusted_rt(object = xdata2,
group_for_figure = "all")
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
plot =
plot_adjusted_rt(object = xdata2,
sample_for_figure = c("sample_11", "sample_78"))
plot
```
```{r,eval=TRUE, echo=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
plot =
plot_adjusted_rt(object = xdata2,
sample_for_figure = "all",
interactive = TRUE)
plot
```
## `intermediate_data`
This is a folder which contains some intermediate data. If you want to re-run the data processing, please delete this folder first.

---
# **Session information**
---
```{r,eval=TRUE,warning=FALSE, R.options="", message=FALSE, cache=TRUE}
sessionInfo()
```