-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript ipo e xcms.R
166 lines (115 loc) · 4.33 KB
/
script ipo e xcms.R
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
#IPO e XCMS script - Elisa R. ([email protected])
##-------------------- Package References ----------------------##
# Websites:
# https://bioconductor.org/packages/release/bioc/html/xcms.html
# https://www.bioconductor.org/packages/release/bioc/html/IPO.html
# Citation
citation("xcms")
citation("IPO")
##-------------------- installation ----------------------##
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install("IPO") # install IPO
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("xcms") # install xcms
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("CAMERA") # install CAMERA.
##-------------------- files ----------------------##
datafiles <- list.files("D:/...", recursive = TRUE, full.names = TRUE)
datafiles # lists files names. Check if the correct files were found
# OBS: files need to be .mzxML format - Check MSConvert from Proteowizard.
##-------------------- loading packages ----------------------##
library(xcms)
library(Rmpi)
library(CAMERA)
library(IPO)
library(beepr)
##-------------------- IPO ----------------------##
# peak picking parameters optimization
peakpickingParameters <- getDefaultXcmsSetStartingParams('matchedFilter') #only matchedFilter (lowres)
peakpickingParameters$step <- c(0.1, 0.2)
peakpickingParameters$fwhm <- c(1, 2)
peakpickingParameters$steps <- 2
time.xcmsSet <- system.time({
resultPeakpicking <-
optimizeXcmsSet(files = datafiles[x:x], # check datafiles object. Input only the files to be tested
params = peakpickingParameters,
nSlaves = 1,# only change if your computer can handle it.
subdir = 'C:/...', #can be null if no plot is to be saved
plot = TRUE)
})
beep()
resultPeakpicking$best_settings$result
optimizedXcmsSetObject <- resultPeakpicking$best_settings$xset
# retention time correction optimization
# OBS: both chunks take a long time, depending on the amount of files.
# Save the R image or object (save.image() + load () | saveRDS() + readRDS()) to keep the objects stored
retcorGroupParameters <- getDefaultRetGroupStartingParams()
retcorGroupParameters$profStep <- 1
retcorGroupParameters$gapExtend <- 2.7
retcorGroupParameters$mzwid <-
time.RetGroup <- system.time({
resultRetcorGroup <-
optimizeRetGroup(xset = optimizedXcmsSetObject,
params = retcorGroupParameters,
nSlaves = 1, #only increase if the PC can handle it
subdir = 'C:/...', #can be set no NULL
plot = TRUE)
})
beep()
writeRScript(resultPeakpicking$best_settings$parameters,
resultRetcorGroup$best_settings)
time.xcmsSet
time.RetGroup
sessionInfo()
##-------------------- XCMS ----------------------##
# Separate the QC and other files on subdirectories - based on groups.
setwd ("C:/...")
# the script generated by IPO is similar to the one below. Substitute this chunk
# with the one generated by IPO and rename the objects so they don't overwrite each other.
xset <- xcmsSet(
method = "matchedFilter",
fwhm = x,
snthresh = x,
step = x,
steps = x,
sigma = x,
max = x,
mzdiff = x,
index = x,)
xset2 <- retcor(
xset,
method = "obiwarp",
plottype = "none",
distFunc = "cor_opt",
profStep = x, #default =1 possible bug, if so, change it to .99
center = x,
response = x,
gapInit = x,
gapExtend = x,
factorDiag = x,
factorGap = x,
localAlignment = x,)
xset3 <- group(
xset2,
method = "density",
bw = 10,
mzwid = 0.1,
minfrac = 1,
minsamp = 1,
max = 100)
xset4 <- fillPeaks(xset3)
# The IPO script ends here
# Substitute the object names inside the ( ) accordingly.
an <- xsAnnotate(xset4)
#Creation of an xsAnnotate object
anF <- groupFWHM(an, perfwhm = 0.6)
#Perfwhm = parameter defines the window width, which is used for matching
anI <- findIsotopes(anF, mzabs=0.01)
#Mzabs = the allowed m/z error
anIC <- groupCorr(anI, cor_eic_th=0.75)
anFA <- findAdducts(anIC, polarity="positive") #change polarity accordingly
write.csv(getPeaklist(anIC), file="Name.csv") # generates a table of features
beep()