Mercurial > repos > prog > lcmsmatching
comparison MsFileDb.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 |
---|---|
82 if (is.null(.self$.db)) { | 82 if (is.null(.self$.db)) { |
83 | 83 |
84 # Load database | 84 # Load database |
85 .db <<- read.table(.self$.file, sep = "\t", quote = "\"", header = TRUE, stringsAsFactors = FALSE, row.names = NULL) | 85 .db <<- read.table(.self$.file, sep = "\t", quote = "\"", header = TRUE, stringsAsFactors = FALSE, row.names = NULL) |
86 | 86 |
87 # Check that colnames are unique | |
88 dupcol <- duplicated(colnames(.self$.db)) | |
89 if (any(dupcol)) | |
90 stop(paste("Database header contains duplicated names: ", paste(unique(colnames(.self$.db)[dupcol]), collapse = ', '), ".")) | |
91 | |
92 # Check that columns names supplied through field map are unique | |
93 dupfields <- duplicated(.self$.fields) | |
94 if (any(dupfields)) | |
95 stop(paste("Some db column names supplied are duplicated: ", paste(unique(.self$.fields[dupfields]), collapse = ', '), ".")) | |
96 | |
87 # Rename columns | 97 # Rename columns |
88 colnames(.self$.db) <- vapply(colnames(.self$.db), function(c) if (c %in% .self$.fields) names(.self$.fields)[.self$.fields %in% c] else c, FUN.VALUE = '') | 98 colnames(.self$.db) <- vapply(colnames(.self$.db), function(c) if (c %in% .self$.fields) names(.self$.fields)[.self$.fields %in% c] else c, FUN.VALUE = '') |
89 } | 99 } |
90 }) | 100 }) |
91 | 101 |
149 | 159 |
150 #################### | 160 #################### |
151 # GET MOLECULE IDS # | 161 # GET MOLECULE IDS # |
152 #################### | 162 #################### |
153 | 163 |
154 MsFileDb$methods( getMoleculeIds = function() { | 164 MsFileDb$methods( getMoleculeIds = function(max.results = NA_integer_) { |
155 | 165 |
156 # Init db | 166 # Init db |
157 .self$.init.db() | 167 .self$.init.db() |
158 | 168 |
159 # Get IDs | 169 # Get IDs |
160 mol.ids <- as.character(.self$.get.col(MSDB.TAG.MOLID)) | 170 mol.ids <- as.character(.self$.get.col(MSDB.TAG.MOLID)) |
161 mol.ids <- mol.ids[ ! duplicated(mol.ids)] | 171 mol.ids <- mol.ids[ ! duplicated(mol.ids)] |
162 mol.ids <- sort(mol.ids) | 172 mol.ids <- sort(mol.ids) |
173 | |
174 # Cut results | |
175 if ( ! is.na(max.results) && length(mol.ids) > max.results) | |
176 mol.ids <- mol.ids[1:max.results] | |
163 | 177 |
164 return(mol.ids) | 178 return(mol.ids) |
165 }) | 179 }) |
166 | 180 |
167 #################### | 181 #################### |
414 ################# | 428 ################# |
415 # GET MZ VALUES # | 429 # GET MZ VALUES # |
416 ################# | 430 ################# |
417 | 431 |
418 # Returns a numeric vector of all masses stored inside the database. | 432 # Returns a numeric vector of all masses stored inside the database. |
419 MsFileDb$methods( getMzValues = function(mode = NULL) { | 433 MsFileDb$methods( getMzValues = function(mode = NULL, max.results = NA_integer_) { |
420 | 434 |
421 # Init db | 435 # Init db |
422 .self$.init.db() | 436 .self$.init.db() |
423 db <- .self$.db | 437 db <- .self$.db |
424 | 438 |
432 # Get masses | 446 # Get masses |
433 mz <- .self$.get(db, col = MSDB.TAG.MZTHEO) | 447 mz <- .self$.get(db, col = MSDB.TAG.MZTHEO) |
434 | 448 |
435 # Remove duplicates | 449 # Remove duplicates |
436 mz <- mz[ ! duplicated(mz)] | 450 mz <- mz[ ! duplicated(mz)] |
451 | |
452 # Apply cut-off | |
453 if ( ! is.na(max.results)) | |
454 mz <- mz[1:max.results] | |
437 | 455 |
438 return(mz) | 456 return(mz) |
439 }) | 457 }) |
440 | 458 |
441 ####################### | 459 ####################### |