bioportal 2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/BSD-LICENSE +23 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +30 -0
  7. data/README.rdoc +11 -0
  8. data/Rakefile +24 -0
  9. data/app/helpers/bio_portal_helper.rb +17 -0
  10. data/app/models/bioportal_concept.rb +39 -0
  11. data/app/views/bioportal/_bioportal_visualise.html.erb +2 -0
  12. data/bioportal.gemspec +11 -0
  13. data/generators/bioportal_migration/USAGE +8 -0
  14. data/generators/bioportal_migration/bioportal_migration_generator.rb +7 -0
  15. data/generators/bioportal_migration/templates/migration.rb +16 -0
  16. data/install.rb +1 -0
  17. data/lib/bioportal.rb +178 -0
  18. data/lib/bioportal/engine.rb +5 -0
  19. data/lib/tasks/bioportal_tasks.rake +4 -0
  20. data/rdoc/classes/BioPortal.html +112 -0
  21. data/rdoc/classes/BioPortal/Acts.html +148 -0
  22. data/rdoc/classes/BioPortal/Acts/ClassMethods.html +160 -0
  23. data/rdoc/classes/BioPortal/Acts/InstanceMethods.html +325 -0
  24. data/rdoc/classes/BioPortal/Acts/SingletonMethods.html +105 -0
  25. data/rdoc/classes/BioPortal/RestAPI.html +489 -0
  26. data/rdoc/classes/BioPortalHelper.html +334 -0
  27. data/rdoc/classes/BioportalConcept.html +251 -0
  28. data/rdoc/created.rid +1 -0
  29. data/rdoc/files/BSD-LICENSE.html +134 -0
  30. data/rdoc/files/README.html +213 -0
  31. data/rdoc/files/app/helpers/bio_portal_helper_rb.html +108 -0
  32. data/rdoc/files/app/models/bioportal_concept_rb.html +101 -0
  33. data/rdoc/files/lib/bioportal_rb.html +112 -0
  34. data/rdoc/fr_class_index.html +34 -0
  35. data/rdoc/fr_file_index.html +31 -0
  36. data/rdoc/fr_method_index.html +53 -0
  37. data/rdoc/index.html +24 -0
  38. data/rdoc/rdoc-style.css +208 -0
  39. data/test/bioportal_test.rb +60 -0
  40. data/test/test_helper.rb +18 -0
  41. data/uninstall.rb +1 -0
  42. metadata +84 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b0961441bb3fba35541487be496d53e94520771
4
+ data.tar.gz: 2132cb61672cac93d978479222e120e952c48609
5
+ SHA512:
6
+ metadata.gz: 2bc35cbc513e07023c8ed63fd46c79de75d1085be2a0a2d5f7b37327ae03a37dda01aca472e57d988bb1e1d01a136f0da0a20ee6ebe08ae1984cdf48b62f00a9
7
+ data.tar.gz: b46d595cfd2b4e125389da7616c6b69abd453eb40f23ef62e28be31f6abda1add61795e0d92594a113840f3e95ea0ddcb8efbe710ad1120f68fff1ed3c422781
@@ -0,0 +1,3 @@
1
+ *~
2
+ test/bioportal_api_key
3
+ .idea/
@@ -0,0 +1 @@
1
+ bioportal-gem
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2014, University of Manchester & HITS gGmbH
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
8
+ and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the University of Manchester or EML Research gGmbH,
12
+ nor the names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+
4
+ gem "rails","2.3.17",:group=>:test
5
+ gem "test-unit",:group=>:test
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.17)
5
+ actionpack (= 2.3.17)
6
+ actionpack (2.3.17)
7
+ activesupport (= 2.3.17)
8
+ rack (~> 1.1.0)
9
+ activerecord (2.3.17)
10
+ activesupport (= 2.3.17)
11
+ activeresource (2.3.17)
12
+ activesupport (= 2.3.17)
13
+ activesupport (2.3.17)
14
+ rack (1.1.6)
15
+ rails (2.3.17)
16
+ actionmailer (= 2.3.17)
17
+ actionpack (= 2.3.17)
18
+ activerecord (= 2.3.17)
19
+ activeresource (= 2.3.17)
20
+ activesupport (= 2.3.17)
21
+ rake (>= 0.8.3)
22
+ rake (10.1.1)
23
+ test-unit (2.5.5)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ rails (= 2.3.17)
30
+ test-unit
@@ -0,0 +1,11 @@
1
+ = Bioportal Gem
2
+
3
+ A simple Gem for using the Bioportal API.
4
+
5
+ This version was a cut-back implementation of a previous version that used the old BioPortal API. It was cut-back just to support
6
+ the needs of the Seek for Science project - http://seek4science.org
7
+
8
+ It supports simple searching and fetching details about a class in an ontology.
9
+
10
+
11
+
@@ -0,0 +1,24 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the bioportal plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the bioportal plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Bioportal Plugin'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('BSD-LICENSE')
23
+ rdoc.rdoc_files.include(['lib/**/*.rb','app/**/*.rb'])
24
+ end
@@ -0,0 +1,17 @@
1
+
2
+
3
+ module BioPortalHelper
4
+
5
+ def visualise_ontology model,options={}
6
+ options[:show_concept]||=false
7
+ concept_id=nil
8
+ concept_id=model.concept_uri if options[:show_concept] && !model.concept_uri.nil?
9
+ ontology_id ||= model.ontology_id
10
+ apikey=options[:apikey]
11
+ render(:partial=>"bioportal/bioportal_visualise",:locals=>{:ontology_id=>ontology_id,:concept_id=>concept_id,:apikey=>apikey})
12
+ end
13
+
14
+
15
+
16
+ end
17
+
@@ -0,0 +1,39 @@
1
+ class BioportalConcept < ActiveRecord::Base
2
+ include BioPortal::RestAPI
3
+
4
+ belongs_to :conceptable,:polymorphic=>true
5
+
6
+ before_save :check_cached_concept
7
+
8
+ def get_concept options={}
9
+ options[:refresh]||=false
10
+
11
+ refresh=options.delete(:refresh)
12
+
13
+ concept=nil
14
+ concept = YAML::load(cached_concept_yaml) unless (refresh || cached_concept_yaml.nil?)
15
+ unless concept
16
+ concept = super(self.ontology_id,self.concept_uri,options)
17
+ update_attribute(:cached_concept_yaml, concept.to_yaml)
18
+ end
19
+
20
+ concept
21
+ end
22
+
23
+
24
+ #the base url is defined by the associated class - this overrides the method in the RestAPI mixin
25
+ def bioportal_base_rest_url
26
+ conceptable.bioportal_base_rest_url
27
+ end
28
+
29
+ protected
30
+
31
+ #invoked before_save, and if the ontology_id, ontology_version_id or concept_uri has changed then the cached concept will be cleared
32
+ def check_cached_concept
33
+ changed_fields = changes.keys
34
+
35
+ if !(changed_fields & ["ontology_id","concept_uri"]).empty?
36
+ self.cached_concept_yaml=nil
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,2 @@
1
+
2
+ <iframe id="bioportal_visualisation" frameborder="0" src="http://bioportal.bioontology.org/widgets/visualization?ontology=<%=ontology_id%>&class=<%=URI.escape(concept_id,":/")%>&apikey=<%=apikey%>"></iframe>
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bioportal'
3
+ s.version = '2.1'
4
+ s.date = '2014-03-20'
5
+ s.summary = "Supports linking of Models within a RoR application to a Concept and Ontology within the BioPortal"
6
+ s.authors = ["Stuart Owen","Quyen Nguyen"]
7
+ s.email = 'nttqa22001@yahoo.com'
8
+ s.files = `git ls-files`.split("\n")
9
+ s.homepage = 'https://github.com/SysMO-DB/bioportal'
10
+ s.require_paths = ["lib"]
11
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ ./script/generate bioportal Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,7 @@
1
+ class BioportalMigrationGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "bioportal_concept_migration"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ class BioportalConceptMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :bioportal_concepts do |t|
4
+ t.column :ontology_id, :integer
5
+ t.column :ontology_version_id,:integer
6
+ t.column :concept_uri,:string
7
+ t.column :cached_concept_yaml,:text
8
+ t.column :conceptable_id,:integer
9
+ t.column :conceptable_type,:string
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :bioportal_concepts
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,178 @@
1
+ require 'pp'
2
+ module BioPortal
3
+
4
+ require 'bioportal/engine' if defined?(Rails)
5
+
6
+ module Acts
7
+ def self.included(mod)
8
+ mod.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def linked_to_bioportal(options = {}, &extension)
13
+ options[:base_url]||="http://data.bioontology.org"
14
+
15
+ has_one :bioportal_concept,:as=>:conceptable,:dependent=>:destroy
16
+ before_save :save_changed_concept
17
+ cattr_accessor :bioportal_base_rest_url, :bioportal_api_key
18
+
19
+ self.bioportal_base_rest_url=options[:base_url]
20
+ self.bioportal_api_key=options[:apikey]
21
+
22
+
23
+ extend BioPortal::Acts::SingletonMethods
24
+ include BioPortal::Acts::InstanceMethods
25
+ end
26
+ end
27
+
28
+ module SingletonMethods
29
+
30
+ end
31
+
32
+ module InstanceMethods
33
+
34
+ def concept options={}
35
+
36
+ options[:apikey] ||= self.bioportal_api_key unless self.bioportal_api_key.nil?
37
+
38
+ return nil if self.bioportal_concept.nil?
39
+ begin
40
+ return self.bioportal_concept.get_concept options
41
+ rescue Exception=>e
42
+ return nil
43
+ end
44
+ end
45
+
46
+ def ncbi_uri
47
+ concept_uri
48
+ end
49
+
50
+ def ncbi_id
51
+ unless ncbi_uri.nil?
52
+ id = ncbi_uri.split("/").last.split("_").last
53
+ id.to_i
54
+ else
55
+ nil
56
+ end
57
+ end
58
+
59
+
60
+ def ontology_id
61
+ return nil if self.bioportal_concept.nil?
62
+ return self.bioportal_concept.ontology_id
63
+ end
64
+
65
+
66
+ def concept_uri
67
+ return nil if self.bioportal_concept.nil?
68
+ return self.bioportal_concept.concept_uri
69
+ end
70
+
71
+ def ontology_id= value
72
+ check_concept
73
+ self.bioportal_concept.ontology_id=value
74
+ end
75
+
76
+
77
+ def concept_uri= value
78
+ check_concept
79
+ self.bioportal_concept.concept_uri=value
80
+ end
81
+
82
+ private
83
+
84
+ def check_concept
85
+ self.bioportal_concept=BioportalConcept.new if self.bioportal_concept.nil?
86
+ end
87
+
88
+ def save_changed_concept
89
+ self.bioportal_concept.save! if !self.bioportal_concept.nil? && self.bioportal_concept.changed?
90
+ end
91
+
92
+ end
93
+ end
94
+
95
+
96
+ module RestAPI
97
+ require 'rubygems'
98
+ require 'open-uri'
99
+ require 'uri'
100
+
101
+
102
+
103
+ def get_concept ontology_acronym,class_id,options={}
104
+ url = "/ontologies/#{ontology_acronym}/classes/#{URI.escape(class_id,":/")}?"
105
+ options.keys.each{|key| url += "#{key.to_s}=#{URI.encode(options[key].to_s)}&"}
106
+ url=bioportal_base_rest_url+url
107
+ json = fetch_json(url)
108
+ concept={}
109
+ concept[:label]=json["prefLabel"]
110
+ concept[:synonyms]=json["synonym"]
111
+ concept[:definitions]=json["definition"]
112
+ concept
113
+ end
114
+
115
+
116
+ def search query,options={}
117
+ options[:pagesize] ||= 10
118
+ options[:page] ||= 1
119
+
120
+ search_url="/search?q=%QUERY%&"
121
+ options.keys.each {|key| search_url+="#{key.to_s}=#{URI.encode(options[key].to_s)}&"}
122
+ search_url=search_url[0..-2] #chop of trailing &
123
+
124
+ search_url=search_url.gsub("%QUERY%",URI.encode(query))
125
+ full_search_path=bioportal_base_rest_url+search_url
126
+
127
+ json = fetch_json(full_search_path)
128
+
129
+ results = json["collection"].collect do |item|
130
+ res = {}
131
+ res[:ontology_link]=item["links"]["ontology"]
132
+ res[:class_link]=item["links"]["self"]
133
+ res[:preferred_label]=item["prefLabel"]
134
+ res[:synonyms]=item["synonym"] || []
135
+ res[:class_id]=item["@id"]
136
+ populate_ontology_details res,options
137
+ res
138
+ end
139
+ pages = json["pageCount"]
140
+
141
+ return results.uniq,pages.to_i
142
+ end
143
+
144
+ def populate_ontology_details search_result, options
145
+ apikey = options[:apikey]
146
+ link = search_result[:ontology_link]
147
+ link = link+"?apikey=#{apikey}"
148
+ json = fetch_json(link)
149
+
150
+ search_result[:ontology_name]=json["name"]
151
+ search_result[:ontology_acronym]=json["acronym"]
152
+ end
153
+
154
+ def fetch_json link
155
+ @@bioportal_json ||={}
156
+ json = @@bioportal_json[link]
157
+ if json.nil?
158
+ json = JSON.parse(open(link).read)
159
+ @@bioportal_json[link]=json
160
+ end
161
+ json
162
+ end
163
+
164
+
165
+ private
166
+
167
+ DEFAULT_REST_URL = "http://data.bioontology.org"
168
+
169
+ def bioportal_base_rest_url
170
+ DEFAULT_REST_URL
171
+ end
172
+
173
+ end
174
+
175
+ end
176
+
177
+ ActiveRecord::Base.send(:include,BioPortal::Acts)
178
+
@@ -0,0 +1,5 @@
1
+ module BioPortal
2
+ class Engine < ::Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bioportal do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,112 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: BioPortal</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">BioPortal</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/bioportal_rb.html">
59
+ lib/bioportal.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+
80
+ </div>
81
+
82
+
83
+ <!-- if includes -->
84
+
85
+ <div id="section">
86
+
87
+ <div id="class-list">
88
+ <h3 class="section-bar">Classes and Modules</h3>
89
+
90
+ Module <a href="BioPortal/Acts.html" class="link">BioPortal::Acts</a><br />
91
+ Module <a href="BioPortal/RestAPI.html" class="link">BioPortal::RestAPI</a><br />
92
+
93
+ </div>
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ <!-- if method_list -->
102
+
103
+
104
+ </div>
105
+
106
+
107
+ <div id="validator-badges">
108
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
109
+ </div>
110
+
111
+ </body>
112
+ </html>