diff MsDbOutputDataFrameStream.R @ 1:45e985cd8e9e draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8-dirty
author prog
date Tue, 31 Jan 2017 05:27:24 -0500
parents 3afe41d3e9e7
children b8f70d8216b3
line wrap: on
line diff
--- a/MsDbOutputDataFrameStream.R	Mon Jul 11 09:12:03 2016 -0400
+++ b/MsDbOutputDataFrameStream.R	Tue Jan 31 05:27:24 2017 -0500
@@ -1,7 +1,6 @@
 if ( ! exists('MsDbOutputDataFrameStream')) { # Do not load again if already loaded
 
 	library(methods)
-	library(plyr)
 	source('MsDbOutputStream.R')
 	source('dfhlp.R', chdir = TRUE)
 
@@ -26,7 +25,7 @@
 	# GET DATA FRAME #
 	##################
 	
-	MsDbOutputDataFrameStream$methods( getDataFrame = function(...) {
+	MsDbOutputDataFrameStream$methods( getDataFrame = function() {
 
 		# Put at least a column name if empty
 		if (nrow(.self$.df) == 0)
@@ -35,16 +34,31 @@
 		return(.self$.df)
 	})
 	
+	# Move columns to beginning {{{1
+	
+	MsDbOutputDataFrameStream$methods( moveColumnsToBeginning = function(cols) {
+		all.cols <- colnames(.self$.df)
+		other.cols <- all.cols[ ! all.cols %in% cols]
+		cols <- cols[cols %in% all.cols]
+		.df <<- .self$.df[c(cols, other.cols)]
+	})
+
 	#################
 	# MATCHED PEAKS #
 	#################
 	
 	MsDbOutputDataFrameStream$methods( matchedPeaks = function(mz, rt = NULL, unused = NULL, peaks = NULL) {
 
+		library(plyr)
+
 		# Set input values
 		x <- data.frame(mz = mz)
-		if ( ! is.null(rt))
-			x <- cbind(x, data.frame(rt = rt))
+		colnames(x) <- MSDB.TAG.MZ
+		if ( ! is.null(rt)) {
+			x.rt <- data.frame(rt = rt)
+			colnames(x.rt) <- MSDB.TAG.RT
+			x <- cbind(x, x.rt)
+		}
 
 		# Merge input values with matched peaks
 		if ( ! is.null(peaks)) {
@@ -73,8 +87,12 @@
 				# Concatenate results in one line
 				if (.self$.one.line) {
  					# For each column, concatenate all values in one string.
-					for (c in seq(peaks))
-						peaks[1, c] <- paste0(peaks[[c]], collapse = .self$.match.sep, FUN.VALUE = '')
+					for (c in seq(peaks)) {
+						v <- peaks[[c]]
+						v <- v[ ! is.na(v)] # remove NA values
+						v <- v[ ! duplicated(v)] # remove duplicates
+						peaks[1, c] <- paste0(v, collapse = .self$.match.sep, FUN.VALUE = '')
+					}
 					peaks <- peaks[1, ] # Keep only first line
 				}
 			}