view MsDbInputDataFrameStream.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
line wrap: on
line source

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

	library(methods)
	source('MsDbInputStream.R')

	#####################
	# CLASS DECLARATION #
	#####################
	
	MsDbInputDataFrameStream <- setRefClass("MsDbInputDataFrameStream", contains = 'MsDbInputStream', fields = list( .df = "ANY", .i = "integer"))
	
	###############
	# CONSTRUCTOR #
	###############
	
	MsDbInputDataFrameStream$methods( initialize = function(df = data.frame(), input.fields = msdb.get.dft.input.fields(), ...) {

		.df <<- df
		.i <<- 0L
		
		callSuper(input.fields = input.fields, ...)
	})

	##########
	# GET MZ #
	##########

	MsDbInputDataFrameStream$methods( getMz = function() {

		if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.MZ]]))
			return(.self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.MZ]]])

		return(NULL)
	})

	##########
	# GET RT #
	##########

	MsDbInputDataFrameStream$methods( getRt = function() {

		if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.RT]]))
			return(.self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.RT]]])

		return(NULL)
	})

	###########
	# GET ALL #
	###########

	MsDbInputDataFrameStream$methods( getAll = function(but = NULL) {

		if (.self$.i > 0 && .self$.i <= nrow(.self$.df)) {

			vals <- .self$.df[.self$.i, , drop = FALSE]

			if ( ! is.null(but))
				vals <- vals[, ! colnames(vals) %in% .self$.input.fields[but], drop = FALSE]

			return(vals)
		}

		return(NULL)
	})

	###############
	# NEXT VALUES #
	###############

	MsDbInputDataFrameStream$methods( nextValues = function() {

		if (.self$.i <= nrow(.self$.df))
			.i <<- .self$.i + 1L
	})

	###################
	# HAS NEXT VALUES #
	###################

	MsDbInputDataFrameStream$methods( hasNextValues = function() {
		return(.self$.i < nrow(.self$.df))
	})

	#########
	# RESET #
	#########

	MsDbInputDataFrameStream$methods( reset = function() {
		.i <<- 0L
	})

} # end of load safe guard