annotate galaxy/tools/LC-MSMS/XSeekerPreparator.R @ 20:ce94e7a141bb draft default tip

" master branch Updating"
author lain
date Tue, 06 Dec 2022 10:18:10 +0000
parents 2937e72e5891
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
2
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
3 assign("TOOL_NAME", "XSeekerPreparator", envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
4 lockBinding("TOOL_NAME", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
5 assign("VERSION", "1.3.0", envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
6 lockBinding("VERSION", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
7 assign("DEBUG_FAST", FALSE, envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
8 lockBinding("DEBUG_FAST", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
9 assign("DEBUG_FAST_IGNORE_SLOW_OP", DEBUG_FAST, envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
10 lockBinding("DEBUG_FAST_IGNORE_SLOW_OP", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
11 assign("PROCESS_SMOL_BATCH", DEBUG_FAST, envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
12 lockBinding("PROCESS_SMOL_BATCH", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
13 assign("FAST_FEATURE_RATIO", 10, envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
14 lockBinding("FAST_FEATURE_RATIO", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
15 assign("OUTPUT_SPECIFIC_TOOL", "XSeeker_Galaxy", envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
16 lockBinding("OUTPUT_SPECIFIC_TOOL", globalenv())
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
17
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
18 assign(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
19 "ENRICHED_RDATA_VERSION",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
20 paste(VERSION, OUTPUT_SPECIFIC_TOOL, sep = "-"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
21 envir = globalenv()
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
22 )
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
23 lockBinding("ENRICHED_RDATA_VERSION", globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
24 assign("ENRICHED_RDATA_DOC", sprintf("
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
25 Welcome to the enriched <Version %s> of the output of CAMERA/xcms.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
26 This doc was generated by the tool: %s - Version %s
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
27 To show the different variables contained in this rdata, type:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
28 - `load('this_rdata.rdata', rdata_env <- new.env())`
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
29 - `names(rdata_env)`
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
30
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
31 Sections
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
32 ######
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
33
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
34
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
35 This tools helpers
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
36 ------
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
37 The version number is somewhat special because the evolution of the
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
38 rdata's format is non-linear.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
39 There may be different branches, each evolving separatly.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
40 To reflect these branches's diversions, there may be a prepended
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
41 branch name following this format:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
42 major.minor.patch-branch_name
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
43 Like this, we can process rdata with the same tool, and output
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
44 rdata formated differently, for each tool.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
45
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
46
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
47 - enriched_rdata:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
48 - Description: flag created by that tool to tell it was enriched.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
49 - Retrieval method: enriched_rdata <- TRUE
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
50
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
51 - enriched_rdata_version:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
52 - Description: A flag created by that tool to tell which version of
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
53 this tool has enriched the rdata.
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
54 - Retrieval method:
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
55 enriched_rdata_version <- sprintf(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
56 \"%s\",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
57 ENRICHED_RDATA_VERSION
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
58 )
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
59
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
60 - enriched_rdata_doc:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
61 - Description: Contains the documentation string.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
62
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
63 Data from original mzxml file
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
64 ------
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
65 - tic:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
66 - Description: Those are the tic values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
67 file, extracted using xcms 2.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
68 - Retrieval method: xcms::xcmsRaw('original_file.mzxml')@tic
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
69 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
70
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
71 - mz:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
72 - Description: Those are the m/z values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
73 file, extracted using xcms 2.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
74 - Retrieval method: xcms::xcmsRaw('original_file.mzxml')@env$mz
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
75 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
76
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
77 - scanindex:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
78 - Description: Those are the scanindex values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
79 file, extracted using xcms 2.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
80 - Retrieval method: xcms::xcmsRaw('original_file.mzxml')@scanindex
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
81 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
82
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
83 - scantime:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
84 - Description: Those are the scantime values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
85 file, extracted using xcms 2.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
86 - Retrieval method: xcms::xcmsRaw('original_file.mzxml')@scantime
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
87 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
88
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
89 - intensity:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
90 - Description: Those are the intensity values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
91 file, extracted using xcms 2.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
92 - Retrieval method: xcms::xcmsRaw('original_file.mzxml')@env$intensity
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
93 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
94
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
95 - polarity:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
96 - Description: Those are the polarity values from the original mzxml
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
97 file, extracted using xcms 2.
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
98 - Retrieval method:
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
99 as.character(xcms::xcmsRaw(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
100 'original_file.mzxml'
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
101 )@polarity[[1]])
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
102 - xcms version: 2.0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
103
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
104 Data taken from incoming rdata
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
105 ------
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
106 - variableMetadata:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
107 - Description: Unmodified copy of variableMetadata from incoming rdata.
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
108 - Retrieval method: rdata_file$variableMetadata
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
109
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
110 - process_params:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
111 - Description: Those are the processing parameters values from the
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
112 curent rdata. They have been simplified to allow easy access like:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
113 for (params in process_params) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
114 if (params[[\"xfunction\"]] == \"annotatediff\") {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
115 process_peak_picking_params(params)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
116 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
117 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
118 - Retrieval method:
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
119 ## just he same list, but simplified
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
120 process_params <- list()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
121 for (list_name in names(rdata_file$listOFlistArguments)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
122 param_list <- list()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
123 for (param_name in names(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
124 rdata_file$listOFlistArguments[[list_name]]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
125 )) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
126 param_list[[param_name]] <- rdata_file$listOFlistArguments[[
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
127 list_name
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
128 ]][[param_name]]
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
129 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
130 process_params[[length(process_params)+1]] <- param_list
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
131 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
132 ", ENRICHED_RDATA_VERSION, TOOL_NAME, VERSION, ENRICHED_RDATA_VERSION),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
133 envir = globalenv())
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
134 lockBinding("ENRICHED_RDATA_DOC", globalenv())
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
135
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
136
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
137
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
138 get_models <- function(path) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
139 if (is.null(path)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
140 stop("No models to define the database schema")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
141 } else {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
142 message(sprintf("Loading models from %s", path))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
143 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
144 ## galaxy mangles the "@" to a "__at__"
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
145 if (substr(path, 1, 9) == "git__at__") {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
146 path <- sub("^git__at__", "git@", path, perl = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
147 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
148 if (
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
149 substr(path, 1, 4) == "git@"
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
150 || substr(path, length(path) - 4, 4) == ".git"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
151 ) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
152 return(get_models_from_git(path))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
153 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
154 if (substr(path, 1, 4) == "http") {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
155 return(get_models_from_url(path))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
156 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
157 return(source(path)$value)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
158 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
159
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
160 get_models_from_git <- function(url, target_file = "models.R", rm = TRUE) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
161 tmp <- tempdir()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
162 message(sprintf("Cloning %s", url))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
163 system2("git", c("clone", url, tmp))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
164 result <- search_tree(file.path(tmp, dir), target_file)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
165 if (!is.null(result)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
166 models <- source(result)$value
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
167 if (rm) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
168 unlink(tmp, recursive = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
169 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
170 return(models)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
171 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
172 if (rm) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
173 unlink(tmp, recursive = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
174 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
175 stop(sprintf(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
176 "Could not find any file named \"%s\" in this repo",
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
177 target_file
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
178 ))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
179 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
180
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
181 get_models_from_url <- function(url, target_file = "models.R", rm = TRUE) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
182 tmp <- tempdir()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
183 message(sprintf("Downloading %s", url))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
184 result <- file.path(tmp, target_file)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
185 if (download.file(url, destfile = result) == 0) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
186 models <- source(result)$value
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
187 if (rm) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
188 unlink(tmp, recursive = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
189 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
190 return(models)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
191 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
192 if (rm) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
193 unlink(tmp, recursive = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
194 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
195 stop("Could not download any file at this adress.")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
196 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
197
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
198 search_tree <- function(path, target) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
199 target <- tolower(target)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
200 for (file in list.files(path)) {
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
201 if (fs::is.dir(file)) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
202 result <- search_tree(file.path(path, file), target)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
203 if (!is.null(result)) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
204 return(result)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
205 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
206 } else if (tolower(file) == target) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
207 return(file.path(path, file))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
208 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
209 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
210 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
211 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
212
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
213 create_database <- function(orm) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
214 orm$recreate_database(no_exists = FALSE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
215 set_database_version(orm, "created")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
216 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
217
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
218 insert_adducts <- function(orm) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
219 message("Creating adducts...")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
220 adducts <- list(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
221 list("[M-H2O-H]-", 1, -1, -48.992020312000001069, 1, 0, 0.5, "H0", "H1O3"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
222 list("[M-H-Cl+O]-", 1, -1, -19.981214542000000022, 2, 0, 0.5, "O1", "H1Cl1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
223 list("[M-Cl+O]-", 1, -1, -18.973389510000000512, 3, 0, 0.5, "O1", "Cl1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
224 list("[M-3H]3-", 1, -3, -3.0218293560000000219, 4, 0, 1.0, "H0", "H3"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
225 list("[2M-3H]3-", 2, -3, -3.0218293560000000219, 4, 0, 0.5, "H0", "H3"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
226 list("[3M-3H]3-", 3, -3, -3.0218293560000000219, 4, 0, 0.5, "H0", "H3"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
227 list("[M-2H]2-", 1, -2, -2.0145529039999998666, 5, 0, 1.0, "H0", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
228 list("[2M-2H]2-", 2, -2, -2.0145529039999998666, 5, 0, 0.5, "H0", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
229 list("[3M-2H]2-", 3, -2, -2.0145529039999998666, 5, 0, 0.5, "H0", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
230 list("[M-H]-", 1, -1, -1.0072764519999999333, 6, 1, 1.0, "H0", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
231 list("[2M-H]-", 2, -1, -1.0072764519999999333, 6, 0, 0.5, "H0", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
232 list("[3M-H]-", 3, -1, -1.0072764519999999333, 6, 0, 0.5, "H0", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
233 list("[M]+", 1, 1, -0.00054858000000000000945, 7, 1, 1.0, "H0", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
234 list("[M]-", 1, -1, 0.00054858000000000000945, 8, 1, 1.0, "H0", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
235 list("[M+H]+", 1, 1, 1.0072764519999999333, 9, 1, 1.0, "H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
236 list("[2M+H]+", 2, 1, 1.0072764519999999333, 9, 0, 0.5, "H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
237 list("[3M+H]+", 3, 1, 1.0072764519999999333, 9, 0, 0.25, "H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
238 list("[M+2H]2+", 1, 2, 2.0145529039999998666, 10, 0, 0.75, "H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
239 list("[2M+2H]2+", 2, 2, 2.0145529039999998666, 10, 0, 0.5, "H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
240 list("[3M+2H]2+", 3, 2, 2.0145529039999998666, 10, 0, 0.25, "H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
241 list("[M+3H]3+", 1, 3, 3.0218293560000000219, 11, 0, 0.75, "H3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
242 list("[2M+3H]3+", 2, 3, 3.0218293560000000219, 11, 0, 0.5, "H3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
243 list("[3M+3H]3+", 3, 3, 3.0218293560000000219, 11, 0, 0.25, "H3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
244 list("[M-2H+NH4]-", 1, -1, 16.019272654000001665, 12, 0, 0.25, "N1H4", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
245 list("[2M-2H+NH4]-", 2, -1, 16.019272654000001665, 12, 0, 0.0, "N1H4", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
246 list("[3M-2H+NH4]-", 3, -1, 16.019272654000001665, 12, 0, 0.25, "N1H4", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
247 list("[M+NH4]+", 1, 1, 18.033825558000000199, 13, 1, 1.0, "N1H4", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
248 list("[2M+NH4]+", 2, 1, 18.033825558000000199, 13, 0, 0.5, "N1H4", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
249 list("[3M+NH4]+", 3, 1, 18.033825558000000199, 13, 0, 0.25, "N1H4", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
250 list("[M+H+NH4]2+", 1, 2, 19.041102009999999467, 14, 0, 0.5, "N1H5", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
251 list("[2M+H+NH4]2+", 2, 2, 19.041102009999999467, 14, 0, 0.5, "N1H5", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
252 list("[3M+H+NH4]2+", 3, 2, 19.041102009999999467, 14, 0, 0.25, "N1H5", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
253 list("[M+Na-2H]-", 1, -1, 20.974668176000001551, 15, 0, 0.75, "Na1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
254 list("[2M-2H+Na]-", 2, -1, 20.974668176000001551, 15, 0, 0.25, "Na1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
255 list("[3M-2H+Na]-", 3, -1, 20.974668176000001551, 15, 0, 0.25, "Na1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
256 list("[M+Na]+", 1, 1, 22.989221080000000086, 16, 1, 1.0, "Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
257 list("[2M+Na]+", 2, 1, 22.989221080000000086, 16, 0, 0.5, "Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
258 list("[3M+Na]+", 3, 1, 22.989221080000000086, 16, 0, 0.25, "Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
259 list("[M+H+Na]2+", 1, 2, 23.996497531999999353, 17, 0, 0.5, "Na1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
260 list("[2M+H+Na]2+", 2, 2, 23.996497531999999353, 17, 0, 0.5, "Na1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
261 list("[3M+H+Na]2+", 3, 2, 23.996497531999999353, 17, 0, 0.25, "Na1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
262 list("[M+2H+Na]3+", 1, 3, 25.003773983999998619, 18, 0, 0.25, "H2Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
263 list("[M+CH3OH+H]+", 1, 1, 33.033491200000000276, 19, 0, 0.25, "C1O1H5", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
264 list("[M-H+Cl]2-", 1, -2, 33.962124838000001148, 20, 0, 1.0, "Cl1", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
265 list("[2M-H+Cl]2-", 2, -2, 33.962124838000001148, 20, 0, 0.5, "Cl1", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
266 list("[3M-H+Cl]2-", 3, -2, 33.962124838000001148, 20, 0, 0.5, "Cl1", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
267 list("[M+Cl]-", 1, -1, 34.969401290000000416, 21, 1, 1.0, "Cl1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
268 list("[2M+Cl]-", 2, -1, 34.969401290000000416, 21, 0, 0.5, "Cl1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
269 list("[3M+Cl]-", 3, -1, 34.969401290000000416, 21, 0, 0.5, "Cl1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
270 list("[M+K-2H]-", 1, -1, 36.948605415999999479, 22, 0, 0.5, "K1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
271 list("[2M-2H+K]-", 2, -1, 36.948605415999999479, 22, 0, 0.0, "K1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
272 list("[3M-2H+K]-", 3, -1, 36.948605415999999479, 22, 0, 0.0, "K1", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
273 list("[M+K]+", 1, 1, 38.963158319999998013, 23, 1, 1.0, "K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
274 list("[2M+K]+", 2, 1, 38.963158319999998013, 23, 0, 0.5, "K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
275 list("[3M+K]+", 3, 1, 38.963158319999998013, 23, 0, 0.25, "K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
276 list("[M+H+K]2+", 1, 2, 39.970434771999997281, 24, 0, 0.5, "K1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
277 list("[2M+H+K]2+", 2, 2, 39.970434771999997281, 24, 0, 0.5, "K1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
278 list("[3M+H+K]2+", 3, 2, 39.970434771999997281, 24, 0, 0.25, "K1H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
279 list("[M+ACN+H]+", 1, 1, 42.033825557999996646, 25, 0, 0.25, "C2H4N1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
280 list("[2M+ACN+H]+", 2, 1, 42.033825557999996646, 25, 0, 0.25, "C2H4N1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
281 list("[M+2Na-H]+", 1, 1, 44.971165708000000902, 26, 0, 0.5, "Na2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
282 list("[2M+2Na-H]+", 2, 1, 44.971165708000000902, 26, 0, 0.25, "Na2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
283 list("[3M+2Na-H]+", 3, 1, 44.971165708000000902, 26, 0, 0.25, "Na2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
284 list("[2M+FA-H]-", 2, -1, 44.998202851999998586, 27, 0, 0.25, "C1O2H2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
285 list("[M+FA-H]-", 1, -1, 44.998202851999998586, 27, 0, 0.5, "C1O2H2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
286 list("[M+2Na]2+", 1, 2, 45.978442160000000172, 28, 0, 0.5, "Na2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
287 list("[2M+2Na]2+", 2, 2, 45.978442160000000172, 28, 0, 0.5, "Na2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
288 list("[3M+2Na]2+", 3, 2, 45.978442160000000172, 28, 0, 0.25, "Na2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
289 list("[M+H+2Na]3+", 1, 3, 46.985718611999999438, 29, 0, 0.25, "H1Na2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
290 list("[M+H+FA]+", 1, 1, 47.012755755999997122, 30, 0, 0.25, "C1O2H3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
291 list("[M+Hac-H]-", 1, -1, 59.013852915999997607, 31, 0, 0.25, "C2O2H4", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
292 list("[2M+Hac-H]-", 2, -1, 59.013852915999997607, 31, 0, 0.25, "C2O2H4", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
293 list("[M+IsoProp+H]+", 1, 1, 61.064791327999998317, 32, 0, 0.25, "C3H9O1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
294 list("[M+Na+K]2+", 1, 2, 61.9523793999999981, 33, 0, 0.5, "Na1K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
295 list("[2M+Na+K]2+", 2, 2, 61.9523793999999981, 33, 0, 0.5, "Na1K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
296 list("[3M+Na+K]2+", 3, 2, 61.9523793999999981, 33, 0, 0.25, "Na1K1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
297 list("[M+NO3]-", 1, -1, 61.988366450000000895, 34, 0, 0.5, "N1O3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
298 list("[M+ACN+Na]+", 1, 1, 64.015770185999997464, 35, 0, 0.25, "C2H3N1Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
299 list("[2M+ACN+Na]+", 2, 1, 64.015770185999997464, 35, 0, 0.25, "C2H3N1Na1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
300 list("[M+NH4+FA]+", 1, 1, 64.039304861999994502, 36, 0, 0.25, "N1C1O2H6", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
301 list("[M-2H+Na+FA]-", 1, -1, 66.980147479999999405, 37, 0, 0.5, "NaC1O2H2", "H2"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
302 list("[M+3Na]3+", 1, 3, 68.967663239999993153, 38, 0, 0.25, "Na3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
303 list("[M+Na+FA]+", 1, 1, 68.99470038399999794, 39, 0, 0.25, "Na1C1O2H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
304 list("[M+2Cl]2-", 1, -2, 69.938802580000000832, 40, 0, 1.0, "Cl2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
305 list("[2M+2Cl]2-", 2, -2, 69.938802580000000832, 40, 0, 0.5, "Cl2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
306 list("[3M+2Cl]2-", 3, -2, 69.938802580000000832, 40, 0, 0.5, "Cl2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
307 list("[M+2K-H]+", 1, 1, 76.919040187999996758, 41, 0, 0.5, "K2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
308 list("[2M+2K-H]+", 2, 1, 76.919040187999996758, 41, 0, 0.25, "K2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
309 list("[3M+2K-H]+", 3, 1, 76.919040187999996758, 41, 0, 0.25, "K2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
310 list("[M+2K]2+", 1, 2, 77.926316639999996028, 42, 0, 0.5, "K2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
311 list("[2M+2K]2+", 2, 2, 77.926316639999996028, 42, 0, 0.5, "K2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
312 list("[3M+2K]2+", 3, 2, 77.926316639999996028, 42, 0, 0.25, "K2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
313 list("[M+Br]-", 1, -1, 78.918886479999997619, 43, 1, 1.0, "Br1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
314 list("[M+Cl+FA]-", 1, -1, 80.974880593999998268, 44, 0, 0.5, "Cl1C1O2H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
315 list("[M+AcNa-H]-", 1, -1, 80.995797543999998426, 45, 0, 0.25, "C2H3Na1O2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
316 list("[M+2ACN+2H]2+", 1, 2, 84.067651115999993292, 46, 0, 0.25, "C4H8N2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
317 list("[M+K+FA]+", 1, 1, 84.968637623999995868, 47, 0, 0.25, "K1C1O2H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
318 list("[M+Cl+Na+FA-H]-", 1, -1, 102.95682522200000619, 48, 0, 0.5, "Cl1Na1C1O2H2", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
319 list("[2M+3H2O+2H]+", 2, 1, 104.03153939599999944, 49, 0, 0.25, "H8O6", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
320 list("[M+TFA-H]-", 1, -1, 112.98558742000000165, 50, 0, 0.5, "C2F3O2H1", "H1"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
321 list("[M+H+TFA]+", 1, 1, 115.00014032400000019, 51, 0, 0.25, "C2F3O2H2", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
322 list("[M+3ACN+2H]2+", 1, 2, 125.09420022199999778, 52, 0, 0.25, "C6H11N3", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
323 list("[M+NH4+TFA]+", 1, 1, 132.02668943000000468, 53, 0, 0.25, "N1C2F3O2H5", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
324 list("[M+Na+TFA]+", 1, 1, 136.98208495200000811, 54, 0, 0.25, "Na1C2F3O2H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
325 list("[M+Cl+TFA]-", 1, -1, 148.96226516199999423, 55, 0, 0.5, "Cl1C2F3O2H1", "H0"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
326 list("[M+K+TFA]+", 1, 1, 152.95602219200000604, 56, 0, 0.25, "K1C2F3O2H1","H0")
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
327 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
328 dummy_adduct <- orm$adduct()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
329 for (adduct in adducts) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
330 i <- 0
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
331 dummy_adduct$set_name(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
332 dummy_adduct$set_multi(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
333 dummy_adduct$set_charge(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
334 dummy_adduct$set_mass(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
335 dummy_adduct$set_oidscore(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
336 dummy_adduct$set_quasi(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
337 dummy_adduct$set_ips(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
338 dummy_adduct$set_formula_add(adduct[[i <- i + 1]])
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
339 dummy_adduct$set_formula_ded(adduct[[i <- i + 1]])
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
340 invisible(dummy_adduct$save())
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
341 dummy_adduct$clear(unset_id = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
342 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
343 message("Adducts created")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
344 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
345
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
346 insert_base_data <- function(orm, path, archetype = FALSE) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
347 if (archetype) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
348 ## not implemented yet
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
349 return()
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
350 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
351 base_data <- readLines(path)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
352 for (sql in strsplit(paste(base_data, collapse = " "), ";")[[1]]) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
353 orm$execute(sql)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
354 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
355 set_database_version(orm, "enriched")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
356 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
357
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
358 insert_compounds <- function(orm, compounds_path) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
359 compounds <- read.csv(file = compounds_path, sep = "\t")
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
360 if (is.null(compounds <- translate_compounds(compounds))) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
361 stop("Could not find asked compound's attributes in csv file.")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
362 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
363 dummy_compound <- orm$compound()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
364 compound_list <- list()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
365 for (i in seq_len(nrow(compounds))) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
366 dummy_compound$set_mz(compounds[i, "mz"])
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
367 dummy_compound$set_name(compounds[i, "name"])
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
368 dummy_compound$set_common_name(compounds[i, "common_name"])
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
369 dummy_compound$set_formula(compounds[i, "formula"])
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
370 compound_list[[length(compound_list) + 1]] <- as.list(
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
371 dummy_compound,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
372 c("mz", "name", "common_name", "formula")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
373 )
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
374 dummy_compound$clear(unset_id = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
375 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
376 invisible(dummy_compound$save(bulk = compound_list))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
377 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
378
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
379 translate_compounds <- function(compounds) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
380 recognized_headers <- list(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
381 c(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
382 "HMDB_ID", "MzBank", "X.M.H..", "X.M.H...1",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
383 "MetName", "ChemFormula", "INChIkey"
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
384 )
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
385 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
386 header_translators <- list(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
387 hmdb_header_translator
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
388 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
389 for (index in seq_along(recognized_headers)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
390 headers <- recognized_headers[[index]]
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
391 if (identical(colnames(compounds), headers)) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
392 return(header_translators[[index]](compounds))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
393 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
394 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
395 if (is.null(translator <- guess_translator(colnames(compounds)))) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
396 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
397 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
398 return(csv_header_translator(translator, compounds))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
399 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
400
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
401 guess_translator <- function(header) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
402 result <- list(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
403 mz = NULL,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
404 name = NULL,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
405 common_name = NULL,
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
406 formula = NULL
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
407 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
408 asked_cols <- names(result)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
409 for (asked_col in asked_cols) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
410 for (col in header) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
411 if ((twisted <- tolower(col)) == asked_col
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
412 || gsub("-", "_", twisted) == asked_col
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
413 || gsub(" ", "_", twisted) == asked_col
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
414 || tolower(gsub("(.)([A-Z])", "\\1_\\2", col)) == asked_col
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
415 ) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
416 result[[asked_col]] <- col
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
417 next
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
418 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
419 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
420 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
421 if (any(mapply(is.null, result))) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
422 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
423 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
424 return(result)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
425 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
426
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
427 hmdb_header_translator <- function(compounds) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
428 return(csv_header_translator(
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
429 list(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
430 HMDB_ID = "HMDB_ID",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
431 mz = "MzBank",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
432 name = "MetName",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
433 common_name = "MetName",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
434 formula = "ChemFormula",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
435 inchi_key = "INChIkey"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
436 ), compounds
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
437 ))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
438 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
439
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
440 csv_header_translator <- function(translation_table, csv) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
441 header_names <- names(translation_table)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
442 result <- data.frame(seq_len(nrow(csv)))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
443 for (i in seq_along(header_names)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
444 result[, header_names[[i]]] <- csv[, translation_table[[i]]]
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
445 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
446 result[, "mz"] <- as.numeric(result[, "mz"])
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
447 return(result)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
448 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
449
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
450 set_database_version <- function(orm, version) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
451 orm$set_tag(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
452 version,
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
453 tag_name = "database_version",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
454 tag_table_name = "XSeeker_tagging_table"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
455 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
456 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
457
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
458 process_rdata <- function(orm, rdata, options) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
459 mzml_tmp_dir <- gather_mzml_files(rdata)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
460 samples <- names(rdata$singlefile)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
461 if (!is.null(options$samples)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
462 samples <- samples[options$samples %in% samples]
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
463 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
464 show_percent <- (
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
465 is.null(options$`not-show-percent`)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
466 || options$`not-show-percent` == FALSE
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
467 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
468 error <- tryCatch({
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
469 process_sample_list(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
470 orm, rdata, samples,
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
471 show_percent = show_percent,
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
472 file_grouping_var = options$class,
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
473 options = options
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
474 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
475 NULL
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
476 }, error = function(e) {
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
477 return(e)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
478 })
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
479 if (!is.null(mzml_tmp_dir)) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
480 unlink(mzml_tmp_dir, recursive = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
481 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
482 if (!is.null(error)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
483 stop(error)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
484 }
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
485 return(!is.null(error))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
486 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
487
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
488 gather_mzml_files <- function(rdata) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
489 if (is.null(rdata$singlefile)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
490 message("Extracting mxml files")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
491 tmp <- tempdir()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
492 rdata$singlefile <- utils::unzip(rdata$zipfile, exdir = tmp)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
493 names(rdata$singlefile) <- tools::file_path_sans_ext(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
494 basename(rdata$singlefile)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
495 )
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
496 message("Extracted")
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
497 return(tmp)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
498 } else {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
499 message(sprintf(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
500 "Not a zip file, loading files directly from path: %s",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
501 paste(rdata$singlefile, collapse = " ; ")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
502 ))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
503 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
504 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
505 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
506
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
507 process_sample_list <- function(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
508 orm,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
509 rdata,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
510 sample_names,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
511 show_percent,
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
512 file_grouping_var = NULL,
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
513 options = list()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
514 ) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
515 if (is.null(file_grouping_var)) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
516 file_grouping_var <- find_grouping_var(rdata$variableMetadata)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
517 if (is.null(file_grouping_var)) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
518 stop("Malformed variableMetada.")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
519 }
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
520 }
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
521 tryCatch({
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
522 headers <- colnames(rdata$variableMetadata)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
523 file_grouping_var <- headers[[as.numeric(file_grouping_var)]]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
524 }, error = function(e) NULL)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
525 if (
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
526 is.null(file_grouping_var)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
527 || !(file_grouping_var %in% colnames(rdata$variableMetadata))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
528 ) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
529 stop(sprintf(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
530 "Could not find grouping variable %s in var meta file.",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
531 file_grouping_var
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
532 ))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
533 }
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
534 message("Processing samples.")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
535 message(sprintf("File grouping variable: %s", file_grouping_var))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
536
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
537 context <- new.env()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
538 context$samples <- list()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
539 context$peaks <- rdata$xa@xcmsSet@peaks
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
540 context$groupidx <- rdata$xa@xcmsSet@groupidx
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
541 xcms_set <- rdata$xa@xcmsSet
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
542 singlefile <- rdata$singlefile
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
543 process_arg_list <- rdata$listOFlistArguments
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
544 var_meta <- rdata$variableMetadata
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
545
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
546 process_params <- list()
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
547 if (is.null(process_arg_list)) {
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
548 for (history in xcms_set@.processHistory) {
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
549 if (
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
550 class(history@param) == "CentWaveParam"
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
551 && history@type == "Peak detection"
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
552 ) {
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
553 params <- history@param
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
554 process_params <- list(list(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
555 xfunction = "annotatediff",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
556 ppm = params@ppm,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
557 peakwidth = sprintf(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
558 "%s - %s",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
559 params@peakwidth[[1]],
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
560 params@peakwidth[[2]]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
561 ),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
562 snthresh = params@snthresh,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
563 prefilterStep = params@prefilter[[1]],
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
564 prefilterLevel = params@prefilter[[2]],
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
565 mzdiff = params@mzdiff,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
566 fitgauss = params@fitgauss,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
567 noise = params@noise,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
568 mzCenterFun = params@mzCenterFun,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
569 integrate = params@integrate,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
570 firstBaselineCheck = params@firstBaselineCheck,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
571 snthreshIsoROIs = !identical(params@roiScales, numeric(0))
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
572 ))
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
573 break
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
574 }
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
575 }
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
576 } else {
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
577 for (list_name in names(process_arg_list)) {
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
578 param_list <- list()
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
579 for (param_name in names(process_arg_list[[list_name]])) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
580 param_list[[param_name]] <- process_arg_list[[
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
581 list_name
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
582 ]][[param_name]]
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
583 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
584 process_params[[length(process_params) + 1]] <- param_list
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
585 }
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
586 }
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
587
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
588 message("Parameters from previous processes extracted.")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
589
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
590 smol_xcms_set <- orm$smol_xcms_set()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
591 mz_tab_info <- new.env()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
592 g <- xcms::groups(xcms_set)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
593 mz_tab_info$group_length <- nrow(g)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
594 mz_tab_info$dataset_path <- xcms::filepaths(xcms_set)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
595 mz_tab_info$sampnames <- xcms::sampnames(xcms_set)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
596 mz_tab_info$sampclass <- xcms::sampclass(xcms_set)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
597 mz_tab_info$rtmed <- g[, "rtmed"]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
598 mz_tab_info$mzmed <- g[, "mzmed"]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
599 mz_tab_info$smallmolecule_abundance_assay <- xcms::groupval(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
600 xcms_set,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
601 value = "into"
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
602 )
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
603 blogified <- blob::blob(fst::compress_fst(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
604 serialize(mz_tab_info, NULL),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
605 compression = 100
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
606 ))
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
607 rm(mz_tab_info)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
608
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
609 invisible(smol_xcms_set$set_raw(blogified)$save())
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
610 smol_xcms_set_id <- smol_xcms_set$get_id()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
611 rm(smol_xcms_set)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
612
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
613 for (no in seq_along(names(singlefile))) {
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
614 sample_name <- names(singlefile)[[no]]
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
615 sample_path <- singlefile[[no]]
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
616 if (
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
617 is.na(no)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
618 || is.null(sample_path)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
619 || !(sample_name %in% sample_names)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
620 ) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
621 next
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
622 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
623 env <- new.env()
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
624
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
625 if (!DEBUG_FAST_IGNORE_SLOW_OP) {
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
626 ms_file <- xcms::xcmsRaw(sample_path)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
627 env$tic <- ms_file@tic
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
628 env$mz <- ms_file@env$mz
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
629 env$scanindex <- ms_file@scanindex
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
630 env$scantime <- ms_file@scantime * 60
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
631 env$intensity <- ms_file@env$intensity
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
632 env$polarity <- as.character(ms_file@polarity[[1]])
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
633
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
634 ## Again, ms file is huge, so we get rid of it quickly.
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
635 rm(ms_file)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
636
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
637 }
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
638 env$sample_name <- sample_name
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
639 env$dataset_path <- sample_path
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
640 env$process_params <- process_params
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
641 env$enriched_rdata <- TRUE
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
642 env$enriched_rdata_version <- ENRICHED_RDATA_VERSION
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
643 env$tool_name <- TOOL_NAME
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
644 env$enriched_rdata_doc <- ENRICHED_RDATA_DOC
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
645
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
646 sample <- add_sample_to_database(orm, env, context, smol_xcms_set_id)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
647 rm(env)
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
648 context$samples[no] <- sample$get_id()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
649 rm(sample)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
650 }
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
651 context$clusters <- list()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
652 context$show_percent <- show_percent
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
653 context$cluster_mean_rt_abundance <- list()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
654 context$central_feature <- list()
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
655 context$adducts <- list()
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
656 load_variable_metadata(orm, var_meta, context)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
657 clusters <- context$clusters
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
658 rm(context)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
659 message("Features enrichment")
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
660 complete_features(orm, clusters, show_percent)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
661 message("Features enrichment done.")
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
662 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
663 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
664
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
665 find_grouping_var <- function(var_meta) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
666 known_colnames <- c(
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
667 "name", "namecustom", "mz", "mzmin", "mzmax",
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
668 "rt", "rtmin", "rtmax", "npeaks", "isotopes", "adduct",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
669 "pcgroup", "ms_level"
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
670 )
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
671 col_names <- colnames(var_meta)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
672 classes <- list()
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
673 for (name in col_names) {
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
674 if (!(name %in% known_colnames)) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
675 classes[[length(classes) + 1]] <- name
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
676 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
677 }
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
678 if (length(classes) > 1) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
679 stop(sprintf(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
680 "Only one class expected in the variable metadata. Found %d .",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
681 length(classes)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
682 ))
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
683 }
7
5be8a770a11d " master branch Updating"
lain
parents: 6
diff changeset
684 if (length(classes) == 0) {
6
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
685 stop("Could not find any class column in your variableMetadata.")
207e36770d18 " master branch Updating"
lain
parents: 0
diff changeset
686 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
687 return(classes[[1]])
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
688 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
689
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
690 add_sample_to_database <- function(orm, env, context, smol_xcms_set_id) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
691 message(sprintf("Processing sample %s", env$sample_name))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
692 sample <- (
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
693 orm$sample()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
694 $set_name(env$sample_name)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
695 $set_path(env$dataset_path)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
696 $set_kind("enriched_rdata")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
697 $set_polarity(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
698 if (
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
699 is.null(env$polarity)
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
700 || identical(env$polarity, character(0))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
701 ) ""
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
702 else env$polarity
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
703 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
704 $set_raw(blob::blob(fst::compress_fst(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
705 serialize(env, NULL),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
706 compression = 100
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
707 )))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
708 )
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
709 sample[["smol_xcms_set_id"]] <- smol_xcms_set_id
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
710 sample$modified__[["smol_xcms_set_id"]] <- smol_xcms_set_id
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
711 sample <- sample$save()
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
712 load_process_params(orm, sample, env$process_params)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
713 message(sprintf("Sample %s inserted.", env$sample_name))
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
714 return(sample)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
715 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
716
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
717
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
718 load_variable_metadata <- function(orm, var_meta, context) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
719 all_clusters <- orm$cluster()$all()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
720
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
721 next_feature_id <- get_next_id(orm$feature()$all(), "featureID") + 1
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
722 next_cluster_id <- 0
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
723 next_pc_group <- get_next_id(all_clusters, "pc_group")
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
724 next_align_group <- get_next_id(all_clusters, "align_group") + 1
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
725 message("Extracting features")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
726 invisible(create_features(
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
727 orm, var_meta, context,
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
728 next_feature_id, next_cluster_id,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
729 next_pc_group, next_align_group
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
730 ))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
731 message("Extracting features done.")
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
732 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
733 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
734
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
735 get_next_id <- function(models, attribute) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
736 if ((id <- models$max(attribute)) == Inf || id == -Inf) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
737 return(0)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
738 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
739 return(id)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
740 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
741
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
742 create_features <- function(
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
743 orm, var_meta, context,
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
744 next_feature_id, next_cluster_id,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
745 next_pc_group, next_align_group
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
746 ) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
747 field_names <- as.list(names(orm$feature()$fields__))
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
748 field_names[field_names == "id"] <- NULL
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
749
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
750 dummy_feature <- orm$feature()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
751
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
752 if (show_percent <- context$show_percent) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
753 percent <- -1
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
754 total <- nrow(var_meta)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
755 }
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
756 rows <- seq_len(nrow(var_meta))
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
757 if (PROCESS_SMOL_BATCH) {
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
758
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
759 rows <- rows[1:as.integer(FAST_FEATURE_RATIO / 100.0 * length(rows))]
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
760 }
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
761 # features <- list()
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
762 features <- as.list(rows) ## allocate all memory before processing
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
763 # cluster_row <- list()
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
764 cluster_row <- as.list(rows) ## allocate all memory before processing
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
765 for (row in rows) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
766 if (show_percent && (row / total) * 100 > percent) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
767 percent <- percent + 1
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
768 message("\r", sprintf("\r%d %%", percent), appendLF = FALSE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
769 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
770
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
771 dummy_feature$set_featureID(next_feature_id)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
772 next_feature_id <- next_feature_id + 1
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
773
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
774 curent_var_meta <- var_meta[row, ]
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
775 set_feature_fields_from_var_meta(dummy_feature, curent_var_meta)
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
776 fake_iso <- dummy_feature$get_iso()
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
777 iso <- extract_iso(fake_iso)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
778 clusterID <- extract_clusterID(fake_iso, next_cluster_id)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
779 context$clusterID <- clusterID
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
780 dummy_feature$set_iso(iso)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
781
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
782 peak_list <- context$peaks[context$groupidx[[row]], ]
10
bb9ebd6365ea " master branch Updating"
lain
parents: 9
diff changeset
783 if (! ("matrix" %in% class(peak_list))) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
784 peak_list <- matrix(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
785 peak_list,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
786 nrow = 1,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
787 ncol = length(peak_list),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
788 dimnames = list(c(), names(peak_list))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
789 )
10
bb9ebd6365ea " master branch Updating"
lain
parents: 9
diff changeset
790 }
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
791
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
792 clusterID <- as.character(clusterID)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
793 if (is.null(context$central_feature[[clusterID]])) {
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
794 int_o <- extract_peak_var(peak_list, "into")
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
795 context$central_feature[[clusterID]] <- (
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
796 peak_list[peak_list[, "into"] == int_o, ]["sample"]
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
797 )
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
798 }
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
799
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
800 if (!DEBUG_FAST_IGNORE_SLOW_OP) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
801 central_feature <- context$central_feature[[clusterID]]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
802 sample_peak_list <- peak_list[
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
803 as.integer(peak_list[, "sample"]) == central_feature,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
804 ,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
805 drop = FALSE
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
806 ]
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
807 if (
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
808 !identical(sample_peak_list, numeric(0))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
809 && !is.null(nrow(sample_peak_list))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
810 && nrow(sample_peak_list) != 0
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
811 ) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
812 int_o <- extract_peak_var(sample_peak_list, "into")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
813 if (!is.na(int_o)) {
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
814 dummy_feature$set_int_o(int_o)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
815 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
816 int_b <- extract_peak_var(sample_peak_list, "intb")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
817 if (!is.na(int_b)) {
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
818 dummy_feature$set_int_b(int_b)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
819 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
820 max_o <- extract_peak_var(sample_peak_list, "maxo")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
821 if (!is.na(max_o)) {
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
822 dummy_feature$set_max_o(max_o)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
823 }
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
824 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
825 }
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
826
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
827 cluster_row[[row]] <- create_associated_cluster(
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
828 orm,
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
829 context$samples[context$central_feature[[clusterID]]][[1]],
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
830 dummy_feature, clusterID,
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
831 context, curent_var_meta, next_pc_group,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
832 next_align_group
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
833 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
834 next_align_group <- next_align_group + 1
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
835 features[[row]] <- as.list(dummy_feature, field_names)
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
836 # features[[length(features) + 1]] <- as.list(dummy_feature, field_names)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
837 dummy_feature$clear()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
838 }
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
839 rm(var_meta)
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
840 message("")
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
841 message("Saving features")
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
842 invisible(dummy_feature$save(bulk = features))
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
843
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
844 ## We link manually clusters to the sample they're in.
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
845 link_cache <- list()
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
846 for (row in rows) {
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
847 sample_nos <- unique(context$peaks[context$groupidx[[row]], "sample"])
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
848 for (sample_id in context$samples[sample_nos]) {
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
849 cluster_id <- cluster_row[[row]]$get_id()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
850 id <- paste(sample_id, cluster_id, sep = ";")
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
851 if (is.null(link_cache[[id]])) {
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
852 link_cache[[id]] <- 1
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
853 orm$cluster_sample(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
854 sample_id = sample_id,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
855 cluster_id = cluster_id
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
856 )$save()
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
857 }
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
858 }
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
859 }
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
860
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
861 message("Saved.")
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
862 return(context$clusters)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
863 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
864
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
865 extract_peak_var <- function(peak_list, var_name, selector = max) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
866 value <- peak_list[, var_name]
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
867 names(value) <- NULL
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
868 return(selector(value))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
869 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
870
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
871 set_feature_fields_from_var_meta <- function(feature, var_meta) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
872 if (!is.null(mz <- var_meta[["mz"]]) && !is.na(mz)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
873 feature$set_mz(mz)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
874 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
875 if (!is.null(mzmin <- var_meta[["mzmin"]]) && !is.na(mzmin)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
876 feature$set_mz_min(mzmin)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
877 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
878 if (!is.null(mzmax <- var_meta[["mzmax"]]) && !is.na(mzmax)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
879 feature$set_mz_max(mzmax)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
880 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
881 if (!is.null(rt <- var_meta[["rt"]]) && !is.na(rt)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
882 feature$set_rt(rt)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
883 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
884 if (!is.null(rtmin <- var_meta[["rtmin"]]) && !is.na(rtmin)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
885 feature$set_rt_min(rtmin)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
886 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
887 if (!is.null(rtmax <- var_meta[["rtmax"]]) && !is.na(rtmax)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
888 feature$set_rt_max(rtmax)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
889 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
890 if (!is.null(isotopes <- var_meta[["isotopes"]]) && !is.na(isotopes)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
891 feature$set_iso(isotopes)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
892 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
893 return(feature)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
894 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
895
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
896 extract_iso <- function(weird_data) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
897 if (grepl("^\\[\\d+\\]", weird_data)[[1]]) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
898 return(sub("^\\[\\d+\\]", "", weird_data, perl = TRUE))
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
899 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
900 return(weird_data)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
901 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
902
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
903 extract_clusterID <- function(weird_data, next_cluster_id) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
904 if (grepl("^\\[\\d+\\]", weird_data)[[1]]) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
905 clusterID <- stringr::str_extract(weird_data, "^\\[\\d+\\]")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
906 clusterID <- as.numeric(stringr::str_extract(clusterID, "\\d+"))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
907 } else {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
908 clusterID <- 0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
909 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
910 return(clusterID + next_cluster_id)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
911 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
912
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
913 create_associated_cluster <- function(
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
914 orm,
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
915 main_sample_id, feature, clusterID,
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
916 context, curent_var_meta, next_pc_group, next_align_group
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
917 ) {
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
918 clusterID <- as.character(clusterID)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
919 if (is.null(cluster <- context$clusters[[clusterID]])) {
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
920 pcgroup <- as.numeric(curent_var_meta[["pcgroup"]])
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
921 adduct_name <- as.character(curent_var_meta[["adduct"]])
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
922 annotation <- curent_var_meta[["isotopes"]]
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
923 cluster <- context$clusters[[clusterID]] <- orm$cluster(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
924 pc_group = pcgroup + next_pc_group,
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
925 # adduct=adduct,
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
926 align_group = next_align_group,
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
927 # curent_group=curent_group,
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
928 clusterID = context$clusterID,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
929 annotation = annotation
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
930 )
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
931 if (is.null(adduct <- context$adducts[[adduct_name]])) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
932 context$adducts[[adduct_name]] <- orm$adduct()$load_by(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
933 name = adduct_name
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
934 )$first()
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
935 if (is.null(adduct <- context$adducts[[adduct_name]])) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
936 adduct <- context$adducts[[adduct_name]] <- orm$adduct(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
937 name = adduct_name,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
938 charge = 0
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
939 )
12
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
940 adduct$save()
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
941 }
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
942 }
bdb2878ee189 " master branch Updating"
lain
parents: 11
diff changeset
943 cluster$set_adduct(adduct)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
944 ## Crappy hack to assign sample id to cluster without loading the
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
945 ## sample. Samples are too big (their sample$env) and slows the
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
946 ## process, and eat all the menory so we dont't want to load them.
14
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
947 cluster[["sample_id"]] <- main_sample_id
00079fadc240 " master branch Updating"
lain
parents: 13
diff changeset
948 cluster$modified__[["sample_id"]] <- main_sample_id
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
949 } else {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
950 if (context$clusterID != 0 && cluster$get_clusterID() == 0) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
951 cluster$set_clusterID(context$clusterID)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
952 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
953 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
954 cluster$save()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
955 feature$set_cluster(cluster)
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
956 feature$save()
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
957 return(cluster)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
958 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
959
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
960 complete_features <- function(orm, clusters, show_percent) {
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
961 total <- length(clusters)
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
962 percent <- -1
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
963 i <- 0
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
964 for (cluster in clusters) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
965 i <- i + 1
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
966 if (show_percent && (i / total) * 100 > percent) {
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
967 percent <- percent + 1
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
968 message("\r", sprintf("\r%d %%", percent), appendLF = FALSE)
11
f4fc4a0f41e2 " master branch Updating"
lain
parents: 10
diff changeset
969 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
970 features <- orm$feature()$load_by(cluster_id = cluster$get_id())
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
971 if (features$any()) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
972 if (!is.null(rt <- features$mean("rt"))) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
973 cluster$set_mean_rt(rt)$save()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
974 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
975 features_df <- as.data.frame(features)
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
976 central_feature <- features_df[
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
977 grepl("^\\[M\\]", features_df[, "iso"]),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
978 ]
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
979 central_feature_into <- central_feature[["int_o"]]
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
980 if (
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
981 !identical(central_feature_into, numeric(0))
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
982 && central_feature_into != 0
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
983 ) {
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
984 for (feature in as.vector(features)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
985 feature$set_abundance(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
986 feature$get_int_o() / central_feature_into * 100
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
987 )$save()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
988 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
989 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
990 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
991 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
992 return(NULL)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
993 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
994
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
995 load_process_params <- function(orm, sample, params) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
996 for (param_list in params) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
997 if (is.null(param_list[["xfunction"]])) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
998 next
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
999 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1000 if (param_list[["xfunction"]] == "annotatediff") {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1001 load_process_params_peak_picking(orm, sample, param_list)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1002 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1003 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1004 return(sample)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1005 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1006
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1007 load_process_params_peak_picking <- function(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1008 orm,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1009 sample,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1010 peak_picking_params
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1011 ) {
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1012 return(add_sample_process_parameters(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1013 params = peak_picking_params,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1014 params_translation = list(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1015 ppm = "ppm",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1016 maxcharge = "maxCharge",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1017 maxiso = "maxIso"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1018 ),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1019 param_model_generator = orm$peak_picking_parameters,
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1020 sample_param_setter = sample$set_peak_picking_parameters
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1021 ))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1022 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1023
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1024 add_sample_process_parameters <- function(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1025 params,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1026 params_translation,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1027 param_model_generator,
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1028 sample_param_setter
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1029 ) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1030 model_params <- list()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1031 for (rdata_param_name in names(params_translation)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1032 database_param_name <- params_translation[[rdata_param_name]]
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1033 if (is.null(rdata_param <- params[[rdata_param_name]])) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1034 next
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1035 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1036 model_params[[database_param_name]] <- rdata_param
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1037 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1038 params_models <- do.call(param_model_generator()$load_by, model_params)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1039 if (params_models$any()) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1040 params_model <- params_models$first()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1041 } else {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1042 params_model <- do.call(param_model_generator, model_params)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1043 params_model$save()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1044 }
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1045 return(sample_param_setter(params_model)$save())
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1046 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1047
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1048
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1049 library(optparse)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1050
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1051 option_list <- list(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1052 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1053 c("-v", "--version"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1054 action = "store_true",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1055 help = "Display this tool's version and exits"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1056 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1057 optparse::make_option(
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1058 c("-V", "--verbose"),
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1059 action = "store_true",
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1060 help = "Does more verbose outputs",
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1061 default = FALSE
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1062 ),
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1063 optparse::make_option(
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1064 c("-i", "--input"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1065 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1066 help = "The rdata path to import in XSeeker"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1067 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1068 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1069 c("-s", "--samples"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1070 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1071 help = "Samples to visualise in XSeeker"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1072 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1073 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1074 c("-B", "--archetype"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1075 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1076 help = "The name of the base database"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1077 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1078 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1079 c("-b", "--database"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1080 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1081 help = "The base database's path"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1082 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1083 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1084 c("-c", "--compounds-csv"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1085 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1086 help = "The csv containing compounds"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1087 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1088 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1089 c("-m", "--models"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1090 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1091 help = paste(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1092 "The path or url (must begin with http[s]:// or git@) to",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1093 "the database's models"
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1094 )
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1095 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1096 optparse::make_option(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1097 c("-k", "--class"),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1098 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1099 help = "The name of the column containing the classes"
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1100 ),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1101 optparse::make_option(
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1102 c("-o", "--output"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1103 type = "character",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1104 help = "The path where to output sqlite"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1105 ),
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1106 optparse::make_option(
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1107 c("-P", "--not-show-percent"),
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1108 action = "store_true",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1109 help = "Flag not to show the percents",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1110 default = FALSE
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1111 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1112 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1113
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1114 options(error = function(){traceback(3)})
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1115
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1116 parser <- OptionParser(
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1117 usage = "%prog [options] file",
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1118 option_list = option_list
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1119 )
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1120 args <- parse_args(parser, positional_arguments = 0)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1121
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1122 err_code <- 0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1123
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1124 if (!is.null(args$options$version)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1125 message(sprintf("%s %s", TOOL_NAME, VERSION))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1126 quit()
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1127 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1128
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1129 models <- get_models(args$options$models)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1130 orm <- DBModelR::ORM(
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1131 connection_params = list(dbname=args$options$output),
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1132 dbms = "SQLite"
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1133 )
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1134
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1135 invisible(orm$models(models))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1136 invisible(create_database(orm))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1137
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1138 message("Database model created")
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1139
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1140 insert_adducts(orm)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1141
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1142 if (!is.null(args$options$database)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1143 insert_base_data(orm, args$options$database)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1144 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1145 message(sprintf("Base data inserted using %s.", args$options$database))
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1146
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1147 if (!is.null(args$options$archetype)) {
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1148 insert_base_data(orm, args$options$archetype, archetype = TRUE)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1149 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1150 if (!is.null(args$options$`compounds-csv`)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1151 insert_compounds(orm, args$options$`compounds-csv`)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1152 }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1153
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1154 # if (!is.null(args$options$rdata)) {
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1155 # load_rdata_in_base(args$options$rdata, args$options$samples, args$options$`not-show-percent`)
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1156 # }
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1157
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1158
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1159 load(args$options$input, rdata <- new.env())
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1160
20
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1161 args$options$verbose <- (
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1162 if (args$options$verbose) {
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1163 message("Verbose outputs.")
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1164 \(...) {
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1165 message(sprintf(...))
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1166 }
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1167 } else {
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1168 \(...) {
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1169 }
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1170 }
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1171 )
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1172
ce94e7a141bb " master branch Updating"
lain
parents: 19
diff changeset
1173 err_code <- process_rdata(orm, rdata, args$options)
0
a174cbbb12dd " master branch Updating"
lain
parents:
diff changeset
1174
19
2937e72e5891 " master branch Updating"
lain
parents: 18
diff changeset
1175 quit(status = err_code)