Mercurial > repos > prog > lcmsmatching
comparison BiodbConn.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 | 253d531a0193 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e66bb061af06 |
|---|---|
| 1 if ( ! exists('BiodbConn')) { # Do not load again if already loaded | |
| 2 | |
| 3 source(file.path('UrlRequestScheduler.R'), chdir = TRUE) | |
| 4 source('biodb-common.R') | |
| 5 | |
| 6 ##################### | |
| 7 # CLASS DECLARATION # | |
| 8 ##################### | |
| 9 | |
| 10 BiodbConn <- setRefClass("BiodbConn", fields = list(.scheduler = "UrlRequestScheduler")) | |
| 11 | |
| 12 ############### | |
| 13 # CONSTRUCTOR # | |
| 14 ############### | |
| 15 | |
| 16 BiodbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, ...) { | |
| 17 | |
| 18 # Check useragent | |
| 19 ! is.null(useragent) && ! is.na(useragent) || stop("You must specify a valid useragent.") | |
| 20 | |
| 21 # Set scheduler | |
| 22 if (is.null(scheduler)) | |
| 23 scheduler <- UrlRequestScheduler$new(n = 3) | |
| 24 inherits(scheduler, "UrlRequestScheduler") || stop("The scheduler instance must inherit from UrlRequestScheduler class.") | |
| 25 scheduler$setUserAgent(useragent) # set agent | |
| 26 .scheduler <<- scheduler | |
| 27 | |
| 28 callSuper(...) # calls super-class initializer with remaining parameters | |
| 29 }) | |
| 30 | |
| 31 ###################### | |
| 32 # HANDLES ENTRY TYPE # | |
| 33 ###################### | |
| 34 | |
| 35 BiodbConn$methods( handlesEntryType = function(type) { | |
| 36 return( ! is.null(.self$getEntryContentType(type))) | |
| 37 }) | |
| 38 | |
| 39 ########################## | |
| 40 # GET ENTRY CONTENT TYPE # | |
| 41 ########################## | |
| 42 | |
| 43 BiodbConn$methods( getEntryContentType = function(type) { | |
| 44 stop("Method getEntryContentType() is not implemented in concrete class.") | |
| 45 }) | |
| 46 | |
| 47 ############# | |
| 48 # GET ENTRY # | |
| 49 ############# | |
| 50 | |
| 51 BiodbConn$methods( getEntry = function(type, id, drop = TRUE) { | |
| 52 content <- .self$getEntryContent(type, id) | |
| 53 return(.self$createEntry(type, content, drop = drop)) | |
| 54 }) | |
| 55 | |
| 56 ##################### | |
| 57 # GET ENTRY CONTENT # | |
| 58 ##################### | |
| 59 | |
| 60 # Download entry content from the public database. | |
| 61 # type The entry type. | |
| 62 # id The ID of the enttry to get. | |
| 63 # RETURN An entry content downloaded from database. | |
| 64 BiodbConn$methods( getEntryContent = function(type, id) { | |
| 65 stop("Method getCompound() is not implemented in concrete class.") | |
| 66 }) | |
| 67 | |
| 68 ############################# | |
| 69 # CREATE ENTRY FROM CONTENT # | |
| 70 ############################# | |
| 71 | |
| 72 # Creates a Compound instance from file content. | |
| 73 # content A file content, downloaded from the public database. | |
| 74 # RETURN A compound instance. | |
| 75 BiodbConn$methods( createEntry = function(type, content, drop = TRUE) { | |
| 76 stop("Method createEntry() is not implemented in concrete class.") | |
| 77 }) | |
| 78 } |
