view MsBioDb.R @ 5:fb9c0409d85c draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 608d9e59a0d2dcf85a037968ddb2c61137fb9bce
author prog
date Wed, 19 Apr 2017 10:00:05 -0400
parents 20d69a062da3
children
line wrap: on
line source

if ( ! exists('MsBioDb')) { # Do not load again if already loaded

	library(methods)
	source('MsDb.R')
	source('BiodbObject.R', chdir = TRUE)
	source('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))
	})

}