Mercurial > repos > prog > lcmsmatching
comparison MsDbInputDataFrameStream.R @ 6:f86fec07f392 draft default tip
planemo upload commit c397cd8a93953798d733fd62653f7098caac30ce
author | prog |
---|---|
date | Fri, 22 Feb 2019 16:04:22 -0500 |
parents | fb9c0409d85c |
children |
comparison
equal
deleted
inserted
replaced
5:fb9c0409d85c | 6:f86fec07f392 |
---|---|
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", .rtunit = 'character')) | |
11 | |
12 ############### | |
13 # CONSTRUCTOR # | |
14 ############### | |
15 | |
16 MsDbInputDataFrameStream$methods( initialize = function(df = data.frame(), input.fields = msdb.get.dft.input.fields(), rtunit = MSDB.RTUNIT.SEC, ...) { | |
17 | |
18 callSuper(input.fields = input.fields, ...) | |
19 | |
20 .df <<- df | |
21 .i <<- 0L | |
22 .rtunit <<- rtunit | |
23 }) | |
24 | |
25 ########## | |
26 # GET MZ # | |
27 ########## | |
28 | |
29 MsDbInputDataFrameStream$methods( getMz = function() { | |
30 | |
31 if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.MZ]])) | |
32 return(.self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.MZ]]]) | |
33 | |
34 return(NULL) | |
35 }) | |
36 | |
37 ########## | |
38 # GET RT # | |
39 ########## | |
40 | |
41 MsDbInputDataFrameStream$methods( getRt = function() { | |
42 | |
43 rt <- NULL | |
44 | |
45 if (.self$.i > 0 && .self$.i <= nrow(.self$.df) && ! is.null(.self$.input.fields[[MSDB.TAG.RT]])) { | |
46 rt <- .self$.df[.self$.i, .self$.input.fields[[MSDB.TAG.RT]]] | |
47 if (.self$.rtunit == MSDB.RTUNIT.MIN) | |
48 rt <- rt * 60 | |
49 } | |
50 | |
51 return(rt) | |
52 }) | |
53 | |
54 ########### | |
55 # GET ALL # | |
56 ########### | |
57 | |
58 MsDbInputDataFrameStream$methods( getAll = function(but = NULL) { | |
59 | |
60 if (.self$.i > 0 && .self$.i <= nrow(.self$.df)) { | |
61 | |
62 vals <- .self$.df[.self$.i, , drop = FALSE] | |
63 | |
64 if ( ! is.null(but)) | |
65 vals <- vals[, ! colnames(vals) %in% .self$.input.fields[but], drop = FALSE] | |
66 | |
67 return(vals) | |
68 } | |
69 | |
70 return(NULL) | |
71 }) | |
72 | |
73 ############### | |
74 # NEXT VALUES # | |
75 ############### | |
76 | |
77 MsDbInputDataFrameStream$methods( nextValues = function() { | |
78 | |
79 if (.self$.i <= nrow(.self$.df)) | |
80 .i <<- .self$.i + 1L | |
81 }) | |
82 | |
83 ################### | |
84 # HAS NEXT VALUES # | |
85 ################### | |
86 | |
87 MsDbInputDataFrameStream$methods( hasNextValues = function() { | |
88 return(.self$.i < nrow(.self$.df)) | |
89 }) | |
90 | |
91 ######### | |
92 # RESET # | |
93 ######### | |
94 | |
95 MsDbInputDataFrameStream$methods( reset = function() { | |
96 .i <<- 0L | |
97 }) | |
98 | |
99 } # end of load safe guard |