From abd0e1ae7b933cbd1c1907dd9e7f1ce1782cf743 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 11 Sep 2009 23:55:32 +0200 Subject: InChI escaping fixed --- Rakefile | 2 +- lib/algorithm.rb | 4 +++- lib/dataset.rb | 6 ++++-- lib/model.rb | 8 ++++++++ lib/opentox-ruby-api-wrapper.rb | 5 ++--- opentox-ruby-api-wrapper.gemspec | 11 ++++++----- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 675ac64..6f71f5d 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ begin gem.email = "helma@in-silico.ch" gem.homepage = "http://github.com/helma/opentox-ruby-api-wrapper" gem.authors = ["Christoph Helma"] - gem.add_dependency "rest-client" + gem.add_dependency "technoweenie-rest-client" gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] gem.files.include %w(lib/tasks/opentox.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/feature.rb, lib/model.rb, lib/utils.rb, lib/templates/*) # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 33731af..7007e3a 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -15,7 +15,9 @@ module OpenTox end def self.weighted_tanimoto(dataset1,compound1,dataset2,compound2) - RestClient.get URI.encode(File.join(@@config[:services]["opentox-dataset"], 'algorithm/weighted_tanimoto/dataset',dataset1.name,'compound',compound1.inchi,'dataset',dataset2.name,'compound',compound2.inchi)) + # URI.escape does not work here + uri = File.join(@@config[:services]["opentox-dataset"], 'algorithm/weighted_tanimoto/dataset',CGI.escape(dataset1.name),'compound',CGI.escape(compound1.inchi),'dataset',CGI.escape(dataset2.name),'compound',CGI.escape(compound2.inchi)) + RestClient.get uri end end diff --git a/lib/dataset.rb b/lib/dataset.rb index f6d0dd7..b635985 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -39,12 +39,13 @@ module OpenTox def import(params) if params[:csv] # RestClient seems not to work for file uploads + #RestClient.post @uri + '/import', :compound_format => params[:compound_format], :content_type => "text/csv", :file => File.new(params[:csv]) `curl -X POST -F "file=@#{params[:csv]};type=text/csv" -F compound_format=#{params[:compound_format]} #{@uri + '/import'}` end end def add(features) - HTTPClient.post @uri, {:features => features.to_yaml} + RestClient.post @uri, :features => features.to_yaml end # Get all compounds from a dataset @@ -58,7 +59,8 @@ module OpenTox # Get all features for a compound def feature_uris(compound) - RestClient.get(File.join(@uri, 'compound', compound.inchi)).split("\n") + uri = File.join(@uri, 'compound', CGI.escape(compound.inchi)) # URI.encode does not work here + RestClient.get(uri).split("\n") end # Get all features for a compound diff --git a/lib/model.rb b/lib/model.rb index c50a458..0fa3be6 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -11,6 +11,14 @@ module OpenTox super(params[:uri]) end + def self.find(name) + RestClient.get File.join(@@config[:services]["opentox-lazar"], 'model', URI.encode(params[:name])) + end + + def self.find_all + RestClient.get File.join(@@config[:services]["opentox-lazar"], 'models')#.split("\n") + end + # Predict a compound def predict(compound) LazarPrediction.new(:uri => RestClient.post(@uri, :compound_uri => compound.uri)) diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb index 9d7e5e5..fd68e72 100644 --- a/lib/opentox-ruby-api-wrapper.rb +++ b/lib/opentox-ruby-api-wrapper.rb @@ -1,8 +1,7 @@ -#['rubygems', 'sinatra', 'sinatra/respond_to', 'sinatra/url_for', 'builder', 'rest_client', 'yaml', 'spork', 'environment', 'openbabel', 'httpclient'].each do |lib| -['rubygems', 'sinatra', 'sinatra/url_for', 'builder', 'rest_client', 'yaml', 'environment', 'openbabel', 'httpclient'].each do |lib| +['rubygems', 'sinatra', 'sinatra/url_for', 'builder', 'rest_client', 'yaml', 'cgi', 'openbabel'].each do |lib| require lib end -['opentox', 'compound','feature','dataset','algorithm','model','utils'].each do |lib| +['environment', 'opentox', 'compound','feature','dataset','algorithm','model','utils'].each do |lib| require lib end diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec index 7ef0252..fd8094f 100644 --- a/opentox-ruby-api-wrapper.gemspec +++ b/opentox-ruby-api-wrapper.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{opentox-ruby-api-wrapper} - s.version = "0.2.2" + s.version = "1.0.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Christoph Helma"] - s.date = %q{2009-09-08} + s.date = %q{2009-09-11} s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)} s.email = %q{helma@in-silico.ch} s.extra_rdoc_files = [ @@ -29,6 +29,7 @@ Gem::Specification.new do |s| "lib/helper.rb", "lib/model.rb", "lib/opentox-ruby-api-wrapper.rb", + "lib/opentox.rb", "lib/spork.rb", "lib/tasks/opentox.rb", "lib/templates/config.ru", @@ -57,11 +58,11 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) end end -- cgit v1.2.3