Mercurial > repos > prog > lcmsmatching
comparison BiodbEntry.R @ 1:253d531a0193 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 36c9d8099c20a1ae848f1337c16564335dd8fb2b
author | prog |
---|---|
date | Sat, 03 Sep 2016 17:02:01 -0400 |
parents | e66bb061af06 |
children | 20d69a062da3 |
comparison
equal
deleted
inserted
replaced
0:e66bb061af06 | 1:253d531a0193 |
---|---|
18 .factory <<- NULL | 18 .factory <<- NULL |
19 | 19 |
20 callSuper(...) # calls super-class initializer with remaining parameters | 20 callSuper(...) # calls super-class initializer with remaining parameters |
21 }) | 21 }) |
22 | 22 |
23 ############# | 23 ################### |
24 # SET FIELD # | 24 # SET FIELD VALUE # |
25 ############# | 25 ################### |
26 | 26 |
27 BiodbEntry$methods( setFieldValue = function(field, value) { | |
28 .self$setField(field, value) | |
29 }) | |
30 | |
27 BiodbEntry$methods( setField = function(field, value) { | 31 BiodbEntry$methods( setField = function(field, value) { |
28 | 32 |
29 class = .self$getFieldClass(field) | 33 class = .self$getFieldClass(field) |
30 | 34 |
31 # Check cardinality | 35 # Check cardinality |
32 if (class != 'data.frame' && .self$getFieldCardinality(field) == RBIODB.CARD.ONE && length(value) > 1) | 36 if (class != 'data.frame' && .self$getFieldCardinality(field) == BIODB.CARD.ONE && length(value) > 1) |
33 stop(paste0('Cannot set more that one value to single value field "', field, '" in BiodEntry.')) | 37 stop(paste0('Cannot set more that one value to single value field "', field, '" in BiodEntry.')) |
34 | 38 |
35 # Check value class | 39 # Check value class |
36 value <- switch(class, | 40 value <- switch(class, |
37 'character' = as.character(value), | 41 'character' = as.character(value), |
43 | 47 |
44 .self$.fields[[field]] <- value | 48 .self$.fields[[field]] <- value |
45 }) | 49 }) |
46 | 50 |
47 ################### | 51 ################### |
52 # GET FIELD NAMES # | |
53 ################### | |
54 | |
55 BiodbEntry$methods( getFieldNames = function(field) { | |
56 return(names(.self$.fields)) | |
57 }) | |
58 | |
59 ################### | |
48 # GET FIELD CLASS # | 60 # GET FIELD CLASS # |
49 ################### | 61 ################### |
50 | 62 |
51 BiodbEntry$methods( getFieldClass = function(field) { | 63 BiodbEntry$methods( getFieldClass = function(field) { |
52 | 64 |
53 if ( ! field %in% RBIODB.FIELDS[['name']]) | 65 if ( ! field %in% BIODB.FIELDS[['name']]) |
54 stop(paste0('Unknown field "', field, '" in BiodEntry.')) | 66 stop(paste0('Unknown field "', field, '" in BiodEntry.')) |
55 | 67 |
56 field.class <- RBIODB.FIELDS[which(field == RBIODB.FIELDS[['name']]), 'class'] | 68 field.class <- BIODB.FIELDS[which(field == BIODB.FIELDS[['name']]), 'class'] |
57 | 69 |
58 return(field.class) | 70 return(field.class) |
59 }) | 71 }) |
60 | 72 |
61 ######################### | 73 ######################### |
62 # GET FIELD CARDINALITY # | 74 # GET FIELD CARDINALITY # |
63 ######################### | 75 ######################### |
64 | 76 |
65 BiodbEntry$methods( getFieldCardinality = function(field) { | 77 BiodbEntry$methods( getFieldCardinality = function(field) { |
66 | 78 |
67 if ( ! field %in% RBIODB.FIELDS[['name']]) | 79 if ( ! field %in% BIODB.FIELDS[['name']]) |
68 stop(paste0('Unknown field "', field, '" in BiodEntry.')) | 80 stop(paste0('Unknown field "', field, '" in BiodEntry.')) |
69 | 81 |
70 field.card <- RBIODB.FIELDS[which(field == RBIODB.FIELDS[['name']]), 'cardinality'] | 82 field.card <- BIODB.FIELDS[which(field == BIODB.FIELDS[['name']]), 'cardinality'] |
71 | 83 |
72 return(field.card) | 84 return(field.card) |
73 }) | 85 }) |
74 | 86 |
75 ############# | 87 ################### |
76 # GET FIELD # | 88 # GET FIELD VALUE # |
77 ############# | 89 ################### |
78 | 90 |
91 BiodbEntry$methods( getFieldValue = function(field) { | |
92 return(.self$getField(field)) | |
93 }) | |
94 | |
79 BiodbEntry$methods( getField = function(field) { | 95 BiodbEntry$methods( getField = function(field) { |
80 | 96 |
81 if ( ! field %in% RBIODB.FIELDS[['name']]) | 97 if ( ! field %in% BIODB.FIELDS[['name']]) |
82 stop(paste0('Unknown field "', field, '" in BiodEntry.')) | 98 stop(paste0('Unknown field "', field, '" in BiodEntry.')) |
83 | 99 |
84 if (field %in% names(.self$.fields)) | 100 if (field %in% names(.self$.fields)) |
85 return(.self$.fields[[field]]) | 101 return(.self$.fields[[field]]) |
86 else if (.self$.compute.field(field)) | 102 else if (.self$.compute.field(field)) |
95 # COMPUTE FIELD # | 111 # COMPUTE FIELD # |
96 ################## | 112 ################## |
97 | 113 |
98 BiodbEntry$methods( .compute.field = function(field) { | 114 BiodbEntry$methods( .compute.field = function(field) { |
99 | 115 |
100 if ( ! is.null(.self$.factory) && field %in% names(RBIODB.FIELD.COMPUTING)) { | 116 if ( ! is.null(.self$.factory) && field %in% names(BIODB.FIELD.COMPUTING)) { |
101 for (db in RBIODB.FIELD.COMPUTING[[field]]) { | 117 for (db in BIODB.FIELD.COMPUTING[[field]]) { |
102 db.id <- .self$getField(paste0(db, 'id')) | 118 db.id <- .self$getField(paste0(db, 'id')) |
103 if ( ! is.na(db.id)) { | 119 if ( ! is.na(db.id)) { |
104 db.compound <- .self$.factory$createEntry(db, type = RBIODB.COMPOUND, id = db.id) | 120 db.compound <- .self$.factory$createEntry(db, type = BIODB.COMPOUND, id = db.id) |
105 if ( ! is.null(db.compound)) { | 121 if ( ! is.null(db.compound)) { |
106 .self$setField(field, db.compound$getField(field)) | 122 .self$setField(field, db.compound$getField(field)) |
107 return(TRUE) | 123 return(TRUE) |
108 } | 124 } |
109 } | 125 } |
110 } | 126 } |
111 } | 127 } |
112 | 128 |
113 return(FALSE) | 129 return(FALSE) |
130 }) | |
131 | |
132 ############################ | |
133 # GET FIELDS AS DATA FRAME # | |
134 ############################ | |
135 | |
136 BiodbEntry$methods( getFieldsAsDataFrame = function(field) { | |
137 | |
138 df <- data.frame() | |
139 | |
140 # Loop on all fields | |
141 for (f in names(.self$.fields)) | |
142 | |
143 # If field class is a basic type | |
144 if (.self$getFieldClass(f) %in% c('character', 'logical', 'integer', 'double')) | |
145 df[1, f] <- .self$getFieldValue(f) | |
146 | |
147 return(df) | |
114 }) | 148 }) |
115 | 149 |
116 ########### | 150 ########### |
117 # FACTORY # | 151 # FACTORY # |
118 ########### | 152 ########### |