annotate resources/galaxy/GIE/tools/LC-MSMS/XSeekerPreparator.R @ 0:15c9fbefeaf1 draft

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