comparison MsDbOutputDataFrameStream.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 253d531a0193
children fb9c0409d85c
comparison
equal deleted inserted replaced
1:253d531a0193 2:20d69a062da3
23 23
24 ################## 24 ##################
25 # GET DATA FRAME # 25 # GET DATA FRAME #
26 ################## 26 ##################
27 27
28 MsDbOutputDataFrameStream$methods( getDataFrame = function(...) { 28 MsDbOutputDataFrameStream$methods( getDataFrame = function() {
29 29
30 # Put at least a column name if empty 30 # Put at least a column name if empty
31 if (nrow(.self$.df) == 0) 31 if (nrow(.self$.df) == 0)
32 .self$.df[[.self$.output.fields[[MSDB.TAG.MZ]]]] <- numeric() 32 .self$.df[[.self$.output.fields[[MSDB.TAG.MZ]]]] <- numeric()
33 33
34 return(.self$.df) 34 return(.self$.df)
35 }) 35 })
36 36
37 # Move columns to beginning {{{1
38
39 MsDbOutputDataFrameStream$methods( moveColumnsToBeginning = function(cols) {
40 all.cols <- colnames(.self$.df)
41 other.cols <- all.cols[ ! all.cols %in% cols]
42 cols <- cols[cols %in% all.cols]
43 .df <<- .self$.df[c(cols, other.cols)]
44 })
45
37 ################# 46 #################
38 # MATCHED PEAKS # 47 # MATCHED PEAKS #
39 ################# 48 #################
40 49
41 MsDbOutputDataFrameStream$methods( matchedPeaks = function(mz, rt = NULL, unused = NULL, peaks = NULL) { 50 MsDbOutputDataFrameStream$methods( matchedPeaks = function(mz, rt = NULL, unused = NULL, peaks = NULL) {
42 51
43 library(plyr) 52 library(plyr)
44 53
45 # Set input values 54 # Set input values
46 x <- data.frame(mz = mz) 55 x <- data.frame(mz = mz)
47 if ( ! is.null(rt)) 56 colnames(x) <- MSDB.TAG.MZ
48 x <- cbind(x, data.frame(rt = rt)) 57 if ( ! is.null(rt)) {
58 x.rt <- data.frame(rt = rt)
59 colnames(x.rt) <- MSDB.TAG.RT
60 x <- cbind(x, x.rt)
61 }
49 62
50 # Merge input values with matched peaks 63 # Merge input values with matched peaks
51 if ( ! is.null(peaks)) { 64 if ( ! is.null(peaks)) {
52 65
53 # No rows 66 # No rows
72 } 85 }
73 86
74 # Concatenate results in one line 87 # Concatenate results in one line
75 if (.self$.one.line) { 88 if (.self$.one.line) {
76 # For each column, concatenate all values in one string. 89 # For each column, concatenate all values in one string.
77 for (c in seq(peaks)) 90 for (c in seq(peaks)) {
78 peaks[1, c] <- paste0(peaks[[c]], collapse = .self$.match.sep, FUN.VALUE = '') 91 v <- peaks[[c]]
92 v <- v[ ! is.na(v)] # remove NA values
93 v <- v[ ! duplicated(v)] # remove duplicates
94 peaks[1, c] <- paste0(v, collapse = .self$.match.sep, FUN.VALUE = '')
95 }
79 peaks <- peaks[1, ] # Keep only first line 96 peaks <- peaks[1, ] # Keep only first line
80 } 97 }
81 } 98 }
82 99
83 # Merge 100 # Merge