Module: OLS
- Defined in:
- lib/ols.rb,
lib/ols/term.rb,
lib/ols/cache.rb,
lib/ols/graph.rb,
lib/ols/version.rb
Overview
Simple wrapper for interacting with the OLS (Ontology Lookup Service - www.ebi.ac.uk/ontology-lookup/) database (created and managed by the EBI).
Defined Under Namespace
Classes: Cache, Graph, Term, TermNotFoundError
Constant Summary collapse
- VERSION =
OLS::VERSION - The OLS gem version
"0.3.4"
Class Attribute Summary collapse
-
.log ⇒ Object
writeonly
Set whether to log HTTP requests - pass in
true
orfalse
. -
.log_level ⇒ Object
Return the log level.
-
.logger ⇒ Object
Returns the logger.
-
.proxy ⇒ Object
Returns a HTTP proxy url.
Class Method Summary collapse
-
.add_ontology_to_cache(ontology) ⇒ Object
(also: refresh_ontology_in_cache)
Add an ontology to the cache.
-
.cached_ontologies ⇒ Array
Returns a list of the cached ontologies.
-
.client ⇒ Object
Returns the raw (Savon) SOAP client for the OLS webservice.
-
.find_by_id(term_id) ⇒ OLS::Term
Fetch an ontology term (OLS::Term) by its id.
-
.log? ⇒ Boolean
Returns whether to log HTTP/SOAP requests.
-
.ontologies ⇒ Hash
Fetch a hash of all ontologies in the OLS service, keyed by their short-name.
-
.remove_ontology_from_cache(ontology) ⇒ Object
Remove an ontology from the cache.
-
.request(method, &block) ⇒ Hash
Generic request method to allow simple access to all the OLS webservice end-points (provided by Savon).
-
.root_terms(ontology) ⇒ Array
Fetch all the root terms for a given ontology.
-
.setup_cache(options = {}) ⇒ Object
Configure the OLS gem to use a local cache.
-
.using_cache? ⇒ Boolean
Are we using a local cache? Defaults to
false
. -
.version ⇒ String
Fetch the version string for the current build of OLS.
Class Attribute Details
.log=(value) ⇒ Object (writeonly)
Set whether to log HTTP requests - pass in true
or false
103 104 105 |
# File 'lib/ols.rb', line 103 def log=(value) @log = value end |
.log_level ⇒ Object
Return the log level. Defaults to :warn
122 123 124 |
# File 'lib/ols.rb', line 122 def log_level @log_level ||= :warn end |
.logger ⇒ Object
Returns the logger. Defaults to an instance of Logger
writing to STDOUT
114 115 116 |
# File 'lib/ols.rb', line 114 def logger @logger ||= ::Logger.new STDOUT end |
.proxy ⇒ Object
Returns a HTTP proxy url. Will read the http_proxy
environment variable if present
130 131 132 |
# File 'lib/ols.rb', line 130 def proxy @proxy ||= ( ENV['http_proxy'] || ENV['HTTP_PROXY'] ) end |
Class Method Details
.add_ontology_to_cache(ontology) ⇒ Object Also known as: refresh_ontology_in_cache
Add an ontology to the cache.
169 170 171 |
# File 'lib/ols.rb', line 169 def add_ontology_to_cache(ontology) @cache.add_ontology_to_cache(ontology) end |
.cached_ontologies ⇒ Array
Returns a list of the cached ontologies.
160 161 162 |
# File 'lib/ols.rb', line 160 def cached_ontologies @cache.cached_ontologies end |
.client ⇒ Object
Returns the raw (Savon) SOAP client for the OLS webservice
17 18 19 20 |
# File 'lib/ols.rb', line 17 def client @client = setup_soap_client if @client.nil? @client end |
.find_by_id(term_id) ⇒ OLS::Term
Fetch an ontology term (OLS::Term) by its id
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ols.rb', line 88 def find_by_id(term_id) term = nil term = @cache.find_by_id(term_id) if using_cache? if term.nil? term_name = request(:get_term_by_id) { soap.body = { :termId => term_id } } raise TermNotFoundError if term_name.eql?(term_id) term = OLS::Term.new(term_id,term_name) end term end |
.log? ⇒ Boolean
Returns whether to log HTTP/SOAP requests. Defaults to false
106 107 108 |
# File 'lib/ols.rb', line 106 def log? @log ? true : false end |
.ontologies ⇒ Hash
Fetch a hash of all ontologies in the OLS service, keyed by their short-name
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ols.rb', line 48 def ontologies @ontologies ||= {} if @ontologies.empty? response = request :get_ontology_names response[:item].each do |ont| @ontologies[ont[:key]] = ont[:value] end end @ontologies end |
.remove_ontology_from_cache(ontology) ⇒ Object
Remove an ontology from the cache.
180 181 182 |
# File 'lib/ols.rb', line 180 def remove_ontology_from_cache(ontology) @cache.remove_ontology_from_cache(ontology) end |
.request(method, &block) ⇒ Hash
Generic request method to allow simple access to all the OLS webservice end-points (provided by Savon)
28 29 30 31 32 33 34 35 36 |
# File 'lib/ols.rb', line 28 def request(method,&block) response = nil if block response = self.client.request(method,&block) else response = self.client.request method end response.body[:"#{method}_response"][:"#{method}_return"] end |
.root_terms(ontology) ⇒ Array
Fetch all the root terms for a given ontology
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ols.rb', line 63 def root_terms(ontology) root_terms = [] root_terms = @cache.root_terms(ontology) if using_cache? if root_terms.empty? response = request(:get_root_terms) { soap.body = { :ontologyName => ontology } } if response[:item].is_a? Array response[:item].each do |term| root_terms.push( OLS::Term.new(term[:key],term[:value]) ) end else term = response[:item] root_terms.push( OLS::Term.new(term[:key],term[:value]) ) end end root_terms end |
.setup_cache(options = {}) ⇒ Object
Configure the OLS gem to use a local cache. Useful if you have some serious ontology activity going on, or you want to insulate yourself from server outages and the like.
NOTE: We only support a file-based (on-disk) cache at the moment. By default it will look in/use the current working directory, or you can pass a configuration hash as follows:
OLS.setup_cache({ :directory => '/path/to/cache_directory' })
Support for other cache backends will come in future builds.
152 153 154 |
# File 'lib/ols.rb', line 152 def setup_cache(={}) @cache = OLS::Cache.new() end |
.using_cache? ⇒ Boolean
Are we using a local cache? Defaults to false
.
137 138 139 |
# File 'lib/ols.rb', line 137 def using_cache? @cache ? true : false end |
.version ⇒ String
Fetch the version string for the current build of OLS
41 42 43 |
# File 'lib/ols.rb', line 41 def version request :get_version end |