From 52dd7cdc664b034c0faa5895358dc01927554277 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 26 Feb 2010 16:54:37 +0100 Subject: source file added to logger --- application.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application.rb b/application.rb index 3ec3bba..9de5915 100644 --- a/application.rb +++ b/application.rb @@ -2,6 +2,8 @@ require 'rubygems' gem 'opentox-ruby-api-wrapper', '= 1.2.7' require 'opentox-ruby-api-wrapper' +LOGGER.progname = File.expand_path(__FILE__) + class Dataset include DataMapper::Resource property :id, Serial -- cgit v1.2.3 From 0b34145066d2a2772de3b87d0cfd7756b7275a58 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 26 Feb 2010 17:04:25 +0100 Subject: public directory added --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1441bd2..b42cb55 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ api_key.rb tmp/* log/* datasets/* +public/* -- cgit v1.2.3 From ea72a52a92e1b2f9cb8090b898c16981092763d1 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 1 Mar 2010 10:21:44 +0100 Subject: wrapper version bumped to 1.3.0 --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 9de5915..058fbd8 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem 'opentox-ruby-api-wrapper', '= 1.2.7' +gem 'opentox-ruby-api-wrapper', '= 1.3.0' require 'opentox-ruby-api-wrapper' LOGGER.progname = File.expand_path(__FILE__) -- cgit v1.2.3 From ad050ae734ba3c1198f2fde5421d7e69889a0b13 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 2 Mar 2010 11:18:39 +0100 Subject: version bumped to 1.3.1 --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 058fbd8..11eb0de 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem 'opentox-ruby-api-wrapper', '= 1.3.0' +gem 'opentox-ruby-api-wrapper', '= 1.3.1' require 'opentox-ruby-api-wrapper' LOGGER.progname = File.expand_path(__FILE__) -- cgit v1.2.3 From 864c6b88ca3f1709e84e0ce2b4c7147d874ea6e6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 10 Mar 2010 12:00:48 +0100 Subject: newline added to end of uri-lists --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 11eb0de..58cfbd4 100644 --- a/application.rb +++ b/application.rb @@ -28,7 +28,7 @@ DataMapper.auto_upgrade! get '/?' do response['Content-Type'] = 'text/uri-list' - Dataset.all.collect{|d| d.uri}.join("\n") + Dataset.all.collect{|d| d.uri}.join("\n") + "\n" end get '/:id/?' do -- cgit v1.2.3 From 1d3d1a8b9a88639e28663ee7cd505331edd77f78 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 10 Mar 2010 19:17:46 +0100 Subject: owl-dl (temporarily) removed, switched to YAML representation --- application.rb | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/application.rb b/application.rb index 58cfbd4..70ceeee 100644 --- a/application.rb +++ b/application.rb @@ -9,6 +9,7 @@ class Dataset property :id, Serial property :uri, String, :length => 255 property :file, String, :length => 255 + property :yaml, Text, :length => 2**32-1 #property :owl, Text, :length => 1000000 property :created_at, DateTime @@ -42,12 +43,13 @@ get '/:id/?' do accept = request.env['HTTP_ACCEPT'] accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil? case accept - when /rdf/ # redland sends text/rdf instead of application/rdf+xml - response['Content-Type'] = 'application/rdf+xml' - dataset.owl +# when /rdf/ # redland sends text/rdf instead of application/rdf+xml +# response['Content-Type'] = 'application/rdf+xml' +# dataset.owl when /yaml/ response['Content-Type'] = 'application/x-yaml' - OpenTox::Dataset.find(dataset.uri).to_yaml + #OpenTox::Dataset.find(dataset.uri).to_yaml + dataset.yaml else halt 400, "Unsupported MIME type '#{accept}'" end @@ -58,7 +60,8 @@ get '/:id/features/:feature_id/?' do end get '/:id/features/?' do - OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).features + YAML.load(Dataset.get(params[:id]).yaml).features.join("\n") + "\n" + #OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).features end post '/?' do @@ -70,41 +73,40 @@ post '/?' do dataset = Dataset.new dataset.save - uri = url_for("/#{dataset.id}", :full) + dataset.uri = url_for("/#{dataset.id}", :full) content_type = request.content_type content_type = "application/rdf+xml" if content_type.nil? case request.content_type + when /yaml/ + dataset.yaml = request.env["rack.input"].read + when /csv/ + dataset.yaml = csv2yaml request.env["rack.input"].read when "application/rdf+xml" - rdf = request.env["rack.input"].read - d= OpenTox::Dataset.new - d.rdf = rdf - d.uri = uri + dataset.yaml = owl2yaml request.env["rack.input"].read else halt 404, "MIME type \"#{request.content_type}\" not supported." end - LOGGER.debug "Saving dataset #{uri}." + LOGGER.debug "Saving dataset #{dataset.uri}." begin - dataset.owl = d.rdf - dataset.uri = uri dataset.save - task.completed(uri) + task.completed(dataset.uri) rescue => e LOGGER.error e.message LOGGER.info e.backtrace - halt 500, "Could not save dataset #{uri}." + halt 500, "Could not save dataset #{dataset.uri}." end LOGGER.debug "#{dataset.uri} saved." end task.pid = pid #status 303 # rest client tries to redirect response['Content-Type'] = 'text/uri-list' - task.uri + task.uri + "\n" end delete '/:id/?' do begin dataset = Dataset.get(params[:id]) - File.delete dataset.file + #File.delete dataset.file dataset.destroy! response['Content-Type'] = 'text/plain' "Dataset #{params[:id]} deleted." -- cgit v1.2.3 From 725519aeda427984906f9b2a3115615d8272c85c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 15 Mar 2010 13:41:08 +0100 Subject: small modification to internal yaml representation --- application.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/application.rb b/application.rb index 70ceeee..8390d61 100644 --- a/application.rb +++ b/application.rb @@ -10,10 +10,17 @@ class Dataset property :uri, String, :length => 255 property :file, String, :length => 255 property :yaml, Text, :length => 2**32-1 - #property :owl, Text, :length => 1000000 property :created_at, DateTime - def owl +=begin + def to_owl + data = YAML.load(@yaml) + owl = OpenTox::Owl.new + owl.class = 'Dataset' + owl.title = data.title + owl.source = data.source + data.data.each do |compound,features| + feature File.read self.file end @@ -21,6 +28,7 @@ class Dataset self.file = File.join(File.dirname(File.expand_path(__FILE__)),'public',"#{id}.owl") File.open(self.file,"w+") { |f| f.write owl } end +=end end DataMapper.auto_upgrade! @@ -65,11 +73,11 @@ get '/:id/features/?' do end post '/?' do - task = OpenTox::Task.create - pid = Spork.spork(:logger => LOGGER) do +# task = OpenTox::Task.create +# pid = Spork.spork(:logger => LOGGER) do - task.started - LOGGER.debug "Dataset task #{task.uri} started" +# task.started +# LOGGER.debug "Dataset task #{task.uri} started" dataset = Dataset.new dataset.save @@ -89,18 +97,19 @@ post '/?' do LOGGER.debug "Saving dataset #{dataset.uri}." begin dataset.save - task.completed(dataset.uri) +# task.completed(dataset.uri) rescue => e LOGGER.error e.message LOGGER.info e.backtrace halt 500, "Could not save dataset #{dataset.uri}." end LOGGER.debug "#{dataset.uri} saved." - end - task.pid = pid +# end +# task.pid = pid #status 303 # rest client tries to redirect response['Content-Type'] = 'text/uri-list' - task.uri + "\n" +# task.uri + "\n" + dataset.uri + "\n" end delete '/:id/?' do -- cgit v1.2.3 From 2ff8706dd7ee3a0e941c9d05ac3c1d4b3ff81c6e Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Mar 2010 11:05:40 +0100 Subject: toxcreate adapted for new representation --- application.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application.rb b/application.rb index 8390d61..0a1b582 100644 --- a/application.rb +++ b/application.rb @@ -56,7 +56,6 @@ get '/:id/?' do # dataset.owl when /yaml/ response['Content-Type'] = 'application/x-yaml' - #OpenTox::Dataset.find(dataset.uri).to_yaml dataset.yaml else halt 400, "Unsupported MIME type '#{accept}'" @@ -69,7 +68,10 @@ end get '/:id/features/?' do YAML.load(Dataset.get(params[:id]).yaml).features.join("\n") + "\n" - #OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).features +end + +get '/:id/compounds/?' do + YAML.load(Dataset.get(params[:id]).yaml).compounds.join("\n") + "\n" end post '/?' do @@ -97,7 +99,6 @@ post '/?' do LOGGER.debug "Saving dataset #{dataset.uri}." begin dataset.save -# task.completed(dataset.uri) rescue => e LOGGER.error e.message LOGGER.info e.backtrace -- cgit v1.2.3 From 32a1907e922c8784413fa2225b5f279f632b5e6b Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Mar 2010 17:35:34 +0100 Subject: OWL-DL export added --- application.rb | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/application.rb b/application.rb index 0a1b582..be16413 100644 --- a/application.rb +++ b/application.rb @@ -12,23 +12,21 @@ class Dataset property :yaml, Text, :length => 2**32-1 property :created_at, DateTime -=begin def to_owl - data = YAML.load(@yaml) - owl = OpenTox::Owl.new - owl.class = 'Dataset' - owl.title = data.title - owl.source = data.source + data = YAML.load(yaml) + owl = OpenTox::Owl.new 'Dataset', uri + ['title', 'source', 'identifier'].each do |method| + eval "owl.#{method} = data.#{method}" + end data.data.each do |compound,features| - feature - File.read self.file + owl.add_data_entries compound,features + end + owl.rdf end - def owl=(owl) - self.file = File.join(File.dirname(File.expand_path(__FILE__)),'public',"#{id}.owl") - File.open(self.file,"w+") { |f| f.write owl } - end -=end + #def from_owl + #end + end DataMapper.auto_upgrade! @@ -51,9 +49,9 @@ get '/:id/?' do accept = request.env['HTTP_ACCEPT'] accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil? case accept -# when /rdf/ # redland sends text/rdf instead of application/rdf+xml -# response['Content-Type'] = 'application/rdf+xml' -# dataset.owl + when /rdf/ # redland sends text/rdf instead of application/rdf+xml + response['Content-Type'] = 'application/rdf+xml' + dataset.to_owl when /yaml/ response['Content-Type'] = 'application/x-yaml' dataset.yaml @@ -75,11 +73,6 @@ get '/:id/compounds/?' do end post '/?' do -# task = OpenTox::Task.create -# pid = Spork.spork(:logger => LOGGER) do - -# task.started -# LOGGER.debug "Dataset task #{task.uri} started" dataset = Dataset.new dataset.save @@ -105,18 +98,13 @@ post '/?' do halt 500, "Could not save dataset #{dataset.uri}." end LOGGER.debug "#{dataset.uri} saved." -# end -# task.pid = pid - #status 303 # rest client tries to redirect response['Content-Type'] = 'text/uri-list' -# task.uri + "\n" dataset.uri + "\n" end delete '/:id/?' do begin dataset = Dataset.get(params[:id]) - #File.delete dataset.file dataset.destroy! response['Content-Type'] = 'text/plain' "Dataset #{params[:id]} deleted." -- cgit v1.2.3 From 08f484d69ba8538570692c9cbca9a29bffa4e70a Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Mar 2010 19:42:55 +0100 Subject: initial test for dataset prediction added --- application.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/application.rb b/application.rb index be16413..18a21d7 100644 --- a/application.rb +++ b/application.rb @@ -89,7 +89,6 @@ post '/?' do else halt 404, "MIME type \"#{request.content_type}\" not supported." end - LOGGER.debug "Saving dataset #{dataset.uri}." begin dataset.save rescue => e -- cgit v1.2.3 From 6840f6003af7c4317583350c2e50804a448ae8b6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 18 Mar 2010 20:54:24 +0100 Subject: more detailed model information in toxcreate --- application.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/application.rb b/application.rb index 18a21d7..cffcf6b 100644 --- a/application.rb +++ b/application.rb @@ -1,6 +1,9 @@ require 'rubygems' gem 'opentox-ruby-api-wrapper', '= 1.3.1' require 'opentox-ruby-api-wrapper' +#require 'sinatra/respond_to' +#Sinatra::Application.register Sinatra::RespondTo + LOGGER.progname = File.expand_path(__FILE__) @@ -10,12 +13,13 @@ class Dataset property :uri, String, :length => 255 property :file, String, :length => 255 property :yaml, Text, :length => 2**32-1 + property :owl, Text, :length => 2**32-1 property :created_at, DateTime def to_owl data = YAML.load(yaml) owl = OpenTox::Owl.new 'Dataset', uri - ['title', 'source', 'identifier'].each do |method| + ['title', 'source'].each do |method| eval "owl.#{method} = data.#{method}" end data.data.each do |compound,features| @@ -38,7 +42,18 @@ get '/?' do Dataset.all.collect{|d| d.uri}.join("\n") + "\n" end -get '/:id/?' do +get '/:id' do + accept = request.env['HTTP_ACCEPT'] + accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil? + # workaround for browser links + case params[:id] + when /.yaml$/ + params[:id].sub!(/.yaml$/,'') + accept = 'application/x-yaml' + when /.rdf$/ + params[:id].sub!(/.rdf$/,'') + accept = 'application/rdf+xml' + end begin dataset = Dataset.get(params[:id]) rescue => e @@ -46,12 +61,14 @@ get '/:id/?' do LOGGER.warn e.backtrace halt 404, "Dataset #{params[:id]} not found." end - accept = request.env['HTTP_ACCEPT'] - accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil? case accept when /rdf/ # redland sends text/rdf instead of application/rdf+xml response['Content-Type'] = 'application/rdf+xml' - dataset.to_owl + unless dataset.owl # lazy owl creation + dataset.owl = dataset.to_owl + dataset.save + end + dataset.owl when /yaml/ response['Content-Type'] = 'application/x-yaml' dataset.yaml -- cgit v1.2.3 From 7821b0e7c7d97a60b881afff67e557426256eac6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 18 Mar 2010 21:03:38 +0100 Subject: opentox-api-wrapper version bumped to 1.4.0 --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index cffcf6b..2e56233 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem 'opentox-ruby-api-wrapper', '= 1.3.1' +gem 'opentox-ruby-api-wrapper', '= 1.4.0' require 'opentox-ruby-api-wrapper' #require 'sinatra/respond_to' #Sinatra::Application.register Sinatra::RespondTo -- cgit v1.2.3 From 2d58fd80281ddc6a9c061867f3e6930a71df0ffd Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 19 Mar 2010 16:24:41 +0100 Subject: owl parsing implemented --- application.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/application.rb b/application.rb index 2e56233..bd0cea6 100644 --- a/application.rb +++ b/application.rb @@ -18,12 +18,14 @@ class Dataset def to_owl data = YAML.load(yaml) - owl = OpenTox::Owl.new 'Dataset', uri + owl = OpenTox::Owl.create 'Dataset', uri ['title', 'source'].each do |method| eval "owl.#{method} = data.#{method}" end - data.data.each do |compound,features| - owl.add_data_entries compound,features + if data.data + data.data.each do |compound,features| + owl.add_data_entries compound,features + end end owl.rdf end @@ -57,8 +59,7 @@ get '/:id' do begin dataset = Dataset.get(params[:id]) rescue => e - LOGGER.error e.message - LOGGER.warn e.backtrace + raise e.message + e.backtrace halt 404, "Dataset #{params[:id]} not found." end case accept -- cgit v1.2.3