-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmultiple_databases.Rmd
executable file
·295 lines (218 loc) · 7.86 KB
/
multiple_databases.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
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
---
title: "Identify peak tables with multiple databases"
author:
- name: Xiaotao Shen PhD (https://www.shen-lab.org/)
date: "Created on 2020-03-28 and updated on `r Sys.Date()`"
output:
html_document:
df_print: paged
toc: no
pdf_document:
toc: no
vignette: >
%\VignetteIndexEntry{multiple_databases}
%\VignettePackage{metid}
% \VignetteEngine{knitr::rmarkdown}
% \usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
---
```{r, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```
***
Some time we have multiple databases, so we can use `identify_metabolite_all()` functions to identify metabolites using multiple database.
# **MS1 data preparation**
The peak table must contain "name" (peak name), "mz" (mass to charge ratio) and "rt" (retention time, unit is second). It can be from any data processing software (XCMS, MS-DIAL and so on).

# MS2 data preparation
The raw MS2 data from DDA or DIA should be transfered to msp, mgf or mzXML format files using [ProteoWizard software](http://proteowizard.sourceforge.net/).
# **Database**
The database must be generated using `construct_database()` function. Here we use the databases in `metid` packages.
* `snyder_database_rplc0.0.3`: A in-house database, it contains m/z, RT and MS2 spectra information.
* `orbitrap_database0.0.3`: A public database from `MassBank`. It contains m/z and MS2 spectra information.
* `hmdb_ms1_database0.0.3`: A public database from `HMDB`, only contains m/z information.
# Data organization
Place the MS1 peak table, MS2 data and databases which you want to use in one folder like below figure shows:

# **Run `identify_metabolite_all()` function**
We use the demo data in `metid` package.
# **Load demo data**
First we load the MS1 peak, MS2 data and databases from `metid` package and then put them in a `example` folder.
```{r,eval = FALSE,warning=FALSE, message=FALSE,R.options="",cache=TRUE}
library(metid)
library(tidyverse)
```
```{r eval = FALSE, message=FALSE, warning=FALSE, message=FALSE, cache=TRUE, R.options=""}
##creat a folder nameed as example
path <- file.path(".", "example")
dir.create(path = path, showWarnings = FALSE)
##get MS1 peak table from metid
ms1_peak <- system.file("ms1_peak", package = "metid")
file.copy(
from = file.path(ms1_peak, "ms1.peak.table.csv"),
to = path,
overwrite = TRUE,
recursive = TRUE
)
##get MS2 data from metid
ms2_data <- system.file("ms2_data", package = "metid")
file.copy(
from = file.path(ms2_data, "QC1_MSMS_NCE25.mgf"),
to = path,
overwrite = TRUE,
recursive = TRUE
)
##get databases from metid
data("snyder_database_rplc0.0.3")
data("orbitrap_database0.0.3")
save(snyder_database_rplc0.0.3, file = file.path(path, "snyder_database_rplc0.0.3"))
save(orbitrap_database0.0.3, file = file.path(path, "orbitrap_database0.0.3"))
```
Now in your `./example`, there are files files, namely `ms1.peak.table.csv`, `QC1_MSMS_NCE25.mgf` and three databases.
## Set parameter list
We need to use `identify_metabolites_params()` functions to set parameter list for each database.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
param1 <-
identify_metabolites_params(
ms1.match.ppm = 15,
rt.match.tol = 15,
polarity = "positive",
ce = "all",
column = "rp",
total.score.tol = 0.5,
candidate.num = 3,
threads = 3,
database = "snyder_database_rplc0.0.3"
)
param2 <- identify_metabolites_params(
ms1.match.ppm = 15,
rt.match.tol = 15,
polarity = "positive",
ce = "all",
column = "rp",
total.score.tol = 0.5,
candidate.num = 3,
threads = 3,
database = "orbitrap_database0.0.3"
)
param3 <- identify_metabolites_params(
ms1.match.ppm = 15,
rt.match.tol = 15,
polarity = "positive",
ce = "all",
column = "rp",
total.score.tol = 0.5,
candidate.num = 3,
threads = 3,
database = "hmdb_ms1_database0.0.3"
)
```
> Note: You can set different parametes for each database.
## Metabolite identification
All the parameters for three databases should be provided to `parameter.list`.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
result <- identify_metabolite_all(
ms1.data = "ms1.peak.table.csv",
ms2.data = "QC1_MSMS_NCE25.mgf",
parameter.list = c(param1, param2, param3),
path = path
)
```
> Note: `result` is a list, and each element is a `metIdentifyClass` object. So you can use the functions for `metIdentifylass` object to process it.
## Integrate annotation results from different databases
After we get the annotation result list, we then can integrate the annotation results from different databases.
For `snyder_database_rplc0.0.3`, the annotaiton results are `Level 1` according to MSI.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
result[[1]]
```
Then get the annotation table.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table1 <-
get_identification_table(result[[1]], type = "new", candidate.num = 1)
annotation_table1 %>%
head()
```
For `orbitrap_database0.0.3`, the annotaiton results are `Level 2` according to MSI.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
result[[2]]
```
Then get the annotation table.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table2 <-
get_identification_table(result[[2]], type = "new", candidate.num = 1)
annotation_table2 %>%
head()
```
For `hmdb_ms1_database0.0.3`, the annotaiton results are `Level 3` according to MSI.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
result[[3]]
```
Then get the annotation table.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table3 <-
get_identification_table(result[[3]], type = "new", candidate.num = 1)
annotation_table3 %>%
head()
```
Then we should combine them together:
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table1 <-
annotation_table1 %>%
dplyr::filter(!is.na(Compound.name))
dim(annotation_table1)
annotation_table1 <-
data.frame(annotation_table1,
Level = 1,
stringsAsFactors = FALSE)
```
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table2 <-
annotation_table2 %>%
dplyr::filter(!is.na(Compound.name))
dim(annotation_table2)
annotation_table2 <-
data.frame(annotation_table2,
Level = 2,
stringsAsFactors = FALSE)
```
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table3 <-
annotation_table3 %>%
dplyr::filter(!is.na(Compound.name))
dim(annotation_table3)
annotation_table3 <-
data.frame(annotation_table3,
Level = 3,
stringsAsFactors = FALSE)
```
If one peak have annotation from three different database, we only contains the annotations with higher confidence.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table2 <-
annotation_table2 %>%
dplyr::filter(!(name %in% annotation_table1$name))
annotation_table <-
rbind(annotation_table1,
annotation_table2)
```
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
annotation_table3 <-
annotation_table3 %>%
dplyr::filter(!(name %in% annotation_table$name))
annotation_table <-
rbind(annotation_table,
annotation_table3)
```
The `annotation_table` is the final annotation table.
Then we can output it as `csv` file.
```{r,eval = FALSE,warning=FALSE, message=TRUE,R.options="",cache=TRUE}
readr::write_csv(annotation_table,file = file.path(path, "annotation_table.csv"))
```

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