view MsDbInputDataFrameStream.R @ 0:e66bb061af06 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 3529b25417f8e1a5836474c9adec4b696d35099d-dirty
author prog
date Tue, 12 Jul 2016 12:02:37 -0400
parents
children 20d69a062da3
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))
	})

} # end of load safe guard