summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-06-28 18:44:37 +0200
committerChristoph Helma <helma@in-silico.ch>2010-06-28 18:44:37 +0200
commit1b7aa1e22b972f8d297b479319bc586033ee7385 (patch)
treedfa55aa255cac4417d08c7471a03049ccbd03f18 /lib
parentd505f1b33bb823be23728178175c799d2f30fcca (diff)
parent6fb9ec6db40d25d2892d4d1bb9de33e56979a945 (diff)
Merge branch 'master' into development
Diffstat (limited to 'lib')
-rw-r--r--lib/dataset.rb27
-rw-r--r--lib/environment.rb6
-rw-r--r--lib/model.rb10
-rw-r--r--lib/owl.rb32
-rw-r--r--lib/rest_client_wrapper.rb24
-rw-r--r--lib/task.rb4
-rw-r--r--lib/utils.rb4
7 files changed, 65 insertions, 42 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 17f0997..1254992 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -22,7 +22,6 @@ module OpenTox
accept_header = "application/rdf+xml"
end
end
-
case accept_header
when "application/x-yaml"
d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'application/x-yaml').to_s
@@ -52,6 +51,7 @@ module OpenTox
# returns uri of new dataset
def create_new_dataset( new_compounds, new_features, new_title, new_creator )
+ LOGGER.debug "create new dataset with "+new_compounds.size.to_s+"/"+compounds.size.to_s+" compounds"
raise "no new compounds selected" unless new_compounds and new_compounds.size>0
# load require features
@@ -69,6 +69,7 @@ module OpenTox
# PENDING: why storing feature values in an array?
new_compounds.each do |c|
data_c = []
+ raise "no data for compound '"+c.to_s+"'" if @data[c]==nil
@data[c].each do |d|
m = {}
new_features.each do |f|
@@ -76,7 +77,6 @@ module OpenTox
end
data_c << m
end
-
dataset.data[c] = data_c
end
return dataset.save
@@ -91,15 +91,16 @@ module OpenTox
else
return "no classification key"
end
- else
- raise "predicted class value is not a hash\n"+
+ elsif v.is_a?(Array)
+ raise "predicted class value is an array\n"+
"value "+v.to_s+"\n"+
"value-class "+v.class.to_s+"\n"+
"dataset "+@uri.to_s+"\n"+
"compound "+compound.to_s+"\n"+
"feature "+feature.to_s+"\n"
+ else
+ return v
end
-
end
# returns prediction confidence if available
@@ -113,12 +114,14 @@ module OpenTox
raise "no confidence key"
end
else
- raise "prediction confidence value is not a hash value\n"+
- "value "+v.to_s+"\n"+
- "value-class "+v.class.to_s+"\n"+
- "dataset "+@uri.to_s+"\n"+
- "compound "+compound.to_s+"\n"+
- "feature "+feature.to_s+"\n"
+ LOGGER.warn "no confidence for compound: "+compound.to_s+", feature: "+feature.to_s
+ return 1
+# raise "prediction confidence value is not a hash value\n"+
+# "value "+v.to_s+"\n"+
+# "value-class "+v.class.to_s+"\n"+
+# "dataset "+@uri.to_s+"\n"+
+# "compound "+compound.to_s+"\n"+
+# "feature "+feature.to_s+"\n"
end
end
@@ -173,7 +176,7 @@ module OpenTox
@features.uniq!
@compounds.uniq!
- OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
end
def init_dirty_features(owl)
diff --git a/lib/environment.rb b/lib/environment.rb
index 7036951..ceb3ef8 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -13,6 +13,7 @@ LOG_DIR = File.join(basedir, "log")
if File.exist?(config_file)
@@config = YAML.load_file(config_file)
+ raise "could not load config, config file: "+config_file.to_s unless @@config
else
FileUtils.mkdir_p TMP_DIR
FileUtils.mkdir_p LOG_DIR
@@ -44,7 +45,7 @@ end
load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb")
# hack: store sinatra in global var to make url_for and halt methods accessible
-before {$sinatra = self unless $sinatra}
+before{ $sinatra = self unless $sinatra }
class Sinatra::Base
# overwriting halt to log halts (!= 202)
@@ -82,7 +83,7 @@ class MyLogger < Logger
end
def format(msg)
- pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+ENV['REMOTE_ADDR'].to_s
+ pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+($sinatra ? $sinatra.request.env['REMOTE_ADDR'] : nil).to_s
end
def debug(msg)
@@ -136,6 +137,7 @@ RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
+#OT = Redland::Namespace.new 'http://ortona.informatik.uni-freiburg.de/opentox.owl#'
XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
# Regular expressions for parsing classification data
diff --git a/lib/model.rb b/lib/model.rb
index 3fb713f..e3ddeb0 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -44,12 +44,6 @@ module OpenTox
def self.build( algorithm_uri, algorithm_params )
- if algorithm_uri =~ /ambit2/
- LOGGER.warn "Ambit hack, replacing 'prediction_feature' with 'target'"
- algorithm_params[:target] = algorithm_params[:prediction_feature]
- algorithm_params.delete(:prediction_feature)
- end
-
LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.inspect.to_s
uri = OpenTox::RestClientWrapper.post(algorithm_uri,algorithm_params).to_s
LOGGER.debug "Build model done: "+uri.to_s
@@ -60,7 +54,7 @@ module OpenTox
def predict_dataset( dataset_uri )
LOGGER.debug "Predict dataset: "+dataset_uri.to_s+" with model "+@uri.to_s
- uri = RestClientWrapper.post(@uri, {:dataset_uri=>dataset_uri})
+ uri = RestClientWrapper.post(@uri, {:accept => "text/uri-list", :dataset_uri=>dataset_uri})
RestClientWrapper.raise_uri_error("Prediciton result no dataset uri: "+uri.to_s, @uri, {:dataset_uri=>dataset_uri} ) unless Utils.dataset_uri?(uri)
uri
end
@@ -73,7 +67,7 @@ module OpenTox
return false
elsif @uri =~/tu-muenchen/ and @title =~ /regression|M5P|GaussP/
return false
- elsif @uri =~/ambit2/ and @title =~ /pKa/
+ elsif @uri =~/ambit2/ and @title =~ /pKa/ || @title =~ /Regression|Caco/
return false
elsif @uri =~/majority/
return (@uri =~ /class/) != nil
diff --git a/lib/owl.rb b/lib/owl.rb
index 671220b..700e6ee 100644
--- a/lib/owl.rb
+++ b/lib/owl.rb
@@ -32,6 +32,7 @@ class Redland::Literal
@@type_date = XML["date"].uri
@@type_boolean = XML["boolean"].uri
@@type_datetime = XML["dateTime"].uri
+ @@type_integer = XML["integer"].uri
# parses value according to datatype uri
def self.parse_value(string_value, datatype_uri)
@@ -54,6 +55,8 @@ class Redland::Literal
return string_value #PENDING date as string?
when @@type_datetime.to_s
return string_value #PENDING date as string?
+ when @@type_integer.to_s
+ return string_value.to_i
else
raise "unknown literal datatype: '"+datatype_uri.to_s+"', value is "+string_value
end
@@ -74,6 +77,12 @@ class Redland::Literal
return @@type_float
elsif value.is_a?(TrueClass) or value.is_a?(FalseClass)
return @@type_boolean
+ elsif value.is_a?(Integer)
+ return @@type_integer
+ elsif value.is_a?(DateTime)
+ return @@type_datetime
+ elsif value.is_a?(Time)
+ return @@type_datetime
else
raise "illegal datatype: "+value.class.to_s+" "+value.to_s
end
@@ -98,7 +107,7 @@ module OpenTox
owl = OpenTox::Owl.new
owl.ot_class = ot_class
owl.root_node = Redland::Resource.new(uri.to_s.strip)
- owl.set("type",owl.node(owl.ot_class))
+ owl.set("type",owl.node(owl.ot_class)) #,true))
owl
end
@@ -169,8 +178,9 @@ module OpenTox
public
def set(name, value, datatype=nil)
+
raise "uri is no prop, cannot set uri" if name=="uri"
- property_node = node(name.to_s)
+ property_node = node(name.to_s) #, true)
begin # delete existing entry
t = @model.object(@root_node, property_node)
@model.delete @root_node, property_node, t
@@ -355,16 +365,30 @@ module OpenTox
"date" => DC["date"],
"format" => DC["format"]}
- # this method has to purposes:
+# @object_prop = OWL["ObjectProperty"]
+# @@type = { "Validation" => OWL["Class"],
+# "Model" => OWL["Class"],
+# "title" => OWL["AnnotationProperty"],
+# "creator" => OWL["AnnotationProperty"],
+# "date" => OWL["AnnotationProperty"],
+# "format" => OWL["AnnotationProperty"],
+# "predictedVariables" => @object_prop}
+
+ # this method has two purposes:
# * distinguishing ot-properties from dc- and rdf- properties
# * caching nodes, as creating nodes is costly
- def node(name)
+ def node(name) #, write_type_to_model=false)
raise "dc[identifier] deprecated, use owl.uri" if name=="identifier"
n = @@property_nodes[name]
unless n
n = OT[name]
@@property_nodes[name] = n
end
+
+# if write_type_to_model and name!="type"
+# raise "no type defined for '"+name+"'" unless @@type[name]
+# @model.add n,RDF['type'],@@type[name]
+# end
return n
end
diff --git a/lib/rest_client_wrapper.rb b/lib/rest_client_wrapper.rb
index 187f3a9..1282bee 100644
--- a/lib/rest_client_wrapper.rb
+++ b/lib/rest_client_wrapper.rb
@@ -9,7 +9,7 @@ module OpenTox
def initialize(code, body, uri, payload, headers)
self.code = code
- self.body = body
+ self.body = body.to_s[0..1000]
self.uri = uri
self.payload = payload
self.headers = headers
@@ -90,8 +90,6 @@ module OpenTox
raise "illegal status code: '"+res.code.to_s+"'" unless res.code==200
return res
- rescue RestClient::RequestFailed => ex
- do_halt ex.http_code,ex.http_body,uri,headers,payload
rescue RestClient::RequestTimeout => ex
do_halt 408,ex.message,uri,headers,payload
rescue => ex
@@ -112,7 +110,7 @@ module OpenTox
task = nil
case res.content_type
- when /application\/rdf\+xml|text\/x-yaml/
+ when /application\/rdf\+xml|application\/x-yaml/
task = OpenTox::Task.from_data(res, res.content_type, res.code, base_uri)
when /text\//
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
error = [Error.new(code, body, uri, payload, headers)]
end
-# #debug utility: write error to file
-# error_dir = "/tmp/ot_errors"
-# FileUtils.mkdir(error_dir) unless File.exist?(error_dir)
-# raise "could not create error dir" unless File.exist?(error_dir) and File.directory?(error_dir)
-# file_name = "error"
-# time=Time.now.strftime("%m.%d.%Y-%H:%M:%S")
-# count = 1
-# count+=1 while File.exist?(File.join(error_dir,file_name+"_"+time+"_"+count.to_s))
-# File.new(File.join(error_dir,file_name+"_"+time+"_"+count.to_s),"w").puts(body)
+ #debug utility: write error to file
+ error_dir = "/tmp/ot_errors"
+ FileUtils.mkdir(error_dir) unless File.exist?(error_dir)
+ raise "could not create error dir" unless File.exist?(error_dir) and File.directory?(error_dir)
+ file_name = "error"
+ time=Time.now.strftime("%m.%d.%Y-%H:%M:%S")
+ count = 1
+ count+=1 while File.exist?(File.join(error_dir,file_name+"_"+time+"_"+count.to_s))
+ File.new(File.join(error_dir,file_name+"_"+time+"_"+count.to_s),"w").puts(body)
# handle error
# we are either in a task, or in sinatra
diff --git a/lib/task.rb b/lib/task.rb
index 66d39f4..88bcb71 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -71,7 +71,7 @@ module OpenTox
end
def error(description)
- RestClientWrapper.put(File.join(@uri,'Error'),{:description => description})
+ RestClientWrapper.put(File.join(@uri,'Error'),{:description => description.to_s[0..2000]})
reload
end
@@ -113,7 +113,7 @@ module OpenTox
end
end
- LOGGER.debug "task no longer running: "+@uri.to_s+", result: "+@resultURI.to_s
+ LOGGER.debug "Task '"+@hasStatus+"': "+@uri.to_s+", Result: "+@resultURI.to_s
end
def check_state
diff --git a/lib/utils.rb b/lib/utils.rb
index 6b32421..741fbd6 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -28,8 +28,9 @@ module OpenTox
return false
end
end
- end
+ end
+
# ['rubygems', 'rest_client'].each do |r|
# require r
# end
@@ -37,5 +38,6 @@ module OpenTox
# puts u+"? "+Utils.is_uri?(u).to_s
# end
+
end