openbel-api 0.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gemspec +65 -0
  3. data/CHANGELOG.md +22 -0
  4. data/INSTALL.md +19 -0
  5. data/INSTALL_RUBY.md +107 -0
  6. data/LICENSE +191 -0
  7. data/README.md +208 -0
  8. data/app/openbel/api/app.rb +83 -0
  9. data/app/openbel/api/config.rb +45 -0
  10. data/app/openbel/api/config.ru +3 -0
  11. data/app/openbel/api/helpers/pager.rb +109 -0
  12. data/app/openbel/api/middleware/auth.rb +112 -0
  13. data/app/openbel/api/resources/adapters/basic_json.rb +52 -0
  14. data/app/openbel/api/resources/annotation.rb +141 -0
  15. data/app/openbel/api/resources/base.rb +16 -0
  16. data/app/openbel/api/resources/completion.rb +89 -0
  17. data/app/openbel/api/resources/evidence.rb +115 -0
  18. data/app/openbel/api/resources/evidence_transform.rb +143 -0
  19. data/app/openbel/api/resources/function.rb +98 -0
  20. data/app/openbel/api/resources/match_result.rb +79 -0
  21. data/app/openbel/api/resources/namespace.rb +174 -0
  22. data/app/openbel/api/routes/annotations.rb +168 -0
  23. data/app/openbel/api/routes/authenticate.rb +108 -0
  24. data/app/openbel/api/routes/base.rb +326 -0
  25. data/app/openbel/api/routes/datasets.rb +519 -0
  26. data/app/openbel/api/routes/evidence.rb +330 -0
  27. data/app/openbel/api/routes/expressions.rb +560 -0
  28. data/app/openbel/api/routes/functions.rb +41 -0
  29. data/app/openbel/api/routes/namespaces.rb +382 -0
  30. data/app/openbel/api/routes/root.rb +39 -0
  31. data/app/openbel/api/schemas.rb +34 -0
  32. data/app/openbel/api/schemas/annotation_collection.schema.json +20 -0
  33. data/app/openbel/api/schemas/annotation_resource.schema.json +36 -0
  34. data/app/openbel/api/schemas/annotation_value_collection.schema.json +21 -0
  35. data/app/openbel/api/schemas/annotation_value_resource.schema.json +35 -0
  36. data/app/openbel/api/schemas/completion_collection.schema.json +21 -0
  37. data/app/openbel/api/schemas/completion_resource.schema.json +146 -0
  38. data/app/openbel/api/schemas/evidence.schema.json +198 -0
  39. data/app/openbel/api/schemas/evidence_collection.schema.json +98 -0
  40. data/app/openbel/api/schemas/evidence_resource.schema.json +29 -0
  41. data/app/openbel/api/schemas/namespace_value_collection.schema.json +21 -0
  42. data/app/openbel/api/schemas/namespace_value_resource.schema.json +43 -0
  43. data/app/openbel/api/util.rb +11 -0
  44. data/bin/openbel-api +78 -0
  45. data/bin/openbel-config +46 -0
  46. data/config/async_evidence.rb +12 -0
  47. data/config/async_jena.rb +14 -0
  48. data/config/config.yml +31 -0
  49. data/config/server_config.rb +184 -0
  50. data/lib/openbel/api/cache/cache.rb +30 -0
  51. data/lib/openbel/api/config/config.rb +33 -0
  52. data/lib/openbel/api/evidence/api.rb +39 -0
  53. data/lib/openbel/api/evidence/facet_api.rb +18 -0
  54. data/lib/openbel/api/evidence/facet_filter.rb +83 -0
  55. data/lib/openbel/api/evidence/mongo.rb +247 -0
  56. data/lib/openbel/api/evidence/mongo_facet.rb +105 -0
  57. data/lib/openbel/api/helpers/dependency_graph.rb +52 -0
  58. data/lib/openbel/api/model/rdf_resource.rb +74 -0
  59. data/lib/openbel/api/plugin/cache/kyotocabinet.rb +85 -0
  60. data/lib/openbel/api/plugin/configure_plugins.rb +97 -0
  61. data/lib/openbel/api/plugin/evidence/evidence.rb +58 -0
  62. data/lib/openbel/api/plugin/plugin.rb +99 -0
  63. data/lib/openbel/api/plugin/plugin_manager.rb +20 -0
  64. data/lib/openbel/api/plugin/plugin_repository.rb +60 -0
  65. data/lib/openbel/api/storage/cache_proxy.rb +74 -0
  66. data/lib/openbel/api/storage/triple_storage.rb +43 -0
  67. metadata +379 -0
@@ -0,0 +1,16 @@
1
+ require 'oat'
2
+ require 'oat/adapters/hal'
3
+ require_relative 'adapters/basic_json'
4
+
5
+ class BaseSerializer < Oat::Serializer
6
+
7
+ protected
8
+
9
+ def url
10
+ context[:url]
11
+ end
12
+
13
+ def base_url
14
+ context[:base_url]
15
+ end
16
+ end
@@ -0,0 +1,89 @@
1
+ require_relative 'base'
2
+
3
+ module OpenBEL
4
+ module Resource
5
+ module Expressions
6
+
7
+ class CompletionSerializer < BaseSerializer
8
+ adapter Oat::Adapters::HAL
9
+ schema do
10
+ type :completion
11
+ property :type, item[:type]
12
+ property :label, item[:label]
13
+ property :value, item[:value]
14
+ property :highlight, item[:highlight]
15
+ property :actions, item[:actions]
16
+ property :id, item[:id]
17
+ end
18
+ end
19
+
20
+ class CompletionResourceSerializer < BaseSerializer
21
+ adapter Oat::Adapters::HAL
22
+ schema do
23
+ type :completion
24
+ properties do |p|
25
+ p.completion item
26
+ end
27
+
28
+ link :self, link_self(item[:id])
29
+ link :describedby, link_described_by(item[:type], item[:id])
30
+ end
31
+
32
+ private
33
+
34
+ def link_self(id)
35
+ {
36
+ :type => 'completion',
37
+ :href => "#{base_url}/api/expressions/#{id}/completions"
38
+ }
39
+ end
40
+
41
+ def link_described_by(type, id)
42
+ case type
43
+ when :function
44
+ {
45
+ :type => 'function',
46
+ :href => "#{base_url}/api/functions/#{id}"
47
+ }
48
+ when :namespace_prefix
49
+ {
50
+ :type => 'namespace_prefix',
51
+ :href => "#{base_url}/api/namespaces/#{id}"
52
+ }
53
+ when :namespace_value
54
+ {
55
+ :type => 'namespace_value',
56
+ :href => "#{base_url}/api/namespaces/hgnc/#{id}"
57
+ }
58
+ else
59
+ raise NotImplementedError.new("Unexpected resource type, #{type}")
60
+ end
61
+ end
62
+ end
63
+
64
+ class CompletionCollectionSerializer < BaseSerializer
65
+ adapter Oat::Adapters::HAL
66
+
67
+ schema do
68
+ type :completion_collection
69
+ properties do |p|
70
+ p.completion_collection item
71
+ end
72
+
73
+ link :self, link_self
74
+ end
75
+
76
+ private
77
+
78
+ def link_self
79
+ bel = context[:bel]
80
+ caret_position = context[:caret_position]
81
+ {
82
+ :type => :completion_collection,
83
+ :href => "#{base_url}/api/expressions/#{bel}/completions?caret_position=#{caret_position}"
84
+ }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,115 @@
1
+ require 'bel'
2
+ require_relative 'base'
3
+
4
+ module OpenBEL
5
+ module Resource
6
+ module Evidence
7
+
8
+ class EvidenceSerializer < BaseSerializer
9
+ adapter Oat::Adapters::HAL
10
+
11
+ schema do
12
+ type :evidence
13
+ property :bel_statement, item['bel_statement']
14
+ property :citation, item['citation']
15
+ property :summary_text, item['summary_text']
16
+ property :experiment_context, item['experiment_context']
17
+ property :metadata, item['metadata']
18
+ property :id, item['_id']
19
+ end
20
+ end
21
+
22
+ class EvidenceResourceSerializer < BaseSerializer
23
+ adapter Oat::Adapters::HAL
24
+
25
+ schema do
26
+ type :evidence
27
+ properties do |p|
28
+ p.evidence item
29
+ end
30
+
31
+ link :self, link_self
32
+ link :collection, link_collection
33
+ end
34
+
35
+ private
36
+
37
+ def link_self
38
+ id = item[:id] || context[:_id]
39
+ item.delete(:id)
40
+ {
41
+ :type => :evidence,
42
+ :href => "#{base_url}/api/evidence/#{id}"
43
+ }
44
+ end
45
+
46
+ def link_collection
47
+ {
48
+ :type => :evidence_collection,
49
+ :href => "#{base_url}/api/evidence"
50
+ }
51
+ end
52
+ end
53
+
54
+ class EvidenceCollectionSerializer < BaseSerializer
55
+ adapter Oat::Adapters::HAL
56
+
57
+ schema do
58
+ type :evidence_collection
59
+ property :evidence_collection, item
60
+ property :facets, context[:facets]
61
+ property :metadata, context[:metadata]
62
+ link :self, link_self
63
+ link :start, link_start
64
+ link :previous, link_previous
65
+ link :next, link_next
66
+ end
67
+
68
+ private
69
+
70
+ def link_self
71
+ start = context[:start]
72
+ size = context[:size]
73
+ {
74
+ :type => :evidence_collection,
75
+ :href => "#{base_url}/api/evidence?start=#{start}&size=#{size}&#{filter_query_params.join('&')}"
76
+ }
77
+ end
78
+
79
+ def link_start
80
+ size = context[:size]
81
+ {
82
+ :type => :evidence_collection,
83
+ :href => "#{base_url}/api/evidence?start=0&size=#{size}&#{filter_query_params.join('&')}"
84
+ }
85
+ end
86
+
87
+ def link_previous
88
+ previous_page = context[:previous_page]
89
+ return {} unless previous_page
90
+
91
+ {
92
+ :type => :evidence_collection,
93
+ :href => "#{base_url}/api/evidence?start=#{previous_page.start_offset}&size=#{previous_page.page_size}&#{filter_query_params.join('&')}"
94
+ }
95
+ end
96
+
97
+ def link_next
98
+ next_page = context[:next_page]
99
+ return {} unless next_page
100
+
101
+ {
102
+ :type => :evidence_collection,
103
+ :href => "#{base_url}/api/evidence?start=#{next_page.start_offset}&size=#{next_page.page_size}&#{filter_query_params.join('&')}"
104
+ }
105
+ end
106
+
107
+ def filter_query_params
108
+ context[:filters].map { |filter|
109
+ "filter=#{filter}"
110
+ }
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,143 @@
1
+ require 'bel'
2
+
3
+ module OpenBEL
4
+ module Resource
5
+ module Evidence
6
+
7
+ class AnnotationTransform
8
+
9
+ SERVER_PATTERN = %r{/api/annotations/([^/]*)/values/([^/]*)/?}
10
+ RDFURI_PATTERN = %r{/bel/namespace/([^/]*)/([^/]*)/?}
11
+ URI_PATTERNS = [
12
+ %r{/api/annotations/([^/]*)/values/([^/]*)/?},
13
+ %r{/bel/namespace/([^/]*)/([^/]*)/?}
14
+ ]
15
+ ANNOTATION_VALUE_URI = "%s/api/annotations/%s/values/%s"
16
+
17
+ def initialize(annotations)
18
+ @annotations = annotations
19
+ end
20
+
21
+ def transform_evidence!(evidence, base_url)
22
+ if evidence
23
+ experiment_context = evidence.experiment_context
24
+ if experiment_context != nil
25
+ experiment_context.values.map! { |annotation|
26
+ transform_annotation(annotation, base_url)
27
+ }
28
+ end
29
+ end
30
+ end
31
+
32
+ def transform_annotation(annotation, base_url)
33
+ if annotation[:uri]
34
+ transformed = transform_uri(annotation[:uri], base_url)
35
+ return transformed if transformed != nil
36
+ end
37
+
38
+ if annotation[:name] && annotation[:value]
39
+ name = annotation[:name]
40
+ value = annotation[:value]
41
+ transform_name_value(name, value, base_url)
42
+ elsif annotation.respond_to?(:each)
43
+ name = annotation[0]
44
+ value = annotation[1]
45
+ transform_name_value(name, value, base_url)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def transform_uri(uri, base_url)
52
+ URI_PATTERNS.map { |pattern|
53
+ match = pattern.match(uri)
54
+ match ? transform_name_value(match[1], match[2], base_url) : nil
55
+ }.compact.first
56
+ end
57
+
58
+ def transform_name_value(name, value, base_url)
59
+ structured_annotation(name, value, base_url) || free_annotation(name, value)
60
+ end
61
+
62
+ def structured_annotation(name, value, base_url)
63
+ annotation = @annotations.find(name).first
64
+ if annotation
65
+ if value.respond_to?(:each)
66
+ {
67
+ :name => annotation.prefLabel.to_s,
68
+ :value => value.map { |v|
69
+ mapped = annotation.find(v).first
70
+ mapped ? mapped.prefLabel.to_s : v
71
+ }
72
+ }
73
+ else
74
+ annotation_value = annotation.find(value).first
75
+ if annotation_value
76
+ {
77
+ :name => annotation.prefLabel.to_s,
78
+ :value => annotation_value.prefLabel.to_s,
79
+ :uri => ANNOTATION_VALUE_URI % [
80
+ base_url,
81
+ annotation.prefix.to_s,
82
+ annotation_value.identifier.to_s
83
+ ]
84
+ }
85
+ else
86
+ {
87
+ :name => annotation.prefLabel.to_s,
88
+ :value => value
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ def free_annotation(name, value)
96
+ {
97
+ :name => normalize_annotation_name(name),
98
+ :value => value
99
+ }
100
+ end
101
+
102
+ def normalize_annotation_name(name, options = {})
103
+ name_s = name.to_s
104
+
105
+ if name_s.empty?
106
+ nil
107
+ else
108
+ name_s.
109
+ split(%r{[^a-zA-Z0-9]+}).
110
+ map! { |word| word.capitalize }.
111
+ join
112
+ end
113
+ end
114
+ end
115
+
116
+ class AnnotationGroupingTransform
117
+
118
+ ExperimentContext = ::BEL::Model::ExperimentContext
119
+
120
+ def transform_evidence!(evidence)
121
+ experiment_context = evidence.experiment_context
122
+ if experiment_context != nil
123
+ evidence.experiment_context = ExperimentContext.new(
124
+ experiment_context.group_by { |annotation|
125
+ annotation[:name]
126
+ }.values.map do |grouped_annotation|
127
+ {
128
+ :name => grouped_annotation.first[:name],
129
+ :value => grouped_annotation.flat_map { |annotation|
130
+ annotation[:value]
131
+ },
132
+ :uri => grouped_annotation.flat_map { |annotation|
133
+ annotation[:uri]
134
+ }
135
+ }
136
+ end
137
+ )
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,98 @@
1
+ require 'bel'
2
+ require_relative 'base'
3
+
4
+ module OpenBEL
5
+ module Resource
6
+ module Functions
7
+
8
+ class FunctionSerializer < BaseSerializer
9
+ adapter Oat::Adapters::HAL
10
+
11
+ schema do
12
+ type :function
13
+ properties do |p|
14
+ p.short_form item[:short_form]
15
+ p.long_form item[:long_form]
16
+ p.description item[:description]
17
+ p.return_type item[:return_type]
18
+ p.signatures item[:signatures]
19
+ end
20
+ end
21
+ end
22
+
23
+ class FunctionResourceSerializer < BaseSerializer
24
+ adapter Oat::Adapters::HAL
25
+
26
+ schema do
27
+ type :function
28
+ properties do |p|
29
+ p.functions item
30
+ end
31
+
32
+ link :self, link_self(item.first[:short_form])
33
+ link :next, link_next
34
+ link :collection, link_collection
35
+ end
36
+
37
+ private
38
+
39
+ def link_self(id)
40
+ {
41
+ :type => :function,
42
+ :href => "#{base_url}/api/functions/#{id}"
43
+ }
44
+ end
45
+
46
+ def link_collection
47
+ {
48
+ :type => :'function_collection',
49
+ :href => "#{base_url}/api/functions"
50
+ }
51
+ end
52
+
53
+ def link_next
54
+ fx_values = FUNCTIONS.values.uniq.sort_by { |fx|
55
+ fx[:short_form]
56
+ }
57
+ next_fx = fx_values[fx_values.index(item) + 1]
58
+ {
59
+ :type => :function,
60
+ :href => next_fx ?
61
+ "#{base_url}/api/functions/#{next_fx[:short_form]}" :
62
+ nil
63
+ }
64
+ end
65
+ end
66
+
67
+ class FunctionCollectionSerializer < BaseSerializer
68
+ adapter Oat::Adapters::HAL
69
+
70
+ schema do
71
+ type :'function_collection'
72
+ properties do |p|
73
+ p.functions item
74
+ end
75
+
76
+ link :self, link_self
77
+ link :start, link_start(item.first[:short_form])
78
+ end
79
+
80
+ private
81
+
82
+ def link_self
83
+ {
84
+ :type => :'function_collection',
85
+ :href => "#{base_url}/api/functions"
86
+ }
87
+ end
88
+
89
+ def link_start(first_function)
90
+ {
91
+ :type => :function,
92
+ :href => "#{base_url}/api/functions/#{first_function}"
93
+ }
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end