opentox-ruby-api-wrapper 1.1.3 → 1.2.0

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.
data/Rakefile CHANGED
@@ -15,15 +15,11 @@ begin
15
15
  gem.add_dependency "rack"
16
16
  gem.add_dependency "rack-contrib"
17
17
  gem.add_dependency "thin"
18
- gem.add_dependency "ezmobius-redis-rb"
19
18
  gem.add_dependency "emk-sinatra-url-for"
20
19
  gem.add_dependency "cehoffman-sinatra-respond_to"
21
- gem.add_dependency "dm-core"
22
- gem.add_dependency "datamapper"
23
- gem.add_dependency "do_sqlite3"
24
20
  gem.add_development_dependency "cucumber"
25
21
  gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
26
- gem.files.include %w(lib/tasks/opentox.rb, lib/tasks/redis.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/feature.rb, lib/model.rb, lib/utils.rb, lib/templates/*)
22
+ gem.files.include %w(lib/tasks/owl.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/model.rb, lib/utils.rb, lib/templates/*)
27
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
28
24
  end
29
25
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.2.0
@@ -1,35 +1,37 @@
1
1
  module OpenTox
2
2
  module Algorithm
3
3
 
4
- class Fminer < OpenTox
5
- # Create a new dataset with BBRC features
6
- def self.create(params)
7
- puts params[:dataset_uri]
8
- uri = RestClient.post File.join(@@config[:services]["opentox-algorithm"],'fminer'), :dataset_uri => params[:dataset_uri]
9
- print "fminer finsihed "
10
- puts uri
11
- uri
12
- end
13
- end
4
+ class Fminer #< OpenTox
5
+ include Owl
14
6
 
15
- class Similarity < OpenTox
16
-
17
- def self.tanimoto(dataset1,compound1,dataset2,compound2)
18
- RestClient.get File.join(@@config[:services]["opentox-algorithm"], 'tanimoto/dataset',dataset1.name,compound1.inchi,'dataset',dataset2.name,compound2.inchi)
7
+ def initialize
8
+ super
9
+ self.uri = File.join(@@config[:services]["opentox-algorithm"],'fminer')
10
+ self.title = "fminer"
11
+ self.source = "http://github.com/amaunz/libfminer"
12
+ self.parameters = {
13
+ "Dataset URI" => { :scope => "mandatory", :value => "dataset_uri" },
14
+ "Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri" }
15
+ }
19
16
  end
20
-
21
- def self.weighted_tanimoto(dataset1,compound1,dataset2,compound2)
22
- # URI.escape does not work here
23
- uri = File.join(@@config[:services]["opentox-algorithm"], 'weighted_tanimoto/dataset',CGI.escape(dataset1.name),'compound',CGI.escape(compound1.inchi),'dataset',CGI.escape(dataset2.name),'compound',CGI.escape(compound2.inchi))
24
- RestClient.get uri
25
- end
26
-
27
17
  end
28
18
 
29
- class Lazar < OpenTox
30
- # Create a new prediction model from a dataset
31
- def self.create(params)
32
- RestClient.post File.join(@@config[:services]["opentox-algorithm"],"lazar_classification"), params
19
+ class Lazar #< OpenTox
20
+ include Owl
21
+
22
+ def initialize
23
+ super
24
+ self.uri = File.join(@@config[:services]["opentox-algorithm"],'lazar')
25
+ self.title = "lazar"
26
+ self.source = "http://github.com/helma/opentox-algorithm"
27
+ self.parameters = {
28
+ "Dataset URI" =>
29
+ { :scope => "mandatory", :value => "dataset_uri" },
30
+ "Feature URI for dependent variable" =>
31
+ { :scope => "mandatory", :value => "feature_uri" },
32
+ "Feature generation URI" =>
33
+ { :scope => "mandatory", :value => "feature_generation_uri" }
34
+ }
33
35
  end
34
36
  end
35
37
 
@@ -1,9 +1,8 @@
1
1
  module OpenTox
2
2
 
3
- # uri: /compound/:inchi
4
- class Compound < OpenTox
3
+ class Compound #< OpenTox
5
4
 
6
- attr_reader :inchi
5
+ attr_reader :inchi, :uri
7
6
 
8
7
  # Initialize with <tt>:uri => uri</tt>, <tt>:smiles => smiles</tt> or <tt>:name => name</tt> (name can be also an InChI/InChiKey, CAS number, etc)
9
8
  def initialize(params)
@@ -14,8 +13,11 @@ module OpenTox
14
13
  elsif params[:inchi]
15
14
  @inchi = params[:inchi]
16
15
  @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
16
+ elsif params[:sdf]
17
+ @inchi = sdf2inchi(params[:sdf])
18
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
17
19
  elsif params[:name]
18
- @inchi = RestClient.get "#{@@cactus_uri}#{params[:name]}/stdinchi"
20
+ @inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp
19
21
  @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
20
22
  elsif params[:uri]
21
23
  @inchi = params[:uri].sub(/^.*InChI/, 'InChI')
@@ -44,8 +46,12 @@ module OpenTox
44
46
  end
45
47
 
46
48
  # Match an array of smarts features, returns matching features
47
- def match(smarts_dataset)
48
- smarts_dataset.all_features.collect{ |uri| uri if self.match?(Feature.new(:uri => uri).name) }.compact
49
+ def match(smarts_array)
50
+ smarts_array.collect{|s| s if match?(s)}.compact
51
+ end
52
+
53
+ def sdf2inchi(sdf)
54
+ obconversion(sdf,'sdf','inchi')
49
55
  end
50
56
 
51
57
  def smiles2inchi(smiles)
@@ -61,7 +67,12 @@ module OpenTox
61
67
  obmol = OpenBabel::OBMol.new
62
68
  obconversion.set_in_and_out_formats input_format, output_format
63
69
  obconversion.read_string obmol, identifier
64
- obconversion.write_string(obmol).gsub(/\s/,'').chomp
70
+ case output_format
71
+ when /smi|can|inchi/
72
+ obconversion.write_string(obmol).gsub(/\s/,'').chomp
73
+ else
74
+ obconversion.write_string(obmol)
75
+ end
65
76
  end
66
77
  end
67
78
  end
@@ -1,79 +1,184 @@
1
1
  module OpenTox
2
2
 
3
- # key: /datasets
4
- # set: dataset uris
5
- # key: /dataset/:dataset/compounds
6
- # set: compound uris
7
- # key: /dataset/:dataset/compound/:inchi
8
- # set: feature uris
9
- class Dataset < OpenTox
3
+ class Dataset
4
+ include Owl
10
5
 
11
- # Initialize with <tt>:uri => uri</tt> or <tt>:name => name</tt> (creates a new dataset)
12
- def initialize(uri)
13
- super(uri)
6
+ #attr_accessor :model
7
+
8
+ def initialize
9
+ super
14
10
  end
15
11
 
16
- def self.create(params)
17
- uri = RestClient.post @@config[:services]["opentox-dataset"], :name => params[:name]
18
- Dataset.new(uri.to_s)
12
+ # find or create a new compound and return the resource
13
+ def find_or_create_compound(uri)
14
+ compound = @model.subject(DC["identifier"], uri)
15
+ if compound.nil?
16
+ compound = @model.create_resource
17
+ @model.add compound, RDF['type'], OT["Compound"]
18
+ @model.add compound, DC["identifier"], uri
19
+ end
20
+ compound
19
21
  end
20
22
 
21
- def self.find(params)
22
- begin
23
- if params[:name]
24
- uri = File.join(@@config[:services]["opentox-dataset"], URI.encode(params[:name]))
25
- elsif params[:uri]
26
- uri = params[:uri]
27
- end
28
- RestClient.get uri # check if the resource is available
29
- Dataset.new(uri) if uri
30
- rescue
31
- nil
23
+ # find or create a new feature and return the resource
24
+ def find_or_create_feature(f)
25
+ feature = @model.subject(DC["title"], f[:name].to_s)
26
+ if feature.nil?
27
+ feature = @model.create_resource
28
+ @model.add feature, RDF['type'], OT["Feature"]
29
+ @model.add feature, DC["identifier"], File.join("feature",feature.to_s.gsub(/[()]/,'')) # relative uri as we don know the final uri
30
+ @model.add feature, DC["title"], f[:name].to_s
31
+ @model.add feature, OT['hasSource'], f[:source].to_s if f[:source]
32
32
  end
33
+ feature
33
34
  end
34
35
 
35
- def self.find_or_create(params)
36
- self.create(params) unless self.find(params)
36
+ # find or create a new value and return the resource
37
+ def find_or_create_value(v)
38
+ value = @model.subject OT["value"], v.to_s
39
+ if value.nil?
40
+ value = @model.create_resource
41
+ @model.add value, RDF['type'], OT["FeatureValue"]
42
+ @model.add value, OT["value"], v.to_s
43
+ end
44
+ value
37
45
  end
38
46
 
39
- def self.base_uri
40
- @@config[:services]["opentox-dataset"]
47
+ def tuple?(t)
48
+ statements = []
49
+ has_tuple = true
50
+ t.each do |name,v|
51
+ feature = self.find_or_create_feature(:name => name)
52
+ value = self.find_or_create_value(v)
53
+ tuple = @model.subject(feature,value)
54
+ has_tuple = false if tuple.nil?
55
+ statements << [tuple,feature,value]
56
+ end
57
+ tuples_found = statements.collect{|s| s[0]}.uniq
58
+ has_tuple = false unless tuples_found.size == 1
59
+ has_tuple
41
60
  end
42
61
 
43
- def import(params)
44
- if params[:csv]
45
- # RestClient seems not to work for file uploads
46
- #RestClient.post @uri + '/import', :compound_format => params[:compound_format], :content_type => "text/csv", :file => File.new(params[:csv])
47
- `curl -X POST -F "file=@#{params[:csv]};type=text/csv" -F compound_format=#{params[:compound_format]} #{@uri + '/import'}`
62
+ def create_tuple(t)
63
+ tuple = @model.create_resource
64
+ @model.add tuple, RDF['type'], OT["Tuple"]
65
+ t.each do |name,value|
66
+ feature = self.find_or_create_feature(:name => name)
67
+ value = self.find_or_create_value(value)
68
+ pair = @model.create_resource
69
+ @model.add tuple, OT['tuple'], pair
70
+ @model.add pair, OT['feature'], feature
71
+ @model.add pair, OT['value'], value
48
72
  end
73
+ tuple
49
74
  end
50
75
 
51
- def add(features)
52
- RestClient.put @uri, :features => features
76
+ def find_or_create_tuple(t)
77
+ if self.tuple?(t)
78
+ t
79
+ else
80
+ self.create_tuple(t)
81
+ end
53
82
  end
54
83
 
55
- # Get all compounds from a dataset
56
- def compound_uris
57
- RestClient.get(File.join(@uri, 'compounds')).split("\n")
84
+ def add_data_entry(compound,feature,value)
85
+ data_entry = @model.create_resource
86
+ @model.add data_entry, RDF['type'], OT["DataEntry"]
87
+ @model.add data_entry, OT['compound'], compound
88
+ @model.add data_entry, OT['feature'], feature
89
+ @model.add data_entry, OT['values'], value
58
90
  end
59
91
 
60
- def compounds
61
- compound_uris.collect{|uri| Compound.new(:uri => uri)}
92
+ def self.create(data, content_type = 'application/rdf+xml')
93
+ uri = RestClient.post @@config[:services]["opentox-dataset"], data, :content_type => content_type
94
+ dataset = Dataset.new
95
+ dataset.read uri.to_s
96
+ dataset
97
+ end
98
+
99
+ def self.find(uri)
100
+ begin
101
+ RestClient.get uri # check if the resource is available
102
+ dataset = Dataset.new
103
+ dataset.read uri.to_s
104
+ dataset
105
+ rescue
106
+ nil
107
+ end
108
+ end
109
+
110
+ def features
62
111
  end
63
112
 
64
- # Get all features for a compound
65
- def feature_uris(compound)
66
- uri = File.join(@uri, 'compound', CGI.escape(compound.inchi)) # URI.encode does not work here
67
- RestClient.get(uri).split("\n")
113
+ def feature_values(uri)
114
+ features = {}
115
+ feature = @model.subject(DC["identifier"],uri)
116
+ @model.subjects(RDF['type'], OT["Compound"]).each do |compound_node|
117
+ compound = @model.object(compound_node, DC["identifier"]).to_s.sub(/^\[(.*)\]$/,'\1')
118
+ features[compound] = [] unless features[compound]
119
+ @model.subjects(OT['compound'], compound_node).each do |data_entry|
120
+ if feature == @model.object(data_entry, OT['feature'])
121
+ values_node = @model.object(data_entry, OT['values'])
122
+ @model.find(values_node, OT['value'], nil) do |s,p,value|
123
+ case value.to_s
124
+ when "true"
125
+ features[compound] << true
126
+ when "false"
127
+ features[compound] << false
128
+ else
129
+ features[compound] << value.to_s
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ features
68
136
  end
69
137
 
70
- # Get all features for a compound
71
- def features(compound)
72
- feature_uris(compound).collect{|uri| Feature.new(:uri => uri)}
138
+ def tuples
139
+ tuples = []
140
+ @model.subjects(RDF['type'], OT["Tuple"]).each do |t|
141
+ tuple = {}
142
+ compounds = []
143
+ @model.subjects(OT['values'], t).each do |data_entry|
144
+ compound_node = @model.object(data_entry,OT['compound'])
145
+ compounds << @model.object(compound_node, DC["identifier"]).to_s
146
+ end
147
+ @model.find(t, OT['tuple'],nil) do |s,p,pair|
148
+ feature_node = @model.object(pair, OT['feature'])
149
+ feature_name = @model.object(feature_node, DC['title']).to_s
150
+ value_node = @model.object(pair, OT['value'])
151
+ value = @model.object(value_node, OT['value']).to_s
152
+ value = value.to_f if value.match(/^[\d\.]+$/)
153
+ tuple[feature_name.to_sym] = value
154
+ end
155
+ tuple[:compounds] = compounds
156
+ tuples << tuple
157
+ end
158
+ tuples
73
159
  end
74
160
 
75
- def all_features
76
- RestClient.get(File.join(@uri, 'features')).split("\n")
161
+ def tuple(compound_uri)
162
+ compound_node = @model.subject(DC["identifier"],compound_uri)
163
+ #puts compound_uri
164
+ @model.subjects(OT['compound'], compound_node).each do |data_entry|
165
+ values_node = @model.object(data_entry, OT['values'])
166
+ @model.find(values_node, OT['tuple'], nil) do |s,p,tuple|
167
+ @model.find(tuple, OT['feature'], nil) do |s,p,feature|
168
+ name = @model.object(feature,DC['title']).to_s
169
+ #puts name
170
+ end
171
+ end
172
+ #puts values_node
173
+ end
174
+ end
175
+
176
+ def compounds
177
+ compounds = []
178
+ @model.subjects(RDF['type'], OT["Compound"]).each do |compound_node|
179
+ compounds << @model.object(compound_node, DC["identifier"])#.to_s.sub(/^\[(.*)\]$/,'\1')
180
+ end
181
+ compounds
77
182
  end
78
183
 
79
184
  # Delete a dataset
@@ -81,14 +186,64 @@ module OpenTox
81
186
  RestClient.delete @uri
82
187
  end
83
188
 
84
- def tanimoto(dataset)
85
- RestClient.get(File.join(@uri,'tanimoto',dataset.path))
86
- end
87
-
88
- def weighted_tanimoto(dataset)
89
- RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path))
189
+ def save
190
+ RestClient.post(@@config[:services]["opentox-dataset"], self.rdf, :content_type => "application/rdf+xml").to_s
90
191
  end
91
192
 
92
193
  end
93
194
 
94
195
  end
196
+
197
+
198
+ # def tanimoto(dataset)
199
+ # RestClient.get(File.join(@uri,'tanimoto',dataset.path))
200
+ # end
201
+ #
202
+ # def weighted_tanimoto(dataset)
203
+ # RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path))
204
+ # end
205
+ =begin
206
+ def data_entries
207
+ data = {}
208
+ @model.subjects(RDF['type'], OT["Compound"]).each do |compound_node|
209
+ compound = @model.object(compound_node, DC["identifier"]).to_s#.sub(/^\[(.*)\]$/,'\1')
210
+ #compound = OpenTox::Compound.new(:inchi => compound).smiles
211
+ data[compound] = [] unless data[compound]
212
+ #puts compound
213
+ @model.subjects(OT['compound'], compound_node).each do |data_entry|
214
+ feature_node = @model.object(data_entry, OT['feature'])
215
+ feature = @model.object(feature_node, DC["identifier"]).to_s
216
+ values_node = @model.object(data_entry, OT['values'])
217
+ type = @model.object(values_node,RDF['type']).to_s
218
+ case type
219
+ when /FeatureValue/
220
+ @model.find(values_node, OT['value'], nil) do |s,p,value|
221
+ case value.to_s
222
+ when "true"
223
+ data[compound] << {feature => true}
224
+ when "false"
225
+ data[compound] << {feature => false}
226
+ else
227
+ data[compound] << {feature => value.to_s}
228
+ end
229
+ end
230
+ when /Tuple/ # this is really slow
231
+ t = {}
232
+ @model.find(values_node, OT['tuple'], nil) do |s,p,tuple|
233
+ @model.find(tuple, OT['feature'], nil) do |s,p,feature|
234
+ @name = @model.object(feature,DC['title']).to_s
235
+ end
236
+ @model.find(tuple, OT['value'], nil) do |s,p,value|
237
+ v = @model.object(value,OT['value']).to_s
238
+ t[@name] = v
239
+ #print @name + ": "
240
+ #puts v
241
+ end
242
+ end
243
+ data[compound] << t
244
+ end
245
+ end
246
+ end
247
+ data
248
+ end
249
+ =end
@@ -17,7 +17,14 @@ else
17
17
  exit
18
18
  end
19
19
 
20
+ # RDF namespaces
21
+ RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
22
+ OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
23
+ DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
24
+ OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
25
+
20
26
  # configure redis database
27
+ =begin
21
28
  begin
22
29
  case ENV['RACK_ENV']
23
30
  when 'production'
@@ -31,3 +38,4 @@ begin
31
38
  rescue
32
39
  puts "Redis database not running, please start it with 'rake redis:start'."
33
40
  end
41
+ =end
@@ -1,11 +1,10 @@
1
1
  module OpenTox
2
2
 
3
- # uri: /feature/:name/:property_name/:property_value/...
4
- class Feature < OpenTox
3
+ class Feature
4
+ include Owl
5
5
 
6
- attr_accessor :name, :values
6
+ def self.find_or_create(feature)
7
7
 
8
- def initialize(params)
9
8
  if params[:uri]
10
9
  @uri = params[:uri]
11
10
  items = URI.split(@uri)[5].split(/\//)
@@ -1,38 +1,69 @@
1
1
  module OpenTox
2
-
3
- module Model
4
-
5
- class LazarClassification < OpenTox
6
-
2
+ module Model
3
+ class Lazar
4
+ include Owl
5
+
7
6
  # Create a new prediction model from a dataset
8
- def initialize(uri)
9
- super(uri)
7
+ def initialize
8
+ super
10
9
  end
11
10
 
12
- def self.create(params)
13
- uri = RestClient.post File.join(@@config[:services]["opentox-model"], 'lazar_classification'), params
14
- puts "URI: " + uri
15
- LazarClassification.new(uri.to_s)
11
+ def read_yaml(id,yaml)
12
+ @lazar = YAML.load yaml
13
+ self.identifier = File.join(@@config[:services]["opentox-model"],'lazar',id)
14
+ self.title = "lazar model for #{@lazar[:endpoint]}"
15
+ self.source = "http://github.com/helma/opentox-model"
16
+ self.parameters = {
17
+ "Dataset URI" => { :scope => "mandatory", :value => "dataset_uri=#{@lazar[:activity_dataset]}" },
18
+ "Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri=#{@lazar[:endpoint]}" },
19
+ "Feature generation URI" => { :scope => "mandatory", :value => "feature_generation_uri=" } #TODO write to yaml
20
+ }
21
+ self.algorithm = File.join(@@config[:services]["opentox-model"],"lazar")
22
+ self.trainingDataset = @lazar[:activity_dataset]
23
+ self.dependentVariables = @lazar[:endpoint]
24
+ self.predictedVariables = @lazar[:endpoint] + " lazar prediction"
16
25
  end
17
26
 
18
- def self.find(name)
19
- uri = RestClient.get File.join(@@config[:services]["opentox-model"], 'lazar_classification', URI.encode(params[:name]))
20
- LazarClassification.new(uri)
27
+ def self.find(uri)
28
+ begin
29
+ YAML.load(RestClient.get uri)
30
+ Lazar.new uri
31
+ rescue
32
+ halt 404, "Model #{uri} not found."
33
+ end
21
34
  end
22
35
 
23
36
  def self.find_all
24
- RestClient.get File.join(@@config[:services]["opentox-model"], 'lazar_classification')#.split("\n")
37
+ RestClient.get(@@config[:services]["opentox-model"]).split("\n")
25
38
  end
26
-
39
+
27
40
  # Predict a compound
28
41
  def predict(compound)
29
- LazarPrediction.new(:uri => RestClient.post(@uri, :compound_uri => compound.uri))
42
+ RestClient.post(@uri, :compound_uri => compound.uri)
30
43
  end
31
44
 
32
45
  def self.base_uri
33
46
  @@config[:services]["opentox-model"]
34
47
  end
35
48
 
49
+ def self.create(data)
50
+ RestClient.post(@@config[:services]["opentox-model"], data, :content_type => "application/x-yaml").to_s
51
+ end
52
+
53
+ def endpoint
54
+ YAML.load(RestClient.get uri)[:endpoint]
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+
61
+ =begin
62
+ module Model
63
+
64
+ class LazarClassification < OpenTox
65
+
66
+
36
67
  end
37
68
 
38
69
  end
@@ -48,11 +79,11 @@ module OpenTox
48
79
  end
49
80
 
50
81
  def classification
51
- YAML.load(RestClient.get @uri)[:classification]
82
+ YAML.load(RestClient.get(@uri))[:classification]
52
83
  end
53
84
 
54
85
  def confidence
55
- YAML.load(RestClient.get @uri)[:confidence]
86
+ YAML.load(RestClient.get(@uri))[:confidence]
56
87
  end
57
88
 
58
89
  def neighbors
@@ -68,4 +99,5 @@ module OpenTox
68
99
  end
69
100
 
70
101
  end
102
+ =end
71
103
  end
@@ -1,4 +1,4 @@
1
- ['rubygems', 'sinatra', 'sinatra/url_for', 'redis','builder', 'rest_client', 'yaml', 'cgi', 'spork', 'environment'].each do |lib|
1
+ ['rubygems', 'sinatra', 'sinatra/url_for', 'rest_client', 'yaml', 'cgi', 'spork', 'redland', 'rdf/redland', 'rdf/redland/util', 'environment'].each do |lib|
2
2
  require lib
3
3
  end
4
4
 
@@ -8,6 +8,6 @@ rescue LoadError
8
8
  puts "Please install Openbabel with 'rake openbabel:install' in the compound component"
9
9
  end
10
10
 
11
- ['opentox', 'compound','feature','dataset','algorithm','model','task','utils'].each do |lib|
11
+ ['owl', 'compound','dataset','algorithm','model','task','utils'].each do |lib|
12
12
  require lib
13
13
  end
@@ -0,0 +1,102 @@
1
+ module OpenTox
2
+
3
+ module Owl
4
+
5
+ attr_reader :uri, :model
6
+
7
+ def initialize
8
+
9
+ @model = Redland::Model.new Redland::MemoryStore.new
10
+ @parser = Redland::Parser.new
11
+ @serializer = Redland::Serializer.ntriples
12
+
13
+ # explicit typing
14
+ # this should come from http://opentox.org/data/documents/development/RDF%20files/OpenToxOntology/at_download/file (does not pass OWL-DL validation)
15
+ @model.add @uri, RDF['type'], OWL['Ontology']
16
+ # annotation properties
17
+ @model.add DC['source'], RDF['type'], OWL["AnnotationProperty"]
18
+ @model.add DC['identifier'], RDF['type'], OWL["AnnotationProperty"]
19
+ @model.add DC['title'], RDF['type'], OWL["AnnotationProperty"]
20
+ # object properties
21
+ @model.add OT['feature'], RDF['type'], OWL["ObjectProperty"]
22
+ @model.add OT['compound'], RDF['type'], OWL["ObjectProperty"]
23
+ @model.add OT['values'], RDF['type'], OWL["ObjectProperty"]
24
+ @model.add OT['tuple'], RDF['type'], OWL["ObjectProperty"] # added by ch
25
+ @model.add OT['parameters'], RDF['type'], OWL["ObjectProperty"]
26
+ # datatype properties
27
+ @model.add OT['value'], RDF['type'], OWL["DatatypeProperty"]
28
+ @model.add OT['paramValue'], RDF['type'], OWL["DatatypeProperty"]
29
+ @model.add OT['paramScope'], RDF['type'], OWL["DatatypeProperty"]
30
+ @model.add OT['hasSource'], RDF['type'], OWL["DatatypeProperty"]
31
+ # classes
32
+ @model.add OT['Dataset'], RDF['type'], OWL["Class"]
33
+ @model.add OT['FeatureValue'], RDF['type'], OWL["Class"]
34
+ @model.add OT['Tuple'], RDF['type'], OWL["Class"] # added by ch
35
+ @model.add OT['Feature'], RDF['type'], OWL["Class"]
36
+ @model.add OT['Compound'], RDF['type'], OWL["Class"]
37
+ @model.add OT['DataEntry'], RDF['type'], OWL["Class"]
38
+ @model.add OT['Parameter'], RDF['type'], OWL["Class"]
39
+ @model.add OT['Algorithm'], RDF['type'], OWL["Class"]
40
+ end
41
+
42
+ def owl_class
43
+ self.class.to_s.sub(/^OpenTox::/,'')
44
+ #@model.subject RDF['type'], OT[self.class.to_s.sub(/^OpenTox::/,'')]
45
+ end
46
+
47
+ def read(uri)
48
+ @parser.parse_into_model(@model,uri)
49
+ @uri = uri
50
+ end
51
+
52
+ def rdf=(rdf)
53
+ @uri = '/' unless @uri
54
+ @parser.parse_string_into_model(@model,rdf,@uri)
55
+ end
56
+
57
+ def rdf
58
+ @model.to_string
59
+ end
60
+
61
+ def uri=(uri)
62
+ identifier = uri
63
+ end
64
+
65
+ def to_ntriples
66
+ @serializer.model_to_string(Redland::Uri.new(@uri), @model)
67
+ end
68
+
69
+ def title
70
+ puts OT[self.owl_class]
71
+ @model.object(OT[self.owl_class], DC['title']).to_s
72
+ end
73
+
74
+ def parameters=(params)
75
+ params.each do |name, settings|
76
+ parameter = @model.create_resource
77
+ @model.add parameter, RDF['type'], OT['Parameter']
78
+ @model.add parameter, DC['title'], name
79
+ @model.add parameter, OT['paramScope'], settings[:scope]
80
+ @model.add parameter, OT['paramValue'], settings[:value]
81
+ end
82
+ end
83
+
84
+ def create_owl_statement(name,value)
85
+ r = @model.create_resource
86
+ @model.add r, RDF['type'], DC[name.gsub(/^[a-z]/) { |a| a.upcase }] # capitalize only the first letter
87
+ @model.add r, DC[name], value
88
+ end
89
+
90
+ def method_missing(name, *args)
91
+ # create magic setter methods
92
+ if /=/ =~ name.to_s
93
+ puts "create_owl_statement #{name.to_s.sub(/=/,'')}, #{args.first}"
94
+ create_owl_statement name.to_s.sub(/=/,''), args.first
95
+ else
96
+ raise "No method #{name}"
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -1,15 +1,16 @@
1
1
  module OpenTox
2
2
 
3
- class Task < OpenTox
4
- #private :new
3
+ class Task #< OpenTox
5
4
 
6
5
  def initialize(uri)
7
6
  super(uri)
8
7
  end
9
8
 
10
- def self.create(params)
11
- uri = RestClient.post @@config[:services]["opentox-task"], :resource_uri => params[:resource_uri]
12
- Task.new uri
9
+ #def self.create(uri)
10
+ def self.create
11
+ puts @@config[:services]["opentox-task"]
12
+ uri = RestClient.post @@config[:services]["opentox-task"], ''#, :dataset_uri => uri
13
+ Task.new(uri)
13
14
  end
14
15
 
15
16
  def self.find(params)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentox-ruby-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Helma
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 +01:00
12
+ date: 2009-12-16 00:00:00 +01:00
13
13
  default_executable: opentox-install-debian.sh
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -62,16 +62,6 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: "0"
64
64
  version:
65
- - !ruby/object:Gem::Dependency
66
- name: ezmobius-redis-rb
67
- type: :runtime
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
74
- version:
75
65
  - !ruby/object:Gem::Dependency
76
66
  name: emk-sinatra-url-for
77
67
  type: :runtime
@@ -92,36 +82,6 @@ dependencies:
92
82
  - !ruby/object:Gem::Version
93
83
  version: "0"
94
84
  version:
95
- - !ruby/object:Gem::Dependency
96
- name: dm-core
97
- type: :runtime
98
- version_requirement:
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
104
- version:
105
- - !ruby/object:Gem::Dependency
106
- name: datamapper
107
- type: :runtime
108
- version_requirement:
109
- version_requirements: !ruby/object:Gem::Requirement
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
114
- version:
115
- - !ruby/object:Gem::Dependency
116
- name: do_sqlite3
117
- type: :runtime
118
- version_requirement:
119
- version_requirements: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: "0"
124
- version:
125
85
  - !ruby/object:Gem::Dependency
126
86
  name: cucumber
127
87
  type: :development
@@ -155,7 +115,7 @@ files:
155
115
  - lib/helper.rb
156
116
  - lib/model.rb
157
117
  - lib/opentox-ruby-api-wrapper.rb
158
- - lib/opentox.rb
118
+ - lib/owl.rb
159
119
  - lib/spork.rb
160
120
  - lib/task.rb
161
121
  - lib/tasks/opentox.rb
@@ -1,27 +0,0 @@
1
- module OpenTox
2
-
3
- class OpenTox
4
- attr_accessor :uri
5
-
6
- def initialize(uri)
7
- @uri = uri
8
- end
9
-
10
- # Get the object name
11
- def name
12
- RestClient.get @uri + '/name'
13
- end
14
-
15
- # Deletes an object
16
- def destroy
17
- RestClient.delete @uri
18
- end
19
-
20
- # Object path without hostname
21
- def path
22
- URI.split(@uri)[5]
23
- end
24
-
25
- end
26
-
27
- end