Mercurial > repos > prog > lcmsmatching
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e66bb061af06 |
---|---|
1 if ( ! exists('MsDbInputDataFrameStream')) { # Do not load again if already loaded | |
2 | |
3 library(methods) | |
4 source('MsDbInputStream.R') | |
5 | |
6 ##################### | |
7 # CLASS DECLARATION # | |
8 ##################### | |
9 | |
10 MsDbInputDataFrameStream <- setRefClass("MsDbInputDataFrameStream", contains = 'MsDbInputStream', fields = list( .df = "ANY", .i = "integer")) | |
11 | |
12 ############### | |
13 # CONSTRUCTOR # | |
14 ############### | |
15 | |
16 MsDbInputDataFrameStream$methods( initialize = function(df = data.frame(), input.fields = msdb.get.dft.input.fields(), ...) { | |
17 | |
18 .df <<- df | |
19 .i <<- 0L | |
20 | |
21 callSuper(input.fields = input.fields, ...) | |
22 }) | |
23 | |
24 ########## | |
25 # GET MZ # | |
26 ########## | |
27 | |
28 MsDbInputDataFrameStream$methods( getMz = function() { | |
29 | |
30 if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.MZ]])) | |
31 return(.self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.MZ]]]) | |
32 | |
33 return(NULL) | |
34 }) | |
35 | |
36 ########## | |
37 # GET RT # | |
38 ########## | |
39 | |
40 MsDbInputDataFrameStream$methods( getRt = function() { | |
41 | |
42 if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.RT]])) | |
43 return(.self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.RT]]]) | |
44 | |
45 return(NULL) | |
46 }) | |
47 | |
48 ########### | |
49 # GET ALL # | |
50 ########### | |
51 | |
52 MsDbInputDataFrameStream$methods( getAll = function(but = NULL) { | |
53 | |
54 if (.self$.i > 0 && .self$.i <= nrow(.self$.df)) { | |
55 | |
56 vals <- .self$.df[.self$.i, , drop = FALSE] | |
57 | |
58 if ( ! is.null(but)) | |
59 vals <- vals[, ! colnames(vals) %in% .self$.input.fields[but], drop = FALSE] | |
60 | |
61 return(vals) | |
62 } | |
63 | |
64 return(NULL) | |
65 }) | |
66 | |
67 ############### | |
68 # NEXT VALUES # | |
69 ############### | |
70 | |
71 MsDbInputDataFrameStream$methods( nextValues = function() { | |
72 | |
73 if (.self$.i <= nrow(.self$.df)) | |
74 .i <<- .self$.i + 1L | |
75 }) | |
76 | |
77 ################### | |
78 # HAS NEXT VALUES # | |
79 ################### | |
80 | |
81 MsDbInputDataFrameStream$methods( hasNextValues = function() { | |
82 return(.self$.i < nrow(.self$.df)) | |
83 }) | |
84 | |
85 } # end of load safe guard |