summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-03-23 13:00:55 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2010-03-23 13:00:55 +0100
commit54d1c336501dd34785ca29a3393a9fd347097482 (patch)
tree9a3764deb28e9db0b09ae5ba284a8df7c7528325 /lib
parent420efdf93cc335c8adbdba38a71fa36b797188b0 (diff)
added amit dataset parsing, static lazar feature modifier
Diffstat (limited to 'lib')
-rw-r--r--lib/dataset.rb10
-rw-r--r--lib/environment.rb3
-rw-r--r--lib/model.rb14
-rw-r--r--lib/spork.rb2
4 files changed, 22 insertions, 7 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index bbadd2d..2d49829 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -123,6 +123,16 @@ module OpenTox
value = true
when FALSE_REGEXP # defined in environment.rb
value = false
+ when /.*\^\^<.*XMLSchema#.*>/
+ case value.to_s
+ when /XMLSchema#string/
+ value = value.to_s[0..(value.to_s.index("^^")-1)]
+ when /XMLSchema#double/
+ value = value.to_s[0..(value.to_s.index("^^")-1)].to_f
+ else
+ LOGGER.warn " ILLEGAL TYPE "+compound_uri + " has value '" + value.to_s + "' for feature " + feature_uri
+ value = nil
+ end
else
LOGGER.warn compound_uri + " has value '" + value.to_s + "' for feature " + feature_uri
value = nil
diff --git a/lib/environment.rb b/lib/environment.rb
index 27da072..4c501b4 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -113,8 +113,7 @@ end
begin
0 < @@users[:users].keys.length
rescue
- puts "Please edit #{user_file} and restart your application. Create at least one user with password."
- exit
+ raise "Please edit #{user_file} and restart your application. Create at least one user with password."
end
# RDF namespaces
diff --git a/lib/model.rb b/lib/model.rb
index 6c48734..b4ef86c 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -2,7 +2,9 @@ module OpenTox
module Model
class Lazar
- include Owl
+ include Owl
+
+ PREDICTION_FEATURE_MODIFIER = "_lazar_prediction"
# Create a new prediction model from a dataset
def initialize
@@ -24,7 +26,7 @@ module OpenTox
lazar.algorithm = File.join(@@config[:services]["opentox-algorithm"],"lazar")
lazar.trainingDataset = yaml[:activity_dataset]
lazar.dependentVariables = yaml[:endpoint]
- lazar.predictedVariables = yaml[:endpoint] + "_lazar_prediction"
+ lazar.predictedVariables = yaml[:endpoint] + PREDICTION_FEATURE_MODIFIER
lazar
end
@@ -35,7 +37,8 @@ module OpenTox
def self.find(uri)
yaml = RestClient.get(uri, :accept => "application/x-yaml")
OpenTox::Model::Lazar.from_yaml(yaml)
- end
+ end
+
# Predict a compound
def predict(compound)
@@ -80,7 +83,7 @@ module OpenTox
def trainingDataset=(trainingDataset)
me = @model.subject(RDF['type'],OT[self.owl_class])
- @model.add me, OT['trainingDataset'], Redland::Uri.new(trainingDataset) # untyped individual comes from this line, why??
+ @model.add me, OT['trainingDataset'], Redland::Uri.new(trainingDataset) # untyped individual comes from this line, why??
@model.add Redland::Uri.new(trainingDataset), RDF['type'], OT['Dataset']
end
@@ -100,7 +103,8 @@ module OpenTox
me = @model.subject(RDF['type'],OT[self.owl_class])
@model.add me, OT['predictedVariables'], Redland::Uri.new(predictedVariables) # untyped individual comes from this line, why??
@model.add Redland::Uri.new(predictedVariables), RDF['type'], OT['Feature']
- end
+ end
+
end
end
end
diff --git a/lib/spork.rb b/lib/spork.rb
index 5b43281..e8cf37f 100644
--- a/lib/spork.rb
+++ b/lib/spork.rb
@@ -37,6 +37,7 @@ module Spork
def self.spork(options={})
logger = options[:logger]
logger.debug "spork> parent PID = #{Process.pid}" if logger
+
child = fork do
begin
start = Time.now
@@ -52,6 +53,7 @@ module Spork
yield
rescue => ex
+ raise ex
logger.error "spork> Exception in child[#{Process.pid}] - #{ex.class}: #{ex.message}" if logger
ensure
logger.info "spork> child[#{Process.pid}] took #{Time.now - start} sec" if logger