Mercurial > repos > prog > lcmsmatching
diff 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 |
line wrap: on
line diff
--- a/BiodbEntry.R Tue Jul 12 12:02:37 2016 -0400 +++ b/BiodbEntry.R Sat Sep 03 17:02:01 2016 -0400 @@ -20,16 +20,20 @@ callSuper(...) # calls super-class initializer with remaining parameters }) - ############# - # SET FIELD # - ############# + ################### + # SET FIELD VALUE # + ################### + BiodbEntry$methods( setFieldValue = function(field, value) { + .self$setField(field, value) + }) + BiodbEntry$methods( setField = function(field, value) { class = .self$getFieldClass(field) # Check cardinality - if (class != 'data.frame' && .self$getFieldCardinality(field) == RBIODB.CARD.ONE && length(value) > 1) + if (class != 'data.frame' && .self$getFieldCardinality(field) == BIODB.CARD.ONE && length(value) > 1) stop(paste0('Cannot set more that one value to single value field "', field, '" in BiodEntry.')) # Check value class @@ -45,15 +49,23 @@ }) ################### + # GET FIELD NAMES # + ################### + + BiodbEntry$methods( getFieldNames = function(field) { + return(names(.self$.fields)) + }) + + ################### # GET FIELD CLASS # ################### - + BiodbEntry$methods( getFieldClass = function(field) { - if ( ! field %in% RBIODB.FIELDS[['name']]) + if ( ! field %in% BIODB.FIELDS[['name']]) stop(paste0('Unknown field "', field, '" in BiodEntry.')) - field.class <- RBIODB.FIELDS[which(field == RBIODB.FIELDS[['name']]), 'class'] + field.class <- BIODB.FIELDS[which(field == BIODB.FIELDS[['name']]), 'class'] return(field.class) }) @@ -64,21 +76,25 @@ BiodbEntry$methods( getFieldCardinality = function(field) { - if ( ! field %in% RBIODB.FIELDS[['name']]) + if ( ! field %in% BIODB.FIELDS[['name']]) stop(paste0('Unknown field "', field, '" in BiodEntry.')) - field.card <- RBIODB.FIELDS[which(field == RBIODB.FIELDS[['name']]), 'cardinality'] + field.card <- BIODB.FIELDS[which(field == BIODB.FIELDS[['name']]), 'cardinality'] return(field.card) }) - ############# - # GET FIELD # - ############# + ################### + # GET FIELD VALUE # + ################### + BiodbEntry$methods( getFieldValue = function(field) { + return(.self$getField(field)) + }) + BiodbEntry$methods( getField = function(field) { - if ( ! field %in% RBIODB.FIELDS[['name']]) + if ( ! field %in% BIODB.FIELDS[['name']]) stop(paste0('Unknown field "', field, '" in BiodEntry.')) if (field %in% names(.self$.fields)) @@ -97,11 +113,11 @@ BiodbEntry$methods( .compute.field = function(field) { - if ( ! is.null(.self$.factory) && field %in% names(RBIODB.FIELD.COMPUTING)) { - for (db in RBIODB.FIELD.COMPUTING[[field]]) { + if ( ! is.null(.self$.factory) && field %in% names(BIODB.FIELD.COMPUTING)) { + for (db in BIODB.FIELD.COMPUTING[[field]]) { db.id <- .self$getField(paste0(db, 'id')) if ( ! is.na(db.id)) { - db.compound <- .self$.factory$createEntry(db, type = RBIODB.COMPOUND, id = db.id) + db.compound <- .self$.factory$createEntry(db, type = BIODB.COMPOUND, id = db.id) if ( ! is.null(db.compound)) { .self$setField(field, db.compound$getField(field)) return(TRUE) @@ -112,6 +128,24 @@ return(FALSE) }) + + ############################ + # GET FIELDS AS DATA FRAME # + ############################ + + BiodbEntry$methods( getFieldsAsDataFrame = function(field) { + + df <- data.frame() + + # Loop on all fields + for (f in names(.self$.fields)) + + # If field class is a basic type + if (.self$getFieldClass(f) %in% c('character', 'logical', 'integer', 'double')) + df[1, f] <- .self$getFieldValue(f) + + return(df) + }) ########### # FACTORY #