summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-09-11 23:55:32 +0200
committerChristoph Helma <helma@in-silico.de>2009-09-11 23:55:32 +0200
commitabd0e1ae7b933cbd1c1907dd9e7f1ce1782cf743 (patch)
treebf394da92dca45b292aa4635dc097c26e63bfab6 /lib
parent59249a0febc2f90cd1643ddb7e3baa68e3f49065 (diff)
InChI escaping fixed
Diffstat (limited to 'lib')
-rw-r--r--lib/algorithm.rb4
-rw-r--r--lib/dataset.rb6
-rw-r--r--lib/model.rb8
-rw-r--r--lib/opentox-ruby-api-wrapper.rb5
4 files changed, 17 insertions, 6 deletions
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