summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-05-23 13:34:49 +0200
committermr <mr@mrautenberg.de>2011-05-23 13:34:49 +0200
commitb7c063f7c256003e2e67ed0a626403de15f01a9b (patch)
tree9ba2cc8f2d557822d4ee626232a6b50074917a53
parent549da2772bed27de7c3ec69e47e76b5ddd5e07b6 (diff)
parent3ed74a342d389e4fa6f8507a983d29a1ac95862a (diff)
Merge branch 'development' of github.com:opentox/model into development
-rw-r--r--application.rb3
-rw-r--r--lazar.rb62
2 files changed, 52 insertions, 13 deletions
diff --git a/application.rb b/application.rb
index 79cddf0..6e1dcd7 100644
--- a/application.rb
+++ b/application.rb
@@ -16,13 +16,14 @@ end
before do
@accept = request.env['HTTP_ACCEPT']
@accept = 'application/rdf+xml' if @accept == '*/*' or @accept == '' or @accept.nil?
+ response['Content-Type'] = @accept
@id = request.path_info.match(/^\/\d+/)
unless @id.nil?
@id = @id.to_s.sub(/\//,'').to_i
@uri = uri @id
@yaml_file = "public/#{@id}.yaml"
- halt 404, "Dataset #{@id} not found." unless File.exists? @yaml_file
+ halt 404, "Model #{@id} not found." unless File.exists? @yaml_file
end
# make sure subjectid is not included in params, subjectid is set as member variable
diff --git a/lazar.rb b/lazar.rb
index 9c76bbb..d297ccf 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -4,18 +4,14 @@ require "haml"
# @return [application/rdf+xml,application/x-yaml] Model representation
get '/:id/?' do
halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
- response['Content-Type'] = @accept
case @accept
when /application\/rdf\+xml/
s = OpenTox::Serializer::Owl.new
s.add_model(@uri,YAML.load_file(@yaml_file).metadata)
- response['Content-Type'] = 'application/rdf+xml'
s.to_rdfxml
when /yaml/
- response['Content-Type'] = 'application/x-yaml'
File.read @yaml_file
when /html/
- response['Content-Type'] = 'text/html'
OpenTox.text_to_html File.read(@yaml_file)
else
halt 400, "Unsupported MIME type '#{@accept}'"
@@ -23,8 +19,8 @@ get '/:id/?' do
end
get '/:id/metadata.?:ext?' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
metadata = YAML.load_file(@yaml_file).metadata
- response['Content-Type'] = @accept
case @accept
when /yaml/
metadata.to_yaml
@@ -35,6 +31,44 @@ get '/:id/metadata.?:ext?' do
end
end
+get '/:id/dependent' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
+ feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables]
+ case @accept
+ when /yaml/
+ OpenTox::Feature.find(feature_uri).to_yaml
+ when "text/uri-list"
+ feature_uri
+ when /rdf/
+ OpenTox::Feature.find(feature_uri).to_rdfxml
+ when /html/
+ OpenTox.text_to_html OpenTox::Feature.find(feature_uri).to_yaml
+ else
+ halt 400, "Unsupported MIME type '#{@accept}'"
+ end
+end
+
+get '/:id/predicted' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
+ return feature_uri if @accept == "text/uri-list"
+ predicted = OpenTox::Feature.new(File.join @uri,"predicted")
+ dependent = OpenTox::Feature.find(YAML.load_file(@yaml_file).metadata[OT.dependentVariables])
+ predicted.metadata[RDF.type] = dependent.metadata[RDF.type]
+ #predicted.metadata[OT.hasSource] = @uri
+ #predicted.metadata[DC.creator] = @uri
+ predicted.metadata[DC.title] = dependent.metadata[DC.title]
+ case @accept
+ when /yaml/
+ predicted.to_yaml
+ when /rdf/
+ predicted.to_rdfxml
+ when /html/
+ OpenTox.text_to_html predicted.to_yaml
+ else
+ halt 400, "Unsupported MIME type '#{@accept}'"
+ end
+end
+
# Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model
# @param [Body] lazar Model representation in YAML format
# @return [String] Model URI
@@ -68,13 +102,17 @@ post '/:id/?' do
if compound_uri
cache = PredictionCache.find(:model_uri => @lazar.uri, :compound_uri => compound_uri).first
return cache.dataset_uri if cache and uri_available?(cache.dataset_uri)
- begin
- prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri
- PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri)
- prediction_uri
- rescue
- LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} "
- halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed."
+ if cache and uri_available?(cache.dataset_uri)
+ return cache.dataset_uri
+ else
+ begin
+ prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri
+ PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri)
+ prediction_uri
+ rescue
+ LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} "
+ halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed."
+ end
end
elsif dataset_uri
task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do |task|