From e77cc376aaff8ca481fdace6d5795c5b5feb0e87 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 20 Feb 2012 14:45:20 +0100 Subject: Added pc descriptor calc service --- application.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'application.rb') diff --git a/application.rb b/application.rb index e4f5044..f806271 100644 --- a/application.rb +++ b/application.rb @@ -1,7 +1,19 @@ +ENV["JAVA_HOME"] = "/usr/lib/jvm/java-6-sun" unless ENV["JAVA_HOME"] +ENV["JOELIB2"] = File.join File.expand_path(File.dirname(__FILE__)),"java" +deps = [] +deps << "#{ENV["JAVA_HOME"]}/lib/tools.jar" +deps << "#{ENV["JAVA_HOME"]}/lib/classes.jar" +deps << "#{ENV["JOELIB2"]}" +jars = Dir[ENV["JOELIB2"]+"/*.jar"].collect {|f| File.expand_path(f) } +deps = deps + jars +ENV["CLASSPATH"] = deps.join(":") + + require 'rubygems' gem "opentox-ruby", "~> 3" require 'opentox-ruby' require 'profiler' +require 'rjb' set :lock, true @@ -340,6 +352,29 @@ post '/:id' do halt 202,task.uri.to_s+"\n" end + +# Create PC descriptors +# +# @param [String] pc_type +# @return [text/uri-list] Task ID +post '/:id/pcdesc' do + response['Content-Type'] = 'text/uri-list' + raise "No PC type given" unless params["pc_type"] + + task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do + types = params[:pc_type].split(",") + if types.include?("joelib") + Rjb.load(nil,["-Xmx64m"]) + s = Rjb::import('JoelibFc') + end + OpenTox::Algorithm.pc_descriptors( { :dataset_uri => @uri, :pc_type => params[:pc_type], :rjb => s } ) + end + raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" + halt 202,task.uri.to_s+"\n" +end + + + # Delete a dataset # @return [text/plain] Status message delete '/:id' do -- cgit v1.2.3 From 2b54733514e1c6e91b0397c70b441fc7c92e1db5 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 20 Feb 2012 16:33:40 +0100 Subject: Support for progress (task) --- application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index f806271..735a4d1 100644 --- a/application.rb +++ b/application.rb @@ -361,13 +361,13 @@ post '/:id/pcdesc' do response['Content-Type'] = 'text/uri-list' raise "No PC type given" unless params["pc_type"] - task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do + task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do |task| types = params[:pc_type].split(",") if types.include?("joelib") Rjb.load(nil,["-Xmx64m"]) s = Rjb::import('JoelibFc') end - OpenTox::Algorithm.pc_descriptors( { :dataset_uri => @uri, :pc_type => params[:pc_type], :rjb => s } ) + OpenTox::Algorithm.pc_descriptors( { :dataset_uri => @uri, :pc_type => params[:pc_type], :rjb => s, :task => task } ) end raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" halt 202,task.uri.to_s+"\n" -- cgit v1.2.3 From 5b53700d63ee55ed2e47331fa30723e873f204eb Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Tue, 21 Feb 2012 16:35:07 +0100 Subject: Added description of pcdesc --- application.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 735a4d1..122361d 100644 --- a/application.rb +++ b/application.rb @@ -357,6 +357,32 @@ end # # @param [String] pc_type # @return [text/uri-list] Task ID +get '/:id/pcdesc' do +algorithm = OpenTox::Algorithm::Generic.new(url_for('/dataset/id/pcdesc',:full)) + algorithm.metadata = { + DC.title => 'Physico-chemical (PC) descriptor calculation', + DC.creator => "andreas@maunz.de, vorgrimmlerdavid@gmx.de", + RDF.type => [OT.Algorithm,OTA.PatternMiningSupervised], + OT.parameters => [ + { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" }, + { DC.description => "PC type", OT.paramScope => "mandatory", DC.title => "pc_type" }, + ] + } + case request.env['HTTP_ACCEPT'] + when /text\/html/ + content_type "text/html" + OpenTox.text_to_html algorithm.to_yaml + when /application\/x-yaml/ + content_type "application/x-yaml" + algorithm.to_yaml + else + response['Content-Type'] = 'application/rdf+xml' + algorithm.to_rdfxml + end +end + + + post '/:id/pcdesc' do response['Content-Type'] = 'text/uri-list' raise "No PC type given" unless params["pc_type"] -- cgit v1.2.3 From 6e395672a02d47218bc80769765d588437a12661 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 13 Mar 2012 10:16:00 +0100 Subject: add cleanup method for failed crossvalidations --- application.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'application.rb') diff --git a/application.rb b/application.rb index e4f5044..aa88ecb 100644 --- a/application.rb +++ b/application.rb @@ -340,6 +340,27 @@ post '/:id' do halt 202,task.uri.to_s+"\n" end +# Deletes datasets that have been created by a crossvalidatoin that does not exist anymore +# (This can happen if a crossvalidation fails unexpectedly) +delete '/cleanup' do + Dir["./#{@@datadir}/*json"].each do |file| + dataset = OpenTox::Dataset.from_json File.read(file) + if dataset.metadata[DC.creator] && dataset.metadata[DC.creator] =~ /crossvalidation\/[0-9]/ + begin + cv = OpenTox::Crossvalidation.find(dataset.metadata[DC.creator],@subjectid) + raise unless cv + rescue + LOGGER.debug "deleting #{dataset.uri}, crossvalidation missing: #{dataset.metadata[DC.creator]}" + begin + dataset.delete @subjectid + rescue + end + end + end + end + "cleanup done" +end + # Delete a dataset # @return [text/plain] Status message delete '/:id' do -- cgit v1.2.3 From 859365c570a514b7c33fa446875f42ff1aa62100 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 20 Mar 2012 16:09:30 +0100 Subject: fix id-multithread issue via id-file --- application.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index aa88ecb..5382453 100644 --- a/application.rb +++ b/application.rb @@ -7,11 +7,24 @@ set :lock, true @@datadir = "data" +@@idfile_path = @@datadir+"/id" +unless File.exist?(@@idfile_path) + id = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.last + id = 0 if id.nil? + open(@@idfile_path,"w") do |f| + f.puts(id) + end +end + helpers do def next_id - id = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.last - id = 0 if id.nil? - id + 1 + open(@@idfile_path, "r+") do |f| + f.flock(File::LOCK_EX) + @id = f.gets.to_i + 1 + f.rewind + f.print @id + end + return @id end def uri(id) -- cgit v1.2.3 From e145f4add589228ee9b2aa5500396035668b5085 Mon Sep 17 00:00:00 2001 From: davor Date: Wed, 28 Mar 2012 14:05:59 +0300 Subject: Fixed dataset uri bug in load_dataset. --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 5382453..257d9a0 100644 --- a/application.rb +++ b/application.rb @@ -38,7 +38,7 @@ helpers do raise "store subject-id in dataset-object, not in params" if params.has_key?(:subjectid) and @subjectid==nil content_type = "application/rdf+xml" if content_type.nil? - dataset = OpenTox::Dataset.new(nil, @subjectid) + dataset = OpenTox::Dataset.new(@uri, @subjectid) case content_type -- cgit v1.2.3 From 3cd136861c68b8c24cc653c903c620d55be4b294 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 2 Apr 2012 09:18:14 +0200 Subject: Remove PC descriptor --- application.rb | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index e75c96c..7c76b15 100644 --- a/application.rb +++ b/application.rb @@ -366,54 +366,6 @@ post '/:id' do end -# Create PC descriptors -# -# @param [String] pc_type -# @return [text/uri-list] Task ID -get '/:id/pcdesc' do -algorithm = OpenTox::Algorithm::Generic.new(url_for('/dataset/id/pcdesc',:full)) - algorithm.metadata = { - DC.title => 'Physico-chemical (PC) descriptor calculation', - DC.creator => "andreas@maunz.de, vorgrimmlerdavid@gmx.de", - RDF.type => [OT.Algorithm,OTA.PatternMiningSupervised], - OT.parameters => [ - { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" }, - { DC.description => "PC type", OT.paramScope => "mandatory", DC.title => "pc_type" }, - ] - } - case request.env['HTTP_ACCEPT'] - when /text\/html/ - content_type "text/html" - OpenTox.text_to_html algorithm.to_yaml - when /application\/x-yaml/ - content_type "application/x-yaml" - algorithm.to_yaml - else - response['Content-Type'] = 'application/rdf+xml' - algorithm.to_rdfxml - end -end - - - -post '/:id/pcdesc' do - response['Content-Type'] = 'text/uri-list' - raise "No PC type given" unless params["pc_type"] - - task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do |task| - types = params[:pc_type].split(",") - if types.include?("joelib") - Rjb.load(nil,["-Xmx64m"]) - s = Rjb::import('JoelibFc') - end - OpenTox::Algorithm.pc_descriptors( { :dataset_uri => @uri, :pc_type => params[:pc_type], :rjb => s, :task => task } ) - end - raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" - halt 202,task.uri.to_s+"\n" -end - - - # Deletes datasets that have been created by a crossvalidatoin that does not exist anymore # (This can happen if a crossvalidation fails unexpectedly) delete '/cleanup' do -- cgit v1.2.3 From 8de6b3ff0ee08c971c583a50d349a1db4b8638bc Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 2 Apr 2012 09:27:48 +0200 Subject: Removed Java ENV --- application.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 7c76b15..730ef7d 100644 --- a/application.rb +++ b/application.rb @@ -1,14 +1,3 @@ -ENV["JAVA_HOME"] = "/usr/lib/jvm/java-6-sun" unless ENV["JAVA_HOME"] -ENV["JOELIB2"] = File.join File.expand_path(File.dirname(__FILE__)),"java" -deps = [] -deps << "#{ENV["JAVA_HOME"]}/lib/tools.jar" -deps << "#{ENV["JAVA_HOME"]}/lib/classes.jar" -deps << "#{ENV["JOELIB2"]}" -jars = Dir[ENV["JOELIB2"]+"/*.jar"].collect {|f| File.expand_path(f) } -deps = deps + jars -ENV["CLASSPATH"] = deps.join(":") - - require 'rubygems' gem "opentox-ruby", "~> 3" require 'opentox-ruby' -- cgit v1.2.3 From f6e6aa0a1fb60fdb8cd4c96aa488a6c376606c83 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Thu, 5 Apr 2012 15:12:42 +0200 Subject: Uploading master via RestClient --- application.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 730ef7d..4df696c 100644 --- a/application.rb +++ b/application.rb @@ -49,6 +49,9 @@ helpers do when /json/ dataset.load_json(input_data) + when "text/csv" + dataset.load_csv(input_data, @subjectid) + when /application\/rdf\+xml/ dataset.load_rdfxml(input_data, @subjectid) -- cgit v1.2.3 From 4f82f43d02b40809f6bff5763c694a9816f546d4 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 25 Apr 2012 10:50:39 +0200 Subject: fix content-type for json --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 4df696c..bda0ff9 100644 --- a/application.rb +++ b/application.rb @@ -185,7 +185,7 @@ get '/:id' do send_file file, :type => 'application/rdf+xml' when /json/ - send_file @json_file, :type => 'application/x-yaml' + send_file @json_file, :type => 'application/json' when /yaml/ file = "#{@@datadir}/#{params[:id]}.yaml" -- cgit v1.2.3 From 8ae034b1ac96b12ebe9c2379d275a73c226f7f49 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Thu, 12 Jul 2012 10:54:48 +0200 Subject: switch to opentox-ruby version 4.0.0 , remove EOL whitespace, update ChangeLog --- application.rb | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index bda0ff9..d4bd78a 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem "opentox-ruby", "~> 3" +gem "opentox-ruby", "~> 4" require 'opentox-ruby' require 'profiler' require 'rjb' @@ -8,7 +8,7 @@ set :lock, true @@datadir = "data" -@@idfile_path = @@datadir+"/id" +@@idfile_path = @@datadir+"/id" unless File.exist?(@@idfile_path) id = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.last id = 0 if id.nil? @@ -39,7 +39,7 @@ helpers do raise "store subject-id in dataset-object, not in params" if params.has_key?(:subjectid) and @subjectid==nil content_type = "application/rdf+xml" if content_type.nil? - dataset = OpenTox::Dataset.new(@uri, @subjectid) + dataset = OpenTox::Dataset.new(@uri, @subjectid) case content_type @@ -54,7 +54,7 @@ helpers do when /application\/rdf\+xml/ dataset.load_rdfxml(input_data, @subjectid) - + when "chemical/x-mdl-sdfile" dataset.load_sdf(input_data, @subjectid) @@ -149,9 +149,9 @@ before do end end end - + # make sure subjectid is not included in params, subjectid is set as member variable - params.delete(:subjectid) + params.delete(:subjectid) end ## REST API @@ -159,7 +159,7 @@ end # Get a list of available datasets # @return [text/uri-list] List of available datasets get '/?' do - uri_list = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.collect{|n| uri n}.join("\n") + "\n" + uri_list = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.collect{|n| uri n}.join("\n") + "\n" case @accept when /html/ response['Content-Type'] = 'text/html' @@ -185,7 +185,7 @@ get '/:id' do send_file file, :type => 'application/rdf+xml' when /json/ - send_file @json_file, :type => 'application/json' + send_file @json_file, :type => 'application/json' when /yaml/ file = "#{@@datadir}/#{params[:id]}.yaml" @@ -193,11 +193,11 @@ get '/:id' do dataset = OpenTox::Dataset.from_json File.read(@json_file) File.open(file,"w+") { |f| f.puts dataset.to_yaml } end - send_file file, :type => 'application/x-yaml' + send_file file, :type => 'application/x-yaml' when /html/ response['Content-Type'] = 'text/html' - OpenTox.text_to_html JSON.pretty_generate(JSON.parse(File.read(@json_file))) + OpenTox.text_to_html JSON.pretty_generate(JSON.parse(File.read(@json_file))) when "text/csv" response['Content-Type'] = 'text/csv' @@ -225,7 +225,7 @@ end # @return [application/rdf+xml] Metadata OWL-DL get '/:id/metadata' do metadata = OpenTox::Dataset.from_json(File.read(@json_file)).metadata - + case @accept when /rdf/ # redland sends text/rdf instead of application/rdf+xml response['Content-Type'] = 'application/rdf+xml' @@ -241,7 +241,7 @@ end # Get a dataset feature # @param [Header] Accept one of `application/rdf+xml or application-x-yaml` (default application/rdf+xml) -# @return [application/rdf+xml,application/x-yaml] Feature metadata +# @return [application/rdf+xml,application/x-yaml] Feature metadata get %r{/(\d+)/feature/(.*)$} do |id,feature| @id = id @@ -249,7 +249,7 @@ get %r{/(\d+)/feature/(.*)$} do |id,feature| @json_file = "#{@@datadir}/#{@id}.json" feature_uri = url_for("/#{@id}/feature/#{URI.encode(feature)}",:full) # work around racks internal uri decoding metadata = OpenTox::Dataset.from_json(File.read(@json_file)).features[feature_uri] - + case @accept when /rdf/ # redland sends text/rdf instead of application/rdf+xml response['Content-Type'] = 'application/rdf+xml' @@ -268,7 +268,7 @@ end # Get a list of all features # @param [Header] Accept one of `application/rdf+xml, application-x-yaml, text/uri-list` (default application/rdf+xml) -# @return [application/rdf+xml, application-x-yaml, text/uri-list] Feature list +# @return [application/rdf+xml, application-x-yaml, text/uri-list] Feature list get '/:id/features' do features = OpenTox::Dataset.from_json(File.read(@json_file)).features @@ -292,7 +292,7 @@ get '/:id/features' do end # Get a list of all compounds -# @return [text/uri-list] Feature list +# @return [text/uri-list] Feature list get '/:id/compounds' do response['Content-Type'] = 'text/uri-list' OpenTox::Dataset.from_json(File.read(@json_file)).compounds.join("\n") + "\n" @@ -309,12 +309,12 @@ end # curl -X POST -F "file=@training.csv;type=text/csv" http://webservices.in-silico.ch/dataset # @param [Header] Content-type one of `application/x-yaml, application/rdf+xml, multipart/form-data/` # @param [BODY] - string with data in selected Content-type -# @param [optional] file, for file uploads, Content-type should be multipart/form-data, please specify the file type `application/rdf+xml, application-x-yaml, text/csv, application/ms-excel` +# @param [optional] file, for file uploads, Content-type should be multipart/form-data, please specify the file type `application/rdf+xml, application-x-yaml, text/csv, application/ms-excel` # @return [text/uri-list] Task URI or Dataset URI (empty datasets) -post '/?' do +post '/?' do response['Content-Type'] = 'text/uri-list' - + # it could be that the read function works only once!, store in varible input_data = request.env["rack.input"].read @id = next_id @@ -325,8 +325,8 @@ post '/?' do OpenTox::Authorization.check_policy(@uri, @subjectid) if File.exists? @json_file @uri else - task = OpenTox::Task.create("Converting and saving dataset ", @uri) do - load_dataset @id, params, request.content_type, input_data + task = OpenTox::Task.create("Converting and saving dataset ", @uri) do + load_dataset @id, params, request.content_type, input_data OpenTox::Authorization.check_policy(@uri, @subjectid) if File.exists? @json_file @uri end @@ -344,13 +344,13 @@ end # curl -X POST -F "file=@training.csv;type=text/csv" http://webservices.in-silico.ch/dataset/1 # @param [Header] Content-type one of `application/x-yaml, application/rdf+xml, multipart/form-data/` # @param [BODY] - string with data in selected Content-type -# @param [optional] file, for file uploads, Content-type should be multipart/form-data, please specify the file type `application/rdf+xml, application-x-yaml, text/csv, application/ms-excel` -# @return [text/uri-list] Task ID -post '/:id' do +# @param [optional] file, for file uploads, Content-type should be multipart/form-data, please specify the file type `application/rdf+xml, application-x-yaml, text/csv, application/ms-excel` +# @return [text/uri-list] Task ID +post '/:id' do response['Content-Type'] = 'text/uri-list' - task = OpenTox::Task.create("Converting and saving dataset ", @uri) do + task = OpenTox::Task.create("Converting and saving dataset ", @uri) do FileUtils.rm Dir["#{@@datadir}/#{@id}.*"] - load_dataset @id, params, request.content_type, request.env["rack.input"].read + load_dataset @id, params, request.content_type, request.env["rack.input"].read @uri end raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" @@ -374,9 +374,9 @@ delete '/cleanup' do rescue end end - end + end end - "cleanup done" + "cleanup done" end # Delete a dataset -- cgit v1.2.3