comparison MsPeakForestDb.R @ 6:b8f70d8216b3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
author prog
date Mon, 27 Mar 2017 06:27:29 -0400
parents 18254e8d1b72
children
comparison
equal deleted inserted replaced
5:18254e8d1b72 6:b8f70d8216b3
1 if ( ! exists('MsPeakForestDb')) { # Do not load again if already loaded 1 if ( ! exists('MsPeakForestDb')) { # Do not load again if already loaded
2 2
3 library(methods) 3 library(methods)
4 source('MsDb.R') 4 source('MsDb.R')
5 source(file.path('UrlRequestScheduler.R')) 5 source('UrlRequestScheduler.R')
6 6
7 ##################### 7 #####################
8 # CLASS DECLARATION # 8 # CLASS DECLARATION #
9 ##################### 9 #####################
10 10
45 url <- paste(.self$.url, url, sep = '/') 45 url <- paste(.self$.url, url, sep = '/')
46 46
47 # Add token 47 # Add token
48 if ( ! is.na(.self$.token)) 48 if ( ! is.na(.self$.token))
49 params <- c(params, token = .self$.token) 49 params <- c(params, token = .self$.token)
50 param.str <- if (is.null(params)) '' else paste('?', vapply(names(params), function(p) paste(p, params[[p]], sep = '='), FUN.VALUE = ''), collapse = '&', sep = '')
51 50
52 # Get URL 51 # Get URL
53 content <- .self$.url.scheduler$getUrl(url = url, params = params) 52 content <- .self$.url.scheduler$getUrl(url = url, params = params)
54 53
55 if (ret.type == 'json') { 54 if (ret.type == 'json') {
285 if ( ! is.null(rt.low) && ! is.null(rt.high)) { 284 if ( ! is.null(rt.low) && ! is.null(rt.high)) {
286 285
287 rt.res <- data.frame(MSDB.TAG.MOLID = character(), MSDB.TAG.COL = character(), MSDB.TAG.COLRT = numeric()) 286 rt.res <- data.frame(MSDB.TAG.MOLID = character(), MSDB.TAG.COL = character(), MSDB.TAG.COLRT = numeric())
288 287
289 if (nrow(results) > 0) { 288 if (nrow(results) > 0) {
289
290 # Build URL for rt search 290 # Build URL for rt search
291 url <- paste0('spectra/lcms/range-rt-min/', rt.low, '/', rt.high) 291 url <- paste0('spectra/lcms/range-rt-min/', rt.low / 60, '/', rt.high / 60)
292 params <- NULL 292 params <- NULL
293 if ( ! is.null(col)) 293 if ( ! is.null(col))
294 params <- c(columns = paste(col, collapse = ',')) 294 params <- c(columns = paste(col, collapse = ','))
295 295
296 # Run query 296 # Run query
297 rtspectra <- .self$.get.url(url = url, params = params) 297 rtspectra <- .self$.get.url(url = url, params = params)
298
299 298
300 # Get compound/molecule IDs 299 # Get compound/molecule IDs
301 for (x in rtspectra) 300 for (x in rtspectra)
302 if (all(c('listOfCompounds', 'liquidChromatography') %in% names(x))) { 301 if (all(c('listOfCompounds', 'liquidChromatography') %in% names(x))) {
303 molids <- vapply(x$listOfCompounds, function(c) if ('id' %in% names(c) && ! is.null(c$id)) as.character(c$id) else NA_character_, FUN.VALUE = '') 302 molids <- vapply(x$listOfCompounds, function(c) if ('id' %in% names(c) && ! is.null(c$id)) as.character(c$id) else NA_character_, FUN.VALUE = '')
306 rtmin <- if ('RTmin' %in% names(x) && ! is.null(x$RTmin)) as.double(x$RTmin) else NA_real_ 305 rtmin <- if ('RTmin' %in% names(x) && ! is.null(x$RTmin)) as.double(x$RTmin) else NA_real_
307 rtmax <- if ('RTmax' %in% names(x) && ! is.null(x$RTmax)) as.double(x$RTmax) else NA_real_ 306 rtmax <- if ('RTmax' %in% names(x) && ! is.null(x$RTmax)) as.double(x$RTmax) else NA_real_
308 colrt <- (rtmin + rtmax) / 2 307 colrt <- (rtmin + rtmax) / 2
309 rt.res <- rbind(rt.res, data.frame(MSDB.TAG.MOLID = molids, 308 rt.res <- rbind(rt.res, data.frame(MSDB.TAG.MOLID = molids,
310 MSDB.TAG.COL = col, 309 MSDB.TAG.COL = col,
311 MSDB.TAG.COLRT = colrt, 310 MSDB.TAG.COLRT = colrt * 60,
312 stringsAsFactors = FALSE)) 311 stringsAsFactors = FALSE))
313 } 312 }
314 } 313 }
315 } 314 }
316 315