summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-01-22 11:16:13 +0100
committerChristoph Helma <helma@in-silico.de>2010-01-22 11:16:13 +0100
commit09974c5a920bbb07475d8e48a725ef3780e60dbe (patch)
treee0992268d21f872eb554452da4a73d8d3acb9b2c /lib
parentc86df1faf22bcd90a8f318632c368d5ce474dbf8 (diff)
central config.ru, generic compound API
Diffstat (limited to 'lib')
-rw-r--r--lib/compound.rb9
-rw-r--r--lib/model.rb8
-rw-r--r--lib/templates/config.ru18
3 files changed, 18 insertions, 17 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 4385a7d..0a90663 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -20,14 +20,19 @@ module OpenTox
@inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:uri]
- @inchi = params[:uri].sub(/^.*InChI/, 'InChI')
+ if params[:uri].match(/InChI/) # shortcut for IST services
+ @inchi = params[:uri].sub(/^.*InChI/, 'InChI')
+ else
+ @inchi = RestClient.get @uri, :accept => 'chemical/x-inchi'
+ end
@uri = params[:uri]
end
end
# Get the (canonical) smiles
def smiles
- obconversion(@inchi,'inchi','can')
+ RestClient.get(@uri, :accept => 'chemical/x-daylight-smiles').split(/\s+/).first # fix ambit output
+ #obconversion(@inchi,'inchi','can')
end
def sdf
diff --git a/lib/model.rb b/lib/model.rb
index 24f6e52..c4041f2 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -31,6 +31,12 @@ module OpenTox
def self.find_all
RestClient.get(@@config[:services]["opentox-model"]).split("\n")
end
+
+ def self.find(uri)
+ puts uri
+ yaml = RestClient.get(uri, :accept => "application/x-yaml")
+ OpenTox::Model::Lazar.from_yaml(yaml)
+ end
# Predict a compound
def predict(compound)
@@ -46,7 +52,7 @@ module OpenTox
end
def endpoint
- YAML.load(RestClient.get uri)[:endpoint]
+ YAML.load(RestClient.get(uri))[:endpoint]
end
def algorithm=(algorithm)
diff --git a/lib/templates/config.ru b/lib/templates/config.ru
index 63dd2ce..81cea9d 100644
--- a/lib/templates/config.ru
+++ b/lib/templates/config.ru
@@ -1,23 +1,13 @@
require 'rubygems'
-require 'sinatra'
+require 'opentox-ruby-api-wrapper'
require 'application.rb'
require 'rack'
require 'rack/contrib'
-FileUtils.mkdir_p 'log' unless File.exists?('log')
-log = File.new("log/#{ENV["RACK_ENV"]}.log", "a")
+FileUtils.mkdir_p @@tmp_dir
+log = File.new("#{@@tmp_dir}/#{ENV["RACK_ENV"]}.log", "a+")
$stdout.reopen(log)
$stderr.reopen(log)
-if ENV['RACK_ENV'] == 'production'
- use Rack::MailExceptions do |mail|
- mail.to 'helma@in-silico.ch'
- mail.subject '[ERROR] %s'
- end
-elsif ENV['RACK_ENV'] == 'development'
- use Rack::Reloader
- use Rack::ShowExceptions
-end
-
+use Rack::ShowExceptions
run Sinatra::Application
-