comparison MsXlsDb.R @ 2:20d69a062da3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author prog
date Thu, 02 Mar 2017 08:55:00 -0500
parents e66bb061af06
children fb9c0409d85c
comparison
equal deleted inserted replaced
1:253d531a0193 2:20d69a062da3
37 ############### 37 ###############
38 38
39 MsXlsDb$methods( initialize = function(db_dir = NA_character_, limit = NA_integer_, cache_dir = NA_character_, cache = FALSE, ...) { 39 MsXlsDb$methods( initialize = function(db_dir = NA_character_, limit = NA_integer_, cache_dir = NA_character_, cache = FALSE, ...) {
40 40
41 # Initialize members 41 # Initialize members
42 # TODO check that db_dir is not null neither na, and tests that it exists and is a directory.
42 .db_dir <<- if ( ! is.null(db_dir)) db_dir else NA_character_ 43 .db_dir <<- if ( ! is.null(db_dir)) db_dir else NA_character_
43 .limit <<- if ( ! is.null(limit) && ! is.na(limit) && limit > 0) limit else NA_integer_ 44 .limit <<- if ( ! is.null(limit) && ! is.na(limit) && limit > 0) limit else NA_integer_
44 cache_dir <- if (cache && is.na(cache_dir) && ! is.na(db_dir)) file.path(db_dir, 'cache') else cache_dir 45 cache_dir <- if (cache && is.na(cache_dir) && ! is.na(db_dir)) file.path(db_dir, 'cache') else cache_dir
45 .cache_dir <<- if ( cache || ! is.null(cache_dir)) cache_dir else NA_character_ 46 .cache_dir <<- if ( cache || ! is.null(cache_dir)) cache_dir else NA_character_
46 .files <<- NULL 47 .files <<- NULL
281 ################# 282 #################
282 # GET MZ VALUES # 283 # GET MZ VALUES #
283 ################# 284 #################
284 285
285 # Returns a numeric vector of all masses stored inside the database. 286 # Returns a numeric vector of all masses stored inside the database.
286 MsXlsDb$methods( getMzValues = function(mode = NULL) { 287 MsXlsDb$methods( getMzValues = function(mode = NULL, max.results = NA_integer_) {
287 288
288 mz <- numeric() 289 mz <- numeric()
289 290
290 # Get all mz values of all molecules 291 # Get all mz values of all molecules
291 for(molid in .self$getMoleculeIds()) 292 for(molid in .self$getMoleculeIds())
292 for (m in (if (is.null(mode) || is.na(mode)) c(MSDB.TAG.POS, MSDB.TAG.NEG) else mode)) 293 for (m in (if (is.null(mode) || is.na(mode)) c(MSDB.TAG.POS, MSDB.TAG.NEG) else mode))
293 mz <- c(mz, .self$.get.peaks(molid, m)[[MSDB.TAG.MZTHEO]]) 294 mz <- c(mz, .self$.get.peaks(molid, m)[[MSDB.TAG.MZTHEO]])
294 295
295 # Remove duplicated 296 # Remove duplicated
296 mz <- mz[ ! duplicated(mz)] 297 mz <- mz[ ! duplicated(mz)]
298
299 # Apply cut-off
300 if ( ! is.na(max.results))
301 mz <- mz[1:max.results]
297 302
298 return(mz) 303 return(mz)
299 }) 304 })
300 305
301 ############# 306 #############