Mercurial > repos > melpetera > testtest
comparison Testtest/GCMS-test_settings.R @ 0:40de28c7d3fb draft
Uploaded
author | melpetera |
---|---|
date | Thu, 23 Nov 2017 08:50:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:40de28c7d3fb |
---|---|
1 # author: Pauline Ribeyre | |
2 | |
3 | |
4 ##################### | |
5 # required packages # | |
6 ##################### | |
7 | |
8 library("metaMS") # provides "metaMSsettings" class | |
9 | |
10 | |
11 #################### | |
12 # default settings # | |
13 #################### | |
14 | |
15 # PeakPicking | |
16 PeakPicking.method = "matchedFilter" | |
17 PeakPicking.step = 0.05 | |
18 PeakPicking.steps = 2 | |
19 PeakPicking.mzdiff = 0.5 | |
20 PeakPicking.fwhm = 5 | |
21 PeakPicking.snthresh = 2 | |
22 PeakPicking.max = 500 | |
23 | |
24 # Alignment | |
25 # ? | |
26 | |
27 # CAMERA | |
28 CAMERA.perfwhm = 1 | |
29 | |
30 # DBconstruction | |
31 DBconstruction.minintens = 0.0 | |
32 DBconstruction.rttol = 0.1 | |
33 DBconstruction.intensityMeasure = "maxo" | |
34 DBconstruction.DBthreshold = .80 | |
35 DBconstruction.minfeat = 5 | |
36 | |
37 # match2DB | |
38 match2DB.rtdiff = 0.5 | |
39 match2DB.minfeat = 5 | |
40 # match2DB.rtval = ? | |
41 # match2DB.mzdiff = ? | |
42 # match2DB.ppm = ? | |
43 match2DB.simthresh = 0.8 | |
44 match2DB.timeComparison = "rt" | |
45 match2DB.RIdiff = 5 | |
46 | |
47 # betweenSamples | |
48 betweenSamples.min.class.fraction = 0.8 # pools | |
49 # betweenSamples.min.class.fraction = 0.5 # samples | |
50 betweenSamples.min.class.size = 5 | |
51 betweenSamples.timeComparison = "rt" | |
52 betweenSamples.rtdiff = 0.5 | |
53 betweenSamples.RIdiff = 2 # default setting | |
54 # betweenSamples.RIdiff = 0.05 # w4m setting | |
55 betweenSamples.simthresh = 0.8 | |
56 | |
57 # matchIrrelevants | |
58 # matchIrrelevants.irrelevantClasses = c("Bleeding", "Plasticizers") | |
59 # matchIrrelevants.RIdiff = ? | |
60 # matchIrrelevants.rtdiff = ? | |
61 # matchIrrelevants.simthresh = ? | |
62 # matchIrrelevants.timeComparison = "RI" | |
63 | |
64 # TODO RI option | |
65 | |
66 | |
67 ################### | |
68 # settings object # | |
69 ################### | |
70 | |
71 # settings <- metaMSsettings("protocolName" = "settings", "chrom" = "GC") | |
72 | |
73 settings <- metaMSsettings("protocolName" = "settings", | |
74 "chrom" = "GC", | |
75 | |
76 PeakPicking = list( | |
77 method = PeakPicking.method, | |
78 step = PeakPicking.step, | |
79 steps = PeakPicking.steps, | |
80 mzdiff = PeakPicking.mzdiff, | |
81 fwhm = PeakPicking.fwhm, | |
82 snthresh = PeakPicking.snthresh, | |
83 max = PeakPicking.max), | |
84 | |
85 CAMERA = list(perfwhm = CAMERA.perfwhm)) | |
86 | |
87 metaSetting(settings, "DBconstruction") <- list( | |
88 minintens = DBconstruction.minintens, | |
89 rttol = DBconstruction.rttol, | |
90 intensityMeasure = DBconstruction.intensityMeasure, | |
91 DBthreshold = DBconstruction.DBthreshold, | |
92 minfeat = DBconstruction.minfeat) | |
93 | |
94 metaSetting(settings, "match2DB") <- list( | |
95 simthresh = match2DB.simthresh, | |
96 timeComparison = match2DB.timeComparison, | |
97 rtdiff = match2DB.rtdiff, | |
98 RIdiff = match2DB.RIdiff, | |
99 minfeat = match2DB.minfeat) | |
100 | |
101 metaSetting(settings, "betweenSamples") <- list( | |
102 min.class.fraction = betweenSamples.min.class.fraction, | |
103 min.class.size = betweenSamples.min.class.size, | |
104 timeComparison = betweenSamples.timeComparison, | |
105 rtdiff = betweenSamples.rtdiff, | |
106 RIdiff = betweenSamples.RIdiff, | |
107 simthresh = betweenSamples.simthresh) | |
108 | |
109 # metaSetting(GALAXY.GC, "matchIrrelevants") <- list( | |
110 # irrelevantClasses = matchIrrelevants.irrelevantClasses, | |
111 # RIdiff = matchIrrelevants.RIdiff, | |
112 # rtdiff = matchIrrelevants.rtdiff, | |
113 # simthresh = matchIrrelevants.simthresh, | |
114 # timeComparison = matchIrrelevants.timeComparison) | |
115 | |
116 | |
117 # best settings pool | |
118 settings@betweenSamples.min.class.size = 5 | |
119 settings@PeakPicking$fwhm = 6 | |
120 settings@PeakPicking$mzdiff = -0.5 | |
121 settings@betweenSamples.min.class.fraction = 0.8 | |
122 settings@betweenSamples.simthresh = 0.7 | |
123 settings@betweenSamples.rtdiff = 0.05 | |
124 | |
125 | |
126 # best settings samples | |
127 settings@betweenSamples.min.class.size = 5 | |
128 settings@PeakPicking$fwhm = 6 | |
129 settings@PeakPicking$mzdiff = 0.5 | |
130 settings@betweenSamples.min.class.fraction = 0.5 | |
131 settings@betweenSamples.simthresh = 0.7 | |
132 settings@betweenSamples.rtdiff = 0.05 | |
133 | |
134 | |
135 ################# | |
136 # vary settings # | |
137 ################# | |
138 | |
139 pop <- function(list) { | |
140 # Removes the last item from a list. | |
141 # | |
142 # Args: | |
143 # list: the list to pop. | |
144 # | |
145 # Returns: | |
146 # The last item of the list before it was removed. | |
147 | |
148 val <- list[length(list)] | |
149 assign(as.character(substitute(list)), list[-length(list)], parent.frame()) | |
150 return (val) | |
151 | |
152 } | |
153 | |
154 | |
155 vary_list_to_settings <- function(settings, vary_list, title = "", titles_to_test = c(), settings_to_test = c()) { | |
156 # Reads the list of parameters to vary and their ranges and builds a list of file titles and settings from it. | |
157 # | |
158 # Args: | |
159 # settings: default settings for runGC. | |
160 # vary_list: list of parameters to vary and the values each parameter must take. | |
161 # title: title of the current file (concatenation of the values taken by the varied parameters). | |
162 # titles_to_test: list of titles (one for each settings set) (concatenation of the values taken by the varied parameters). | |
163 # settings_to_test: list of settings sets for runGC. | |
164 # | |
165 # Returns: | |
166 # A list containing: | |
167 # 1: the list of file titles ; | |
168 # 2: the list of runGC() settings. | |
169 | |
170 if (length(vary_list) == 0) { # if there are no parameters to vary | |
171 | |
172 titles_to_test <- c(titles_to_test, "default_settings") | |
173 settings_to_test <- c(settings_to_test, settings) | |
174 | |
175 } | |
176 | |
177 else { | |
178 | |
179 param <- pop(vary_list)[[1]] | |
180 | |
181 title <- paste0(title, param[1]) | |
182 setting <- param[2] | |
183 range <- as.numeric(param[3:length(param)]) | |
184 | |
185 # for each possible value of the parameter | |
186 for (p in range) { | |
187 | |
188 # change the settings | |
189 isSlot <- regexpr("\\$", setting)[1] | |
190 | |
191 if (isSlot == -1) { # the parameter is a slot in class metaMSsettings | |
192 slot(settings, setting) <- p | |
193 } | |
194 else { # the parameter is not a slot in class metaMSsettings | |
195 slot(settings, substr(setting, 1, isSlot - 1))[substr(setting, isSlot + 1, nchar(setting))] <- p | |
196 } | |
197 | |
198 new_title <- paste0(title, "=", p, "_") | |
199 | |
200 # save the settings in a list | |
201 if (length(vary_list) == 0) { | |
202 titles_to_test <- c(titles_to_test, new_title) | |
203 settings_to_test <- c(settings_to_test, settings) | |
204 } | |
205 else { | |
206 res <- vary_list_to_settings(settings, vary_list, new_title, titles_to_test, settings_to_test) | |
207 titles_to_test <- res[[1]] | |
208 settings_to_test <- res[[2]] | |
209 } | |
210 | |
211 } # end for | |
212 | |
213 } # end else | |
214 | |
215 return (list(titles_to_test, settings_to_test)) | |
216 | |
217 } | |
218 | |
219 | |
220 ############ | |
221 # main # | |
222 ############ | |
223 | |
224 # settings to vary and ranges of values | |
225 res <- vary_list_to_settings(settings, vary_list) | |
226 titles_to_test <- res[[1]] | |
227 settings_to_test <- res[[2]] |