Mercurial > repos > prog > lcmsmatching
diff MsBioDb.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 | |
children | fb9c0409d85c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MsBioDb.R Thu Mar 02 08:55:00 2017 -0500 @@ -0,0 +1,100 @@ +if ( ! exists('MsBioDb')) { # Do not load again if already loaded + + library(methods) + source('MsDb.R') + source(file.path('BiodbObject.R'), chdir = TRUE) + source(file.path('BiodbFactory.R'), chdir = TRUE) + + ##################### + # CLASS DECLARATION # + ##################### + + MsBioDb <- setRefClass("MsBioDb", contains = "MsDb", fields = list(.massdb = "ANY")) + + ############### + # CONSTRUCTOR # + ############### + + MsBioDb$methods( initialize = function(massdb = NULL, ...) { + + # Check bio database + ! is.null(massdb) || stop("You must set a bio database.") + inherits(massdb, "MassdbConn") || stop("The bio database must inherit from MassdbConn class.") + .massdb <<- massdb + + callSuper(...) + }) + + #################### + # HANDLE COMPOUNDS # + #################### + + MsBioDb$methods( handleCompounds = function() { + return(.self$.massdb$handlesEntryType(BIODB.COMPOUND)) + }) + + #################### + # GET MOLECULE IDS # + #################### + + MsBioDb$methods( getMoleculeIds = function(max.results = NA_integer_) { + return(.self$.massdb$getEntryIds(type = BIODB.COMPOUND, max.results = max.results)) + }) + + #################### + # GET NB MOLECULES # + #################### + + MsBioDb$methods( getNbMolecules = function() { + return(.self$.massdb$getNbEntries(type = BIODB.COMPOUND)) + }) + + ################# + # GET MZ VALUES # + ################# + + MsBioDb$methods( getMzValues = function(mode = NULL, max.results = NA_integer_) { + return(.self$.massdb$getMzValues(mode = mode, max.results = max.results)) + }) + + ##################### + # GET MOLECULE NAME # + ##################### + + MsBioDb$methods( getMoleculeName = function(molid) { + return(.self$.massdb$getMoleculeName(molid)) + }) + + ############################### + # GET CHROMATOGRAPHIC COLUMNS # + ############################### + + MsBioDb$methods( getChromCol = function(molid = NULL) { + return(.self$.massdb$getChromCol(molid)) + }) + + ################ + # FIND BY NAME # + ################ + + MsBioDb$methods( findByName = function(name) { + return(.self$.massdb$findCompoundByName(name)) + }) + + ####################### + # GET RETENTION TIMES # + ####################### + + MsBioDb$methods( getRetentionTimes = function(molid, col = NA_character_) { + return(.self$.massdb$getRetentionTimes(molid, chrom.cols = col)) + }) + + ################ + # GET NB PEAKS # + ################ + + MsBioDb$methods( getNbPeaks = function(molid = NA_integer_, mode = NA_character_) { + return(.self$.massdb$getNbPeaks(compound.ids = molid, mode = mode)) + }) + +}