summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-09-10 15:21:09 +0200
committerChristoph Helma <helma@in-silico.de>2009-09-10 15:21:09 +0200
commit59249a0febc2f90cd1643ddb7e3baa68e3f49065 (patch)
treeb9395e815c677e7af59f4a27c596521aee215354
parent285daeaafa3bdff027bc068be9a13232fca3e35d (diff)
initial wrapper for new webservices
-rw-r--r--lib/algorithm.rb16
-rw-r--r--lib/compound.rb4
-rw-r--r--lib/dataset.rb54
-rw-r--r--lib/feature.rb7
-rw-r--r--lib/model.rb3
-rw-r--r--lib/opentox-ruby-api-wrapper.rb32
-rw-r--r--lib/tasks/opentox.rb3
7 files changed, 52 insertions, 67 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 912e14d..33731af 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -3,23 +3,19 @@ module OpenTox
class Fminer < OpenTox
# Create a new dataset with BBRC features
- def initialize(training_dataset)
- @uri = RestClient.post @@config[:services]["opentox-fminer"], :dataset_uri => training_dataset.uri
+ def self.create(training_dataset_uri)
+ RestClient.post @@config[:services]["opentox-fminer"], :dataset_uri => training_dataset_uri
end
end
class Similarity < OpenTox
- def initialize
- @uri = @@config[:services]["opentox-similarity"]
+ def self.tanimoto(dataset1,compound1,dataset2,compound2)
+ RestClient.get File.join(@@config[:services]["opentox-dataset"], 'algorithm/tanimoto/dataset',dataset1.name,compound1.inchi,'dataset',dataset2.name,compound2.inchi)
end
- def self.tanimoto(dataset,compounds)
- RestClient.post @uri + 'tanimoto', :dataset_uri => dataset.uri, :compound_uris => compounds.collect{ |c| c.uri }
- end
-
- def self.weighted_tanimoto(dataset,compounds)
- RestClient.post @uri + 'weighted_tanimoto', :dataset_uri => dataset.uri, :compound_uris => compounds.collect{ |c| c.uri }
+ 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))
end
end
diff --git a/lib/compound.rb b/lib/compound.rb
index 4652770..67c8004 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -44,8 +44,8 @@ module OpenTox
end
# Match an array of smarts features, returns matching features
- def match(smarts_features)
- smarts_features.all_features.collect{ |smarts| smarts if self.match?(smarts.name) }.compact
+ def match(smarts_dataset)
+ smarts_dataset.all_features.collect{ |uri| uri if self.match?(Feature.new(:uri => uri).name) }.compact
end
def smiles2inchi(smiles)
diff --git a/lib/dataset.rb b/lib/dataset.rb
index ca82f11..f6d0dd7 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -4,7 +4,7 @@ module OpenTox
# set: dataset uris
# key: /dataset/:dataset/compounds
# set: compound uris
- # key: /dataset/:dataset/compound/:inchi/:feature_type
+ # key: /dataset/:dataset/compound/:inchi
# set: feature uris
class Dataset < OpenTox
@@ -19,31 +19,32 @@ module OpenTox
end
def self.find(params)
- if params[:name]
- uri = RestClient.get File.join(@@config[:services]["opentox-dataset"], params[:name])
- elsif params[:uri]
- uri = params[:uri]
- end
- if RestClient.get uri
- Dataset.new(uri)
- else
+ begin
+ if params[:name]
+ uri = File.join(@@config[:services]["opentox-dataset"], URI.encode(params[:name]))
+ elsif params[:uri]
+ uri = params[:uri]
+ end
+ RestClient.get uri # check if the resource is available
+ Dataset.new(uri) if uri
+ rescue
nil
end
end
+ def self.find_or_create(params)
+ self.create(params) unless self.find(params)
+ end
+
def import(params)
if params[:csv]
# RestClient seems not to work for file uploads
- `curl -X POST -F "file=@#{params[:csv]};type=text/csv" -F compound_format=#{params[:compound_format]} -F feature_type=#{params[:feature_type]} #{@uri + '/import'}`
+ `curl -X POST -F "file=@#{params[:csv]};type=text/csv" -F compound_format=#{params[:compound_format]} #{@uri + '/import'}`
end
end
- def add_features(features,feature_type)
- #puts @uri
- #puts feature_type
- #puts features.to_yaml
- HTTPClient.post @uri, {:feature_type => feature_type, :features => features.to_yaml}
- #`curl -X POST -F feature_type="#{feature_type}" -F features="#{features.to_yaml}" #{@uri}`
+ def add(features)
+ HTTPClient.post @uri, {:features => features.to_yaml}
end
# Get all compounds from a dataset
@@ -56,14 +57,17 @@ module OpenTox
end
# Get all features for a compound
- def feature_uris(compound,feature_type)
- #puts File.join(@uri, 'compound', compound.inchi, feature_type)
- RestClient.get(File.join(@uri, 'compound', compound.inchi, feature_type)).split("\n")
+ def feature_uris(compound)
+ RestClient.get(File.join(@uri, 'compound', compound.inchi)).split("\n")
end
# Get all features for a compound
- def features(compound,feature_type)
- feature_uris(compound,feature_type).collect{|uri| Feature.new(:uri => uri)}
+ def features(compound)
+ feature_uris(compound).collect{|uri| Feature.new(:uri => uri)}
+ end
+
+ def all_features
+ RestClient.get(File.join(@uri, 'features')).split("\n")
end
# Delete a dataset
@@ -71,6 +75,14 @@ module OpenTox
RestClient.delete @uri
end
+ def tanimoto(dataset)
+ RestClient.get(File.join(@uri,'tanimoto',dataset.path))
+ end
+
+ def weighted_tanimoto(dataset)
+ RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path))
+ end
+
end
end
diff --git a/lib/feature.rb b/lib/feature.rb
index 0cad7c0..8b0839f 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -9,15 +9,16 @@ module OpenTox
if params[:uri]
@uri = params[:uri]
items = URI.split(@uri)[5].split(/\//)
- @name = items[1]
+ @name = items[2]
@values = {}
- i = 3
+ i = 4
while i < items.size
@values[items[i]] = items[i+1]
i += 2
end
else
- @name = URI.encode(URI.decode(params[:name]))
+ @name = params[:name]
+ #@name = URI.encode(URI.decode(params[:name]))
@values = params[:values]
@uri = File.join(@@config[:services]["opentox-dataset"],"feature",path)
end
diff --git a/lib/model.rb b/lib/model.rb
index 7f43860..c50a458 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -1,4 +1,7 @@
module OpenTox
+
+ # key: /models
+ # set: dataset uris
module Model
class Lazar < OpenTox
diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb
index e504e65..9d7e5e5 100644
--- a/lib/opentox-ruby-api-wrapper.rb
+++ b/lib/opentox-ruby-api-wrapper.rb
@@ -1,36 +1,8 @@
#['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', 'spork', 'environment', 'openbabel', 'httpclient'].each do |lib|
+['rubygems', 'sinatra', 'sinatra/url_for', 'builder', 'rest_client', 'yaml', 'environment', 'openbabel', 'httpclient'].each do |lib|
require lib
end
-module OpenTox
-
- class OpenTox
- attr_reader :uri
-
- def initialize(uri)
- @uri = uri
- end
-
- # Get the object name
- def name
- RestClient.get @uri + '/name'
- end
-
- # Deletes an object
- def destroy
- RestClient.delete @uri
- end
-
- # Object path without hostname
- def path
- URI.split(@uri)[5]
- end
-
- end
-
-end
-
-['compound','feature','dataset','algorithm','model','utils'].each do |lib|
+['opentox', 'compound','feature','dataset','algorithm','model','utils'].each do |lib|
require lib
end
diff --git a/lib/tasks/opentox.rb b/lib/tasks/opentox.rb
index afb8cb6..0dace9a 100644
--- a/lib/tasks/opentox.rb
+++ b/lib/tasks/opentox.rb
@@ -19,7 +19,8 @@ namespace :opentox do
@@config[:services].each do |service,uri|
dir = File.join(@@config[:base_dir], service)
server = @@config[:webserver]
- `redis-server &`
+ #puts "Starting Redis database"
+ #puts `redis-server /etc/redis.conf &`
case server
when /thin|mongrel|webrick/
port = uri.sub(/^.*:/,'').sub(/\/$/,'')