comparison spectralMatching.R @ 6:a67b129cd78e draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
author computational-metabolomics
date Thu, 04 Mar 2021 12:30:15 +0000
parents c635d8b0b929
children
comparison
equal deleted inserted replaced
5:4b627470dea2 6:a67b129cd78e
1 library(msPurity) 1 library(msPurity)
2 library(msPurityData) 2 library(msPurityData)
3 library(optparse) 3 library(optparse)
4 print(sessionInfo()) 4 print(sessionInfo())
5 # load in library spectra config 5 # load in library spectra config
6 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } 6 source_local <- function(fname) {
7 argv <- commandArgs(trailingOnly = FALSE)
8 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
9 source(paste(base_dir, fname, sep = "/"))
10 }
7 source_local("dbconfig.R") 11 source_local("dbconfig.R")
8 12
9 option_list <- list( 13 option_list <- list(
10 make_option(c("-o", "--outDir"), type="character"), 14 make_option(c("-o", "--outDir"), type = "character"),
11 make_option("--q_dbPth", type="character"), 15 make_option("--q_dbPth", type = "character"),
12 make_option("--l_dbPth", type="character"), 16 make_option("--l_dbPth", type = "character"),
13 17
14 make_option("--q_dbType", type="character", default=NA), 18 make_option("--q_dbType", type = "character", default = NA),
15 make_option("--l_dbType", type="character", default=NA), 19 make_option("--l_dbType", type = "character", default = NA),
16 20
17 make_option("--q_msp", type="character", default=NA), 21 make_option("--q_msp", type = "character", default = NA),
18 make_option("--l_msp", type="character", default=NA), 22 make_option("--l_msp", type = "character", default = NA),
19 23
20 make_option("--q_defaultDb", action="store_true"), 24 make_option("--q_defaultDb", action = "store_true"),
21 make_option("--l_defaultDb", action="store_true"), 25 make_option("--l_defaultDb", action = "store_true"),
22 26
23 make_option("--q_ppmPrec", type="double"), 27 make_option("--q_ppmPrec", type = "double"),
24 make_option("--l_ppmPrec", type="double"), 28 make_option("--l_ppmPrec", type = "double"),
25 29
26 make_option("--q_ppmProd", type="double"), 30 make_option("--q_ppmProd", type = "double"),
27 make_option("--l_ppmProd", type="double"), 31 make_option("--l_ppmProd", type = "double"),
28 32
29 make_option("--q_raThres", type="double", default=NA), 33 make_option("--q_raThres", type = "double", default = NA),
30 make_option("--l_raThres", type="double", default=NA), 34 make_option("--l_raThres", type = "double", default = NA),
31 35
32 make_option("--q_polarity", type="character", default=NA), 36 make_option("--q_polarity", type = "character", default = NA),
33 make_option("--l_polarity", type="character", default=NA), 37 make_option("--l_polarity", type = "character", default = NA),
34 38
35 make_option("--q_purity", type="double", default=NA), 39 make_option("--q_purity", type = "double", default = NA),
36 make_option("--l_purity", type="double", default=NA), 40 make_option("--l_purity", type = "double", default = NA),
37 41
38 make_option("--q_xcmsGroups", type="character", default=NA), 42 make_option("--q_xcmsGroups", type = "character", default = NA),
39 make_option("--l_xcmsGroups", type="character", default=NA), 43 make_option("--l_xcmsGroups", type = "character", default = NA),
40 44
41 make_option("--q_pids", type="character", default=NA), 45 make_option("--q_pids", type = "character", default = NA),
42 make_option("--l_pids", type="character", default=NA), 46 make_option("--l_pids", type = "character", default = NA),
43 47
44 make_option("--q_rtrangeMin", type="double", default=NA), 48 make_option("--q_rtrangeMin", type = "double", default = NA),
45 make_option("--l_rtrangeMin", type="double", default=NA), 49 make_option("--l_rtrangeMin", type = "double", default = NA),
46 50
47 make_option("--q_rtrangeMax", type="double", default=NA), 51 make_option("--q_rtrangeMax", type = "double", default = NA),
48 make_option("--l_rtrangeMax", type="double", default=NA), 52 make_option("--l_rtrangeMax", type = "double", default = NA),
49 53
50 make_option("--q_accessions", type="character", default=NA), 54 make_option("--q_accessions", type = "character", default = NA),
51 make_option("--l_accessions", type="character", default=NA), 55 make_option("--l_accessions", type = "character", default = NA),
52 56
53 make_option("--q_sources", type="character", default=NA), 57 make_option("--q_sources", type = "character", default = NA),
54 make_option("--l_sources", type="character", default=NA), 58 make_option("--l_sources", type = "character", default = NA),
55 59
56 make_option("--q_sourcesUser", type="character", default=NA), 60 make_option("--q_sourcesUser", type = "character", default = NA),
57 make_option("--l_sourcesUser", type="character", default=NA), 61 make_option("--l_sourcesUser", type = "character", default = NA),
58 62
59 make_option("--q_instrumentTypes", type="character", default=NA), 63 make_option("--q_instrumentTypes", type = "character", default = NA),
60 make_option("--l_instrumentTypes", type="character", default=NA), 64 make_option("--l_instrumentTypes", type = "character", default = NA),
61 65
62 make_option("--q_instrumentTypesUser", type="character", default=NA), 66 make_option("--q_instrumentTypesUser", type = "character", default = NA),
63 make_option("--l_instrumentTypesUser", type="character", default=NA), 67 make_option("--l_instrumentTypesUser", type = "character", default = NA),
64 68
65 make_option("--q_instruments", type="character", default=NA), 69 make_option("--q_instruments", type = "character", default = NA),
66 make_option("--l_instruments", type="character", default=NA), 70 make_option("--l_instruments", type = "character", default = NA),
67 71
68 make_option("--q_spectraTypes", type="character", default=NA), 72 make_option("--q_spectraTypes", type = "character", default = NA),
69 make_option("--l_spectraTypes", type="character", default=NA), 73 make_option("--l_spectraTypes", type = "character", default = NA),
70 74
71 make_option("--q_spectraFilter", action="store_true"), 75 make_option("--q_spectraFilter", action = "store_true"),
72 make_option("--l_spectraFilter", action="store_true"), 76 make_option("--l_spectraFilter", action = "store_true"),
73 77
74 make_option("--usePrecursors", action="store_true"), 78 make_option("--usePrecursors", action = "store_true"),
75 79
76 make_option("--mzW", type="double"), 80 make_option("--mzW", type = "double"),
77 make_option("--raW", type="double"), 81 make_option("--raW", type = "double"),
78 82
79 make_option("--rttol", type="double", default=NA), 83 make_option("--rttol", type = "double", default = NA),
80 84
81 make_option("--updateDb", action="store_true"), 85 make_option("--updateDb", action = "store_true"),
82 make_option("--copyDb", action="store_true"), 86 make_option("--copyDb", action = "store_true"),
83 make_option("--cores", default=1) 87 make_option("--cores", default = 1)
84 88
85 89
86 ) 90 )
87 91
88 # store options 92 # store options
89 opt<- parse_args(OptionParser(option_list=option_list)) 93 opt <- parse_args(OptionParser(option_list = option_list))
90 94
91 print(opt) 95 print(opt)
92 96
93 # check if the sqlite databases have any spectra 97 # check if the sqlite databases have any spectra
94 checkSPeakMeta <- function(dbPth, nme){ 98 checkSPeakMeta <- function(dbPth, nme) {
95 if(is.null(dbPth)){ 99 if (is.null(dbPth)) {
96 return(TRUE) 100 return(TRUE)
97 }else if ((file.exists(dbPth)) & (file.info(dbPth)$size>0)){ 101 }else if ((file.exists(dbPth)) & (file.info(dbPth)$size > 0)) {
98 con <- DBI::dbConnect(RSQLite::SQLite(), dbPth) 102 con <- DBI::dbConnect(RSQLite::SQLite(), dbPth)
99 if (DBI::dbExistsTable(con, "s_peak_meta")){ 103 if (DBI::dbExistsTable(con, "s_peak_meta")) {
100 spm <- DBI::dbGetQuery(con, 'SELECT * FROM s_peak_meta ORDER BY ROWID ASC LIMIT 1') 104 spm <- DBI::dbGetQuery(con, "SELECT * FROM s_peak_meta ORDER BY ROWID ASC LIMIT 1")
101 return(TRUE) 105 return(TRUE)
102 }else if(DBI::dbExistsTable(con, "library_spectra_meta")){ 106 }else if (DBI::dbExistsTable(con, "library_spectra_meta")) {
103 spm <- DBI::dbGetQuery(con, 'SELECT * FROM library_spectra_meta ORDER BY ROWID ASC LIMIT 1') 107 spm <- DBI::dbGetQuery(con, "SELECT * FROM library_spectra_meta ORDER BY ROWID ASC LIMIT 1")
104 return(TRUE) 108 return(TRUE)
105 }else{ 109 }else{
106 print(paste("No spectra available for ",nme)) 110 print(paste("No spectra available for ", nme))
107 return(FALSE) 111 return(FALSE)
108 } 112 }
109 }else{ 113 }else{
110 print(paste("file empty or does not exist for", nme)) 114 print(paste("file empty or does not exist for", nme))
111 return(FALSE) 115 return(FALSE)
112 } 116 }
113 117
114 118
115 } 119 }
116 120
117 121
118 addQueryNameColumn <- function(sm){ 122 addQueryNameColumn <- function(sm) {
119 if (is.null(sm$matchedResults) || length(sm$matchedResults)==1 || nrow(sm$matchedResults)==0){ 123 if (is.null(sm$matchedResults) || length(sm$matchedResults) == 1 || nrow(sm$matchedResults) == 0) {
120 return(sm) 124 return(sm)
121 } 125 }
122 126
123 con <- DBI::dbConnect(RSQLite::SQLite(),sm$q_dbPth) 127 con <- DBI::dbConnect(RSQLite::SQLite(), sm$q_dbPth)
124 if (DBI::dbExistsTable(con, "s_peak_meta")){ 128 if (DBI::dbExistsTable(con, "s_peak_meta")) {
125 spm <- DBI::dbGetQuery(con, 'SELECT pid, name AS query_entry_name FROM s_peak_meta') 129 spm <- DBI::dbGetQuery(con, "SELECT pid, name AS query_entry_name FROM s_peak_meta")
126 }else if(DBI::dbExistsTable(con, "library_spectra_meta")){ 130 }else if (DBI::dbExistsTable(con, "library_spectra_meta")) {
127 spm <- DBI::dbGetQuery(con, 'SELECT id AS pid, name AS query_entry_name FROM library_spectra_meta') 131 spm <- DBI::dbGetQuery(con, "SELECT id AS pid, name AS query_entry_name FROM library_spectra_meta")
128 } 132 }
129 print(sm$matchedResults) 133 print(sm$matchedResults)
130 if ('pid' %in% colnames(sm$matchedResults)){ 134 if ("pid" %in% colnames(sm$matchedResults)) {
131 sm$matchedResults <- merge(sm$matchedResults, spm, by.x='pid', by.y='pid') 135 sm$matchedResults <- merge(sm$matchedResults, spm, by.x = "pid", by.y = "pid")
132 }else{ 136 }else{
133 sm$matchedResults <- merge(sm$matchedResults, spm, by.x='qpid', by.y='pid') 137 sm$matchedResults <- merge(sm$matchedResults, spm, by.x = "qpid", by.y = "pid")
134 } 138 }
135 139
136 print(sm$xcmsMatchedResults) 140 print(sm$xcmsMatchedResults)
137 if (is.null(sm$xcmsMatchedResults) || length(sm$xcmsMatchedResults)==1 || nrow(sm$xcmsMatchedResults)==0){ 141 if (is.null(sm$xcmsMatchedResults) || length(sm$xcmsMatchedResults) == 1 || nrow(sm$xcmsMatchedResults) == 0) {
138 return(sm) 142 return(sm)
139 }else{ 143 }else{
140 if ('pid' %in% colnames(sm$xcmsMatchedResults)){ 144 if ("pid" %in% colnames(sm$xcmsMatchedResults)) {
141 sm$xcmsMatchedResults<- merge(sm$xcmsMatchedResults, spm, by.x='pid', by.y='pid') 145 sm$xcmsMatchedResults <- merge(sm$xcmsMatchedResults, spm, by.x = "pid", by.y = "pid")
142 }else{ 146 }else{
143 sm$xcmsMatchedResults <- merge(sm$xcmsMatchedResults, spm, by.x='qpid', by.y='pid') 147 sm$xcmsMatchedResults <- merge(sm$xcmsMatchedResults, spm, by.x = "qpid", by.y = "pid")
144 } 148 }
145 } 149 }
146 150
147 return(sm) 151 return(sm)
148 152
149 } 153 }
150 154
151 155
152 updateDbF <- function(q_con, l_con){ 156 updateDbF <- function(q_con, l_con) {
153 message('Adding extra details to database') 157 message("Adding extra details to database")
154 q_con <- DBI::dbConnect(RSQLite::SQLite(),sm$q_dbPth) 158 q_con <- DBI::dbConnect(RSQLite::SQLite(), sm$q_dbPth)
155 if (DBI::dbExistsTable(q_con, "l_s_peak_meta")){ 159 if (DBI::dbExistsTable(q_con, "l_s_peak_meta")) {
156 l_s_peak_meta <- DBI::dbGetQuery(q_con, 'SELECT * FROM l_s_peak_meta') 160 l_s_peak_meta <- DBI::dbGetQuery(q_con, "SELECT * FROM l_s_peak_meta")
157 colnames(l_s_peak_meta)[1] <- 'pid' 161 colnames(l_s_peak_meta)[1] <- "pid"
158 } 162 }
159 163
160 l_con <- DBI::dbConnect(RSQLite::SQLite(),l_dbPth) 164 l_con <- DBI::dbConnect(RSQLite::SQLite(), l_dbPth)
161 if (DBI::dbExistsTable(l_con, "s_peaks")){ 165 if (DBI::dbExistsTable(l_con, "s_peaks")) {
162 l_s_peaks <- DBI::dbGetQuery(q_con, sprintf("SELECT * FROM s_peaks WHERE pid in (%s)", paste(unique(l_s_peak_meta$pid), collapse=','))) 166 l_s_peaks <- DBI::dbGetQuery(q_con, sprintf("SELECT * FROM s_peaks WHERE pid in (%s)", paste(unique(l_s_peak_meta$pid), collapse = ",")))
163 167
164 }else if(DBI::dbExistsTable(l_con, "library_spectra")){ 168 }else if (DBI::dbExistsTable(l_con, "library_spectra")) {
165 l_s_peaks <- DBI::dbGetQuery(l_con, sprintf("SELECT * FROM library_spectra 169 l_s_peaks <- DBI::dbGetQuery(l_con, sprintf("SELECT * FROM library_spectra
166 WHERE library_spectra_meta_id in (%s)", paste(unique(l_s_peak_meta$pid), collapse=','))) 170 WHERE library_spectra_meta_id in (%s)", paste(unique(l_s_peak_meta$pid), collapse = ",")))
167 }else{ 171 }else{
168 l_s_peaks = NULL 172 l_s_peaks <- NULL
169 } 173 }
170 174
171 if (DBI::dbExistsTable(l_con, "source")){ 175 if (DBI::dbExistsTable(l_con, "source")) {
172 l_source <- DBI::dbGetQuery(l_con, 'SELECT * FROM source') 176 l_source <- DBI::dbGetQuery(l_con, "SELECT * FROM source")
173 }else if (DBI::dbExistsTable(l_con, "library_spectra_source")) { 177 }else if (DBI::dbExistsTable(l_con, "library_spectra_source")) {
174 l_source <- DBI::dbGetQuery(l_con, 'SELECT * FROM library_spectra_source') 178 l_source <- DBI::dbGetQuery(l_con, "SELECT * FROM library_spectra_source")
175 }else{ 179 }else{
176 l_source = NULL 180 l_source <- NULL
177 } 181 }
178 182
179 if (!is.null(l_s_peaks)){ 183 if (!is.null(l_s_peaks)) {
180 DBI::dbWriteTable(q_con, name='l_s_peaks', value=l_s_peaks, row.names=FALSE, append=TRUE) 184 DBI::dbWriteTable(q_con, name = "l_s_peaks", value = l_s_peaks, row.names = FALSE, append = TRUE)
181 } 185 }
182 186
183 if (!is.null(l_source)){ 187 if (!is.null(l_source)) {
184 DBI::dbWriteTable(q_con, name='l_source', value=l_source, row.names=FALSE, append=TRUE) 188 DBI::dbWriteTable(q_con, name = "l_source", value = l_source, row.names = FALSE, append = TRUE)
185 } 189 }
186 190
187 191 }
188 } 192
189 193
190 194 extractMultiple <- function(optParam) {
191 extractMultiple <- function(optParam){ 195 if (!is.na(optParam)) {
192 if (!is.na(optParam)){ 196 param <- trimws(strsplit(optParam, ",")[[1]])
193 param <- trimws(strsplit(optParam, ',')[[1]])
194 param <- param[param != ""] 197 param <- param[param != ""]
195 }else{ 198 }else {
196 param <- NA 199 param <- NA
197 } 200 }
198 return(param) 201 return(param)
199 202
200 } 203 }
201 204
202 if(!is.null(opt$q_defaultDb)){ 205 if (!is.null(opt$q_defaultDb)) {
203 q_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package="msPurityData") 206 q_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package = "msPurityData")
204 q_dbType <- 'sqlite' 207 q_dbType <- "sqlite"
205 }else if (!opt$q_dbType=='local_config'){ 208 }else if (!opt$q_dbType == "local_config") {
206 q_dbType <- opt$q_dbType 209 q_dbType <- opt$q_dbType
207 q_dbPth <- opt$q_dbPth 210 q_dbPth <- opt$q_dbPth
208 } 211 }
209 212
210 if(!is.null(opt$l_defaultDb)){ 213 if (!is.null(opt$l_defaultDb)) {
211 l_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package="msPurityData") 214 l_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package = "msPurityData")
212 l_dbType <- 'sqlite' 215 l_dbType <- "sqlite"
213 }else if (!opt$l_dbType=='local_config'){ 216 }else if (!opt$l_dbType == "local_config") {
214 l_dbType <- opt$l_dbType 217 l_dbType <- opt$l_dbType
215 l_dbPth <- opt$l_dbPth 218 l_dbPth <- opt$l_dbPth
216 } 219 }
217 220
221 q_spectraTypes <- extractMultiple(opt$q_spectraTypes)
222 l_spectraTypes <- extractMultiple(opt$l_spectraTypes)
218 223
219 q_polarity <- extractMultiple(opt$q_polarity) 224 q_polarity <- extractMultiple(opt$q_polarity)
220 l_polarity <- extractMultiple(opt$l_polarity) 225 l_polarity <- extractMultiple(opt$l_polarity)
221 226
222 q_xcmsGroups <- extractMultiple(opt$q_xcmsGroups) 227 q_xcmsGroups <- extractMultiple(opt$q_xcmsGroups)
229 l_sources <- extractMultiple(opt$l_sources) 234 l_sources <- extractMultiple(opt$l_sources)
230 235
231 q_sourcesUser <- extractMultiple(opt$q_sourcesUser) 236 q_sourcesUser <- extractMultiple(opt$q_sourcesUser)
232 l_sourcesUser <- extractMultiple(opt$l_sourcesUser) 237 l_sourcesUser <- extractMultiple(opt$l_sourcesUser)
233 238
234 q_sources <-c(q_sources, q_sourcesUser) 239 q_sources <- c(q_sources, q_sourcesUser)
235 l_sources <-c(l_sources, l_sourcesUser) 240 l_sources <- c(l_sources, l_sourcesUser)
236 241
237 q_instrumentTypes <- extractMultiple(opt$q_instrumentTypes) 242 q_instrumentTypes <- extractMultiple(opt$q_instrumentTypes)
238 l_instrumentTypes <- extractMultiple(opt$l_instrumentTypes) 243 l_instrumentTypes <- extractMultiple(opt$l_instrumentTypes)
239 244
240 q_instrumentTypes <-c(q_instrumentTypes, q_instrumentTypes) 245 q_instrumentTypes <- c(q_instrumentTypes, q_instrumentTypes)
241 l_instrumentTypes <-c(l_instrumentTypes, l_instrumentTypes) 246 l_instrumentTypes <- c(l_instrumentTypes, l_instrumentTypes)
242 247
243 248
244 if(!is.null(opt$l_spectraFilter)){ 249 if (!is.null(opt$l_spectraFilter)) {
245 l_spectraFilter <- TRUE 250 l_spectraFilter <- TRUE
246 }else{ 251 }else{
247 l_spectraFilter <- FALSE 252 l_spectraFilter <- FALSE
248 } 253 }
249 254
250 if(!is.null(opt$q_spectraFilter)){ 255 if (!is.null(opt$q_spectraFilter)) {
251 q_spectraFilter <- TRUE 256 q_spectraFilter <- TRUE
252 }else{ 257 }else{
253 q_spectraFilter <- FALSE 258 q_spectraFilter <- FALSE
254 } 259 }
255 260
256 if(!is.null(opt$updateDb)){ 261 if (!is.null(opt$updateDb)) {
257 updateDb <- TRUE 262 updateDb <- TRUE
258 }else{ 263 }else{
259 updateDb <- FALSE 264 updateDb <- FALSE
260 } 265 }
261 266
262 if(!is.null(opt$copyDb)){ 267 if (!is.null(opt$copyDb)) {
263 copyDb <- TRUE 268 copyDb <- TRUE
264 }else{ 269 }else{
265 copyDb <- FALSE 270 copyDb <- FALSE
266 } 271 }
267 272
268 if(!is.null(opt$l_rtrangeMax)){ 273 if (!is.null(opt$l_rtrangeMax)) {
269 l_rtrangeMax <- opt$l_rtrangeMax 274 l_rtrangeMax <- opt$l_rtrangeMax
270 }else{ 275 }else{
271 l_rtrangeMax <- NA 276 l_rtrangeMax <- NA
272 } 277 }
273 278
274 if(!is.null(opt$q_rtrangeMax)){ 279 if (!is.null(opt$q_rtrangeMax)) {
275 q_rtrangeMax <- opt$q_rtrangeMax 280 q_rtrangeMax <- opt$q_rtrangeMax
276 }else{ 281 }else{
277 q_rtrangeMax <- NA 282 q_rtrangeMax <- NA
278 } 283 }
279 284
280 if(!is.null(opt$l_rtrangeMin)){ 285 if (!is.null(opt$l_rtrangeMin)) {
281 l_rtrangeMin <- opt$l_rtrangeMin 286 l_rtrangeMin <- opt$l_rtrangeMin
282 }else{ 287 }else{
283 l_rtrangeMin <- NA 288 l_rtrangeMin <- NA
284 } 289 }
285 290
286 if(!is.null(opt$q_rtrangeMin)){ 291 if (!is.null(opt$q_rtrangeMin)) {
287 q_rtrangeMin <- opt$q_rtrangeMin 292 q_rtrangeMin <- opt$q_rtrangeMin
288 }else{ 293 }else{
289 q_rtrangeMin <- NA 294 q_rtrangeMin <- NA
290 } 295 }
291 296
292 q_check <- checkSPeakMeta(opt$q_dbPth, 'query') 297 q_check <- checkSPeakMeta(opt$q_dbPth, "query")
293 l_check <- checkSPeakMeta(opt$l_dbPth, 'library') 298 l_check <- checkSPeakMeta(opt$l_dbPth, "library")
294 299
295 300
296 if (q_check && l_check){ 301 if (q_check && l_check) {
297 sm <- msPurity::spectralMatching( 302 sm <- msPurity::spectralMatching(
298 q_purity = opt$q_purity, 303 q_purity = opt$q_purity,
299 l_purity = opt$l_purity, 304 l_purity = opt$l_purity,
300 305
301 q_ppmProd = opt$q_ppmProd, 306 q_ppmProd = opt$q_ppmProd,
302 l_ppmProd = opt$l_ppmProd, 307 l_ppmProd = opt$l_ppmProd,
303 308
304 q_ppmPrec = opt$q_ppmPrec, 309 q_ppmPrec = opt$q_ppmPrec,
305 l_ppmPrec = opt$l_ppmPrec, 310 l_ppmPrec = opt$l_ppmPrec,
306 311
307 q_raThres = opt$q_raThres, 312 q_raThres = opt$q_raThres,
308 l_raThres = opt$l_raThres, 313 l_raThres = opt$l_raThres,
309 314
310 q_pol = q_polarity, 315 q_pol = q_polarity,
311 l_pol = l_polarity, 316 l_pol = l_polarity,
312 317
318 q_spectraFilter = q_spectraFilter,
319 l_spectraFilter = l_spectraFilter,
320
313 q_xcmsGroups = q_xcmsGroups, 321 q_xcmsGroups = q_xcmsGroups,
314 l_xcmsGroups = l_xcmsGroups, 322 l_xcmsGroups = l_xcmsGroups,
315 323
316 q_pids = q_pids, 324 q_pids = q_pids,
317 l_pids = l_pids, 325 l_pids = l_pids,
318 326
319 q_sources = q_sources, 327 q_sources = q_sources,
320 l_sources = l_sources, 328 l_sources = l_sources,
321 329
322 q_instrumentTypes = q_instrumentTypes, 330 q_instrumentTypes = q_instrumentTypes,
323 l_instrumentTypes = l_instrumentTypes, 331 l_instrumentTypes = l_instrumentTypes,
324 332
325 q_spectraFilter= q_spectraFilter, 333 q_spectraTypes = q_spectraTypes,
326 l_spectraFilter= l_spectraFilter, 334 l_spectraTypes = l_spectraTypes,
327 335
328 l_rtrange=c(l_rtrangeMin, l_rtrangeMax), 336 l_rtrange = c(l_rtrangeMin, l_rtrangeMax),
329 q_rtrange=c(q_rtrangeMin, q_rtrangeMax), 337 q_rtrange = c(q_rtrangeMin, q_rtrangeMax),
330 338
331 q_accessions = opt$q_accessions, 339 q_accessions = opt$q_accessions,
332 l_accessions= opt$l_accessions, 340 l_accessions = opt$l_accessions,
333 341
334 raW = opt$raW, 342 raW = opt$raW,
335 mzW = opt$mzW, 343 mzW = opt$mzW,
336 rttol=opt$rttol, 344 rttol = opt$rttol,
337 cores=opt$cores, 345 cores = opt$cores,
338 346
339 copyDb=copyDb, 347 copyDb = copyDb,
340 updateDb=updateDb, 348 updateDb = updateDb,
341 outPth = "db_with_spectral_matching.sqlite", 349 outPth = "db_with_spectral_matching.sqlite",
342 350
343 q_dbPth = q_dbPth, 351 q_dbPth = q_dbPth,
344 q_dbType = q_dbType, 352 q_dbType = q_dbType,
345 q_dbName = q_dbName, 353 q_dbName = q_dbName,
346 q_dbHost = q_dbHost, 354 q_dbHost = q_dbHost,
347 q_dbUser = q_dbUser, 355 q_dbUser = q_dbUser,
348 q_dbPass = q_dbPass, 356 q_dbPass = q_dbPass,
349 q_dbPort = q_dbPort, 357 q_dbPort = q_dbPort,
350 358
351 l_dbPth = l_dbPth, 359 l_dbPth = l_dbPth,
352 l_dbType = l_dbType, 360 l_dbType = l_dbType,
353 l_dbName = l_dbName, 361 l_dbName = l_dbName,
354 l_dbHost = l_dbHost, 362 l_dbHost = l_dbHost,
355 l_dbUser = l_dbUser, 363 l_dbUser = l_dbUser,
356 l_dbPass = l_dbPass, 364 l_dbPass = l_dbPass,
357 l_dbPort = l_dbPort 365 l_dbPort = l_dbPort
358 366
359 ) 367 )
360 368
361 sm <- addQueryNameColumn(sm) 369 sm <- addQueryNameColumn(sm)
362 # Get name of the query results (and merged with the data frames) 370 # Get name of the query results (and merged with the data frames)
363 write.table(sm$matchedResults, 'matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE) 371 write.table(sm$matchedResults, "matched_results.tsv", sep = "\t", row.names = FALSE, col.names = TRUE)
364 write.table(sm$xcmsMatchedResults, 'xcms_matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE) 372 write.table(sm$xcmsMatchedResults, "xcms_matched_results.tsv", sep = "\t", row.names = FALSE, col.names = TRUE)
365 373
366 if(updateDb){ 374 if (updateDb) {
367 updateDbF(q_con, l_con) 375 updateDbF(q_con, l_con)
368 } 376 }
369 } 377 }