Mercurial > repos > prog > lcmsmatching
comparison BiodbConn.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 |
---|---|
1 if ( ! exists('BiodbConn')) { # Do not load again if already loaded | 1 if ( ! exists('BiodbConn')) { |
2 | 2 |
3 source(file.path('UrlRequestScheduler.R'), chdir = TRUE) | |
4 source('biodb-common.R') | 3 source('biodb-common.R') |
5 | 4 |
6 ##################### | 5 ##################### |
7 # CLASS DECLARATION # | 6 # CLASS DECLARATION # |
8 ##################### | 7 ##################### |
9 | 8 |
10 BiodbConn <- setRefClass("BiodbConn", fields = list(.scheduler = "UrlRequestScheduler")) | 9 BiodbConn <- setRefClass("BiodbConn", fields = list( .debug = "logical" )) |
11 | 10 |
12 ############### | 11 ############### |
13 # CONSTRUCTOR # | 12 # CONSTRUCTOR # |
14 ############### | 13 ############### |
15 | 14 |
16 BiodbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, ...) { | 15 BiodbConn$methods( initialize = function(debug = FALSE, ...) { |
16 .debug <<- debug | |
17 }) | |
17 | 18 |
18 # Check useragent | 19 ####################### |
19 ! is.null(useragent) && ! is.na(useragent) || stop("You must specify a valid useragent.") | 20 # PRINT DEBUG MESSAGE # |
21 ####################### | |
20 | 22 |
21 # Set scheduler | 23 BiodbConn$methods( .print.debug.msg = function(msg) { |
22 if (is.null(scheduler)) | 24 if (.self$.debug) |
23 scheduler <- UrlRequestScheduler$new(n = 3) | 25 .print.msg(msg = msg, class = class(.self)) |
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 }) | 26 }) |
30 | 27 |
31 ###################### | 28 ###################### |
32 # HANDLES ENTRY TYPE # | 29 # HANDLES ENTRY TYPE # |
33 ###################### | 30 ###################### |
34 | 31 |
35 BiodbConn$methods( handlesEntryType = function(type) { | 32 BiodbConn$methods( handlesEntryType = function(type) { |
57 # GET ENTRY CONTENT # | 54 # GET ENTRY CONTENT # |
58 ##################### | 55 ##################### |
59 | 56 |
60 # Download entry content from the public database. | 57 # Download entry content from the public database. |
61 # type The entry type. | 58 # type The entry type. |
62 # id The ID of the enttry to get. | 59 # id The ID of the entry to get. |
63 # RETURN An entry content downloaded from database. | 60 # RETURN An entry content downloaded from database. |
64 BiodbConn$methods( getEntryContent = function(type, id) { | 61 BiodbConn$methods( getEntryContent = function(type, id) { |
65 stop("Method getCompound() is not implemented in concrete class.") | 62 stop("Method getCompound() is not implemented in concrete class.") |
66 }) | 63 }) |
67 | 64 |
73 # content A file content, downloaded from the public database. | 70 # content A file content, downloaded from the public database. |
74 # RETURN A compound instance. | 71 # RETURN A compound instance. |
75 BiodbConn$methods( createEntry = function(type, content, drop = TRUE) { | 72 BiodbConn$methods( createEntry = function(type, content, drop = TRUE) { |
76 stop("Method createEntry() is not implemented in concrete class.") | 73 stop("Method createEntry() is not implemented in concrete class.") |
77 }) | 74 }) |
75 | |
76 ################# | |
77 # GET ENTRY IDS # | |
78 ################# | |
79 | |
80 # Get a list of IDs of all entries contained in this database. | |
81 BiodbConn$methods( getEntryIds = function(type) { | |
82 stop("Method getEntryIds() is not implemented in concrete class.") | |
83 }) | |
84 | |
85 ################## | |
86 # GET NB ENTRIES # | |
87 ################## | |
88 | |
89 # Get the number of entries contained in this database. | |
90 BiodbConn$methods( getNbEntries = function(type) { | |
91 stop("Method getNbEntries() is not implemented in concrete class.") | |
92 }) | |
78 } | 93 } |