opentox-ruby-api-wrapper 1.5.6 → 1.5.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.6
1
+ 1.5.7
data/lib/dataset.rb CHANGED
@@ -22,7 +22,6 @@ module OpenTox
22
22
  accept_header = "application/rdf+xml"
23
23
  end
24
24
  end
25
-
26
25
  case accept_header
27
26
  when "application/x-yaml"
28
27
  d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'application/x-yaml').to_s
@@ -52,6 +51,7 @@ module OpenTox
52
51
  # returns uri of new dataset
53
52
  def create_new_dataset( new_compounds, new_features, new_title, new_creator )
54
53
 
54
+ LOGGER.debug "create new dataset with "+new_compounds.size.to_s+"/"+compounds.size.to_s+" compounds"
55
55
  raise "no new compounds selected" unless new_compounds and new_compounds.size>0
56
56
 
57
57
  # load require features
@@ -69,6 +69,7 @@ module OpenTox
69
69
  # PENDING: why storing feature values in an array?
70
70
  new_compounds.each do |c|
71
71
  data_c = []
72
+ raise "no data for compound '"+c.to_s+"'" if @data[c]==nil
72
73
  @data[c].each do |d|
73
74
  m = {}
74
75
  new_features.each do |f|
@@ -76,7 +77,6 @@ module OpenTox
76
77
  end
77
78
  data_c << m
78
79
  end
79
-
80
80
  dataset.data[c] = data_c
81
81
  end
82
82
  return dataset.save
@@ -91,15 +91,16 @@ module OpenTox
91
91
  else
92
92
  return "no classification key"
93
93
  end
94
- else
95
- raise "predicted class value is not a hash\n"+
94
+ elsif v.is_a?(Array)
95
+ raise "predicted class value is an array\n"+
96
96
  "value "+v.to_s+"\n"+
97
97
  "value-class "+v.class.to_s+"\n"+
98
98
  "dataset "+@uri.to_s+"\n"+
99
99
  "compound "+compound.to_s+"\n"+
100
100
  "feature "+feature.to_s+"\n"
101
+ else
102
+ return v
101
103
  end
102
-
103
104
  end
104
105
 
105
106
  # returns prediction confidence if available
@@ -113,12 +114,14 @@ module OpenTox
113
114
  raise "no confidence key"
114
115
  end
115
116
  else
116
- raise "prediction confidence value is not a hash value\n"+
117
- "value "+v.to_s+"\n"+
118
- "value-class "+v.class.to_s+"\n"+
119
- "dataset "+@uri.to_s+"\n"+
120
- "compound "+compound.to_s+"\n"+
121
- "feature "+feature.to_s+"\n"
117
+ LOGGER.warn "no confidence for compound: "+compound.to_s+", feature: "+feature.to_s
118
+ return 1
119
+ # raise "prediction confidence value is not a hash value\n"+
120
+ # "value "+v.to_s+"\n"+
121
+ # "value-class "+v.class.to_s+"\n"+
122
+ # "dataset "+@uri.to_s+"\n"+
123
+ # "compound "+compound.to_s+"\n"+
124
+ # "feature "+feature.to_s+"\n"
122
125
  end
123
126
  end
124
127
 
@@ -173,7 +176,7 @@ module OpenTox
173
176
 
174
177
  @features.uniq!
175
178
  @compounds.uniq!
176
- OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
179
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
177
180
  end
178
181
 
179
182
  def init_dirty_features(owl)
data/lib/environment.rb CHANGED
@@ -13,6 +13,7 @@ LOG_DIR = File.join(basedir, "log")
13
13
 
14
14
  if File.exist?(config_file)
15
15
  @@config = YAML.load_file(config_file)
16
+ raise "could not load config, config file: "+config_file.to_s unless @@config
16
17
  else
17
18
  FileUtils.mkdir_p TMP_DIR
18
19
  FileUtils.mkdir_p LOG_DIR
@@ -44,7 +45,7 @@ end
44
45
  load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb")
45
46
 
46
47
  # hack: store sinatra in global var to make url_for and halt methods accessible
47
- before {$sinatra = self unless $sinatra}
48
+ before{ $sinatra = self unless $sinatra }
48
49
 
49
50
  class Sinatra::Base
50
51
  # overwriting halt to log halts (!= 202)
@@ -82,7 +83,7 @@ class MyLogger < Logger
82
83
  end
83
84
 
84
85
  def format(msg)
85
- pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+ENV['REMOTE_ADDR'].to_s
86
+ pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+($sinatra ? $sinatra.request.env['REMOTE_ADDR'] : nil).to_s
86
87
  end
87
88
 
88
89
  def debug(msg)
@@ -132,6 +133,7 @@ RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
132
133
  OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
133
134
  DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
134
135
  OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
136
+ #OT = Redland::Namespace.new 'http://ortona.informatik.uni-freiburg.de/opentox.owl#'
135
137
  XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
136
138
 
137
139
  # Regular expressions for parsing classification data
data/lib/model.rb CHANGED
@@ -44,12 +44,6 @@ module OpenTox
44
44
 
45
45
  def self.build( algorithm_uri, algorithm_params )
46
46
 
47
- if algorithm_uri =~ /ambit2/
48
- LOGGER.warn "Ambit hack, replacing 'prediction_feature' with 'target'"
49
- algorithm_params[:target] = algorithm_params[:prediction_feature]
50
- algorithm_params.delete(:prediction_feature)
51
- end
52
-
53
47
  LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.inspect.to_s
54
48
  uri = OpenTox::RestClientWrapper.post(algorithm_uri,algorithm_params).to_s
55
49
  LOGGER.debug "Build model done: "+uri.to_s
@@ -60,7 +54,7 @@ module OpenTox
60
54
  def predict_dataset( dataset_uri )
61
55
 
62
56
  LOGGER.debug "Predict dataset: "+dataset_uri.to_s+" with model "+@uri.to_s
63
- uri = RestClientWrapper.post(@uri, {:dataset_uri=>dataset_uri})
57
+ uri = RestClientWrapper.post(@uri, {:accept => "text/uri-list", :dataset_uri=>dataset_uri})
64
58
  RestClientWrapper.raise_uri_error("Prediciton result no dataset uri: "+uri.to_s, @uri, {:dataset_uri=>dataset_uri} ) unless Utils.dataset_uri?(uri)
65
59
  uri
66
60
  end
@@ -73,7 +67,7 @@ module OpenTox
73
67
  return false
74
68
  elsif @uri =~/tu-muenchen/ and @title =~ /regression|M5P|GaussP/
75
69
  return false
76
- elsif @uri =~/ambit2/ and @title =~ /pKa/
70
+ elsif @uri =~/ambit2/ and @title =~ /pKa/ || @title =~ /Regression|Caco/
77
71
  return false
78
72
  elsif @uri =~/majority/
79
73
  return (@uri =~ /class/) != nil
data/lib/owl.rb CHANGED
@@ -32,6 +32,7 @@ class Redland::Literal
32
32
  @@type_date = XML["date"].uri
33
33
  @@type_boolean = XML["boolean"].uri
34
34
  @@type_datetime = XML["dateTime"].uri
35
+ @@type_integer = XML["integer"].uri
35
36
 
36
37
  # parses value according to datatype uri
37
38
  def self.parse_value(string_value, datatype_uri)
@@ -54,6 +55,8 @@ class Redland::Literal
54
55
  return string_value #PENDING date as string?
55
56
  when @@type_datetime.to_s
56
57
  return string_value #PENDING date as string?
58
+ when @@type_integer.to_s
59
+ return string_value.to_i
57
60
  else
58
61
  raise "unknown literal datatype: '"+datatype_uri.to_s+"', value is "+string_value
59
62
  end
@@ -74,6 +77,12 @@ class Redland::Literal
74
77
  return @@type_float
75
78
  elsif value.is_a?(TrueClass) or value.is_a?(FalseClass)
76
79
  return @@type_boolean
80
+ elsif value.is_a?(Integer)
81
+ return @@type_integer
82
+ elsif value.is_a?(DateTime)
83
+ return @@type_datetime
84
+ elsif value.is_a?(Time)
85
+ return @@type_datetime
77
86
  else
78
87
  raise "illegal datatype: "+value.class.to_s+" "+value.to_s
79
88
  end
@@ -98,7 +107,7 @@ module OpenTox
98
107
  owl = OpenTox::Owl.new
99
108
  owl.ot_class = ot_class
100
109
  owl.root_node = Redland::Resource.new(uri.to_s.strip)
101
- owl.set("type",owl.node(owl.ot_class))
110
+ owl.set("type",owl.node(owl.ot_class)) #,true))
102
111
  owl
103
112
  end
104
113
 
@@ -169,8 +178,9 @@ module OpenTox
169
178
 
170
179
  public
171
180
  def set(name, value, datatype=nil)
181
+
172
182
  raise "uri is no prop, cannot set uri" if name=="uri"
173
- property_node = node(name.to_s)
183
+ property_node = node(name.to_s) #, true)
174
184
  begin # delete existing entry
175
185
  t = @model.object(@root_node, property_node)
176
186
  @model.delete @root_node, property_node, t
@@ -355,16 +365,30 @@ module OpenTox
355
365
  "date" => DC["date"],
356
366
  "format" => DC["format"]}
357
367
 
358
- # this method has to purposes:
368
+ # @object_prop = OWL["ObjectProperty"]
369
+ # @@type = { "Validation" => OWL["Class"],
370
+ # "Model" => OWL["Class"],
371
+ # "title" => OWL["AnnotationProperty"],
372
+ # "creator" => OWL["AnnotationProperty"],
373
+ # "date" => OWL["AnnotationProperty"],
374
+ # "format" => OWL["AnnotationProperty"],
375
+ # "predictedVariables" => @object_prop}
376
+
377
+ # this method has two purposes:
359
378
  # * distinguishing ot-properties from dc- and rdf- properties
360
379
  # * caching nodes, as creating nodes is costly
361
- def node(name)
380
+ def node(name) #, write_type_to_model=false)
362
381
  raise "dc[identifier] deprecated, use owl.uri" if name=="identifier"
363
382
  n = @@property_nodes[name]
364
383
  unless n
365
384
  n = OT[name]
366
385
  @@property_nodes[name] = n
367
386
  end
387
+
388
+ # if write_type_to_model and name!="type"
389
+ # raise "no type defined for '"+name+"'" unless @@type[name]
390
+ # @model.add n,RDF['type'],@@type[name]
391
+ # end
368
392
  return n
369
393
  end
370
394
 
@@ -9,7 +9,7 @@ module OpenTox
9
9
 
10
10
  def initialize(code, body, uri, payload, headers)
11
11
  self.code = code
12
- self.body = body
12
+ self.body = body.to_s[0..1000]
13
13
  self.uri = uri
14
14
  self.payload = payload
15
15
  self.headers = headers
@@ -90,8 +90,6 @@ module OpenTox
90
90
  raise "illegal status code: '"+res.code.to_s+"'" unless res.code==200
91
91
  return res
92
92
 
93
- rescue RestClient::RequestFailed => ex
94
- do_halt ex.http_code,ex.http_body,uri,headers,payload
95
93
  rescue RestClient::RequestTimeout => ex
96
94
  do_halt 408,ex.message,uri,headers,payload
97
95
  rescue => ex
@@ -112,7 +110,7 @@ module OpenTox
112
110
 
113
111
  task = nil
114
112
  case res.content_type
115
- when /application\/rdf\+xml|text\/x-yaml/
113
+ when /application\/rdf\+xml|application\/x-yaml/
116
114
  task = OpenTox::Task.from_data(res, res.content_type, res.code, base_uri)
117
115
  when /text\//
118
116
  raise "uri list has more than one entry, should be a task" if res.content_type=~/text\/uri-list/ and
@@ -142,15 +140,15 @@ module OpenTox
142
140
  error = [Error.new(code, body, uri, payload, headers)]
143
141
  end
144
142
 
145
- # #debug utility: write error to file
146
- # error_dir = "/tmp/ot_errors"
147
- # FileUtils.mkdir(error_dir) unless File.exist?(error_dir)
148
- # raise "could not create error dir" unless File.exist?(error_dir) and File.directory?(error_dir)
149
- # file_name = "error"
150
- # time=Time.now.strftime("%m.%d.%Y-%H:%M:%S")
151
- # count = 1
152
- # count+=1 while File.exist?(File.join(error_dir,file_name+"_"+time+"_"+count.to_s))
153
- # File.new(File.join(error_dir,file_name+"_"+time+"_"+count.to_s),"w").puts(body)
143
+ #debug utility: write error to file
144
+ error_dir = "/tmp/ot_errors"
145
+ FileUtils.mkdir(error_dir) unless File.exist?(error_dir)
146
+ raise "could not create error dir" unless File.exist?(error_dir) and File.directory?(error_dir)
147
+ file_name = "error"
148
+ time=Time.now.strftime("%m.%d.%Y-%H:%M:%S")
149
+ count = 1
150
+ count+=1 while File.exist?(File.join(error_dir,file_name+"_"+time+"_"+count.to_s))
151
+ File.new(File.join(error_dir,file_name+"_"+time+"_"+count.to_s),"w").puts(body)
154
152
 
155
153
  # handle error
156
154
  # we are either in a task, or in sinatra
data/lib/task.rb CHANGED
@@ -71,7 +71,7 @@ module OpenTox
71
71
  end
72
72
 
73
73
  def error(description)
74
- RestClientWrapper.put(File.join(@uri,'Error'),{:description => description})
74
+ RestClientWrapper.put(File.join(@uri,'Error'),{:description => description.to_s[0..2000]})
75
75
  reload
76
76
  end
77
77
 
@@ -113,7 +113,7 @@ module OpenTox
113
113
  end
114
114
  end
115
115
 
116
- LOGGER.debug "task no longer running: "+@uri.to_s+", result: "+@resultURI.to_s
116
+ LOGGER.debug "Task '"+@hasStatus+"': "+@uri.to_s+", Result: "+@resultURI.to_s
117
117
  end
118
118
 
119
119
  def check_state
@@ -43,23 +43,18 @@
43
43
  - "text/plain"
44
44
  opentox-dataset:
45
45
  - "application/x-yaml"
46
- - "text/x-yaml"
47
46
  - "application/rdf+xml"
48
47
  opentox-algorithm:
49
48
  - "application/x-yaml"
50
- - "text/x-yaml"
51
49
  - "application/rdf+xml"
52
50
  opentox-model:
53
51
  - "application/x-yaml"
54
- - "text/x-yaml"
55
52
  - "application/rdf+xml"
56
53
  opentox-task:
57
54
  - "application/x-yaml"
58
- - "text/x-yaml"
59
55
  - "application/rdf+xml"
60
56
  opentox-validation:
61
57
  - "application/x-yaml"
62
- - "text/x-yaml"
63
58
  - "application/rdf+xml"
64
59
 
65
60
  # Timeouts:
data/lib/utils.rb CHANGED
@@ -28,8 +28,9 @@ module OpenTox
28
28
  return false
29
29
  end
30
30
  end
31
- end
32
31
 
32
+ end
33
+
33
34
  # ['rubygems', 'rest_client'].each do |r|
34
35
  # require r
35
36
  # end
@@ -37,5 +38,6 @@ module OpenTox
37
38
  # puts u+"? "+Utils.is_uri?(u).to_s
38
39
  # end
39
40
 
41
+
40
42
  end
41
43
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentox-ruby-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 6
10
- version: 1.5.6
9
+ - 7
10
+ version: 1.5.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christoph Helma, Martin Guetlein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-15 00:00:00 +02:00
18
+ date: 2010-06-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -357,8 +357,8 @@ dependencies:
357
357
  description: Ruby wrapper for the OpenTox REST API (http://www.opentox.org)
358
358
  email: helma@in-silico.ch
359
359
  executables:
360
- - opentox-install-ubuntu.sh
361
360
  - yaml2owl.rb
361
+ - opentox-install-ubuntu.sh
362
362
  - opentox-install-debian.sh
363
363
  extensions: []
364
364