summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2011-03-09 14:11:39 +0100
committerChristoph Helma <helma@in-silico.ch>2011-03-09 14:11:39 +0100
commitd7a018b4a96d67f835a5096f4fdc821c5bc6c946 (patch)
tree724620675973f2726a8a4c8115d9aab98ca35634
parentdbb2e0c8e0c1442523c1a72f7587d4ebe54a1542 (diff)
parent431a1abe3ed7327704e22bc45ef9968b6ef8949a (diff)
Merge branch 'release/v1.0.0'
-rw-r--r--Rakefile3
-rw-r--r--application.rb147
-rw-r--r--config.ru4
3 files changed, 59 insertions, 95 deletions
diff --git a/Rakefile b/Rakefile
index fbfcd62..d43e8f3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,7 +1,6 @@
require 'rubygems'
require 'rake'
-require 'opentox-ruby-api-wrapper'
-#require 'tasks/opentox'
+require 'opentox-ruby'
@gems = "sinatra rest-client emk-sinatra-url-for sinatra-respond_to"
diff --git a/application.rb b/application.rb
index 58106d1..0a3794a 100644
--- a/application.rb
+++ b/application.rb
@@ -7,130 +7,93 @@ ENV["CLASSPATH"] = "#{ENV["CLASSPATH"]}:#{java_dir}:#{cdk}:#{jchempaint}"
require 'rubygems'
require 'rjb'
-gem "opentox-ruby-api-wrapper", "= 1.6.5"
-require 'opentox-ruby-api-wrapper'
+gem "opentox-ruby", "~> 1"
+require 'opentox-ruby'
-#set :lock, true # avoid JVM memory allocation problems
-# -Xmx64m
-
-get "/display/activating/(.+)$" do
- content_type "image/png"
- attachment "#{params["smiles"]}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(params["smiles"],150)
- s.match_activating(params["smarts"])
- s.show
-end
-
-post "/display/deactivating" do
- content_type "image/png"
- attachment "#{params["smiles"]}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(params["smiles"],150)
- s.match_deactivating(params["smarts"])
- s.show
-end
-
-get %r{/smiles/(.+)/smarts/activating/(.*)/deactivating/(.*)/highlight/(.*)$} do |smiles,activating,deactivating,smarts|
- activating = activating.to_s.split(/\//).collect{|s| s.gsub(/"/,'')}
- deactivating = deactivating.to_s.split(/\//).collect{|s| s.gsub(/"/,'')}
- content_type "image/png"
- attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(smiles,150)
- s.match_deactivating(deactivating) unless deactivating.empty?
- s.match_activating(activating) unless activating.empty?
- s.match(smarts)
- s.show
- #s = nil
+before do
+ @inchi = URI.unescape request.env['REQUEST_URI'].sub(/^\//,'').sub(/.*compound\//,'').sub(/\/smarts.*$/,'').sub(/\/image/,'') # hack to avoid sinatra's URI/CGI unescaping, splitting, ..."
end
-get %r{/smiles/(.+)/smarts/activating/(.*)/deactivating/(.*)$} do |smiles,activating,deactivating|
+# Display activating (red) and deactivating (green) substructures. Overlaps betwen activating and deactivating structures are marked in yellow.
+# @example
+# curl http://webservices.in-silico.ch/compound/compound/InChI=1S/C6H5NO2/c8-7(9)6-4-2-1-3-5-6/h1-5H/smarts/activating/cN/ccN/deactivating/cc" > img.png
+# @return [image/png] Image with highlighted substructures
+get %r{/(.+)/smarts/activating/(.*)/deactivating/(.*)$} do |inchi,activating,deactivating|
+ smiles = OpenTox::Compound.from_inchi(@inchi).to_smiles
activating = activating.to_s.split(/\//).collect{|s| s.gsub(/"/,'')}
deactivating = deactivating.to_s.split(/\//).collect{|s| s.gsub(/"/,'')}
content_type "image/png"
attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(smiles,150)
- s.match_deactivating(deactivating)
- s.match_activating(activating)
- s.show
- #s = nil
-end
-
-get %r{/smiles/(.+)/smarts/(.*)/(.*activating)$} do |smiles,allsmarts,effect|
- LOGGER.debug "String:"
- LOGGER.debug allsmarts
- smarts = allsmarts.to_s.split(/\//)
- smarts.collect!{|s| s.gsub(/"/,'')}
- LOGGER.debug "Smarts:"
- LOGGER.debug smarts.to_yaml
- content_type "image/png"
- attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(smiles,150)
- if effect == "activating"
- s.match_activating(smarts)
- elsif effect == "deactivating"
- s.match_deactivating(smarts)
+ begin
+ Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
+ s = Rjb::import('Structure').new(smiles,150)
+ s.match_deactivating(deactivating)
+ s.match_activating(activating)
+ s.show
+ rescue => e
+ LOGGER.warn e.message
end
- s.show
end
-get %r{/smiles/(.+)/smarts/(.*)$} do |smiles,smarts|
- content_type "image/png"
- attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- s = Rjb::import('Structure').new(smiles,150)
- s.match(smarts)
- s.show
-end
-
-get %r{/smiles/(.+)} do |smiles|
+# Get png image
+# @return [image/png] Image data
+get %r{/(.+)/image} do |inchi| # catches all remaining get requests
+ smiles = OpenTox::Compound.from_inchi(@inchi).to_smiles
content_type "image/png"
attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- Rjb::import('Structure').new(smiles,150).show
-end
-
-get %r{/(.+)/image} do |inchi| # catches all remaining get requests
- smiles = OpenTox::Compound.new(:inchi => inchi).smiles
- content_type "image/png"
- attachment "#{smiles}.png"
- Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
- Rjb::import('Structure').new(smiles,150).show
+ begin
+ Rjb.load(nil,["-Xmx64m"])# avoid JVM memory allocation problems
+ Rjb::import('Structure').new(smiles,150).show
+ rescue
+ LOGGER.warn e.message
+ end
end
+# Get compound representation
+# @param [optinal, HEADER] Accept one of `chemical/x-daylight-smiles, chemical/x-inchi, chemical/x-mdl-sdfile, chemical/x-mdl-molfile, text/plain, image/gif, image/png`, defaults to chemical/x-daylight-smiles
+# @example Get smiles
+# curl http://webservices.in-silico.ch/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H
+# @example Get all known names
+# curl -H "Accept:text/plain" http://webservices.in-silico.ch/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H
+# @return [chemical/x-daylight-smiles, chemical/x-inchi, chemical/x-mdl-sdfile, chemical/x-mdl-molfile, text/plain, image/gif, image/png] Compound representation
get %r{/(.+)} do |inchi| # catches all remaining get requests
- inchi = URI.unescape request.env['REQUEST_URI'].sub(/^\//,'').sub(/.*compound\//,'') # hack to avoid sinatra's URI/CGI unescaping, splitting, ..."
+ #inchi = URI.unescape request.env['REQUEST_URI'].sub(/^\//,'').sub(/.*compound\//,'') # hack to avoid sinatra's URI/CGI unescaping, splitting, ..."
case request.env['HTTP_ACCEPT']
when "*/*"
response['Content-Type'] = "chemical/x-daylight-smiles"
- OpenTox::Compound.new(:inchi => inchi).smiles
+ OpenTox::Compound.from_inchi(@inchi).to_smiles
when "chemical/x-daylight-smiles"
response['Content-Type'] = "chemical/x-daylight-smiles"
- OpenTox::Compound.new(:inchi => inchi).smiles
+ OpenTox::Compound.from_inchi(@inchi).to_smiles
when "chemical/x-inchi"
response['Content-Type'] = "chemical/x-inchi"
- inchi
+ @inchi
when "chemical/x-mdl-sdfile"
response['Content-Type'] = "chemical/x-mdl-sdfile"
- OpenTox::Compound.new(:inchi => inchi).sdf
+ OpenTox::Compound.from_inchi(@inchi).to_sdf
when "image/gif"
response['Content-Type'] = "image/gif"
- OpenTox::Compound.new(:inchi => inchi).gif
+ OpenTox::Compound.from_inchi(@inchi).to_gif
when "image/png"
response['Content-Type'] = "image/png"
- OpenTox::Compound.new(:inchi => inchi).png
+ OpenTox::Compound.from_inchi(@inchi).to_png
when "text/plain"
response['Content-Type'] = "text/plain"
- uri = File.join @@cactus_uri,inchi,"names"
+ uri = File.join @@cactus_uri,@inchi,"names"
RestClient.get(uri).body
else
halt 400, "Unsupported MIME type '#{request.env['HTTP_ACCEPT']}'"
end
end
+# Create a new compound URI (compounds are not saved at the compound service)
+# @param [HEADER] Content-type one of `chemical/x-daylight-smiles, chemical/x-inchi, chemical/x-mdl-sdfile, chemical/x-mdl-molfile, text/plain`
+# @example Create compound from Smiles string
+# curl -X POST -H "Content-type:chemical/x-daylight-smiles" --data "c1ccccc1" http://webservices.in-silico.ch/compound
+# @example Create compound from name, uses an external lookup service and should work also with trade names, CAS numbers, ...
+# curl -X POST -H "Content-type:text/plain" --data "Benzene" http://webservices.in-silico.ch/compound
+# @param [BODY] - string with identifier/data in selected Content-type
+# @return [text/uri-list] compound URI
post '/?' do
input = request.env["rack.input"].read
@@ -138,13 +101,13 @@ post '/?' do
begin
case request.content_type
when /chemical\/x-daylight-smiles/
- OpenTox::Compound.new(:smiles => input).uri + "\n"
+ OpenTox::Compound.from_smiles(input).uri + "\n"
when /chemical\/x-inchi/
- OpenTox::Compound.new(:inchi => input).uri + "\n"
+ OpenTox::Compound.from_inchi(input).uri + "\n"
when /chemical\/x-mdl-sdfile|chemical\/x-mdl-molfile/
- OpenTox::Compound.new(:sdf => input).uri + "\n"
+ OpenTox::Compound.from_sdf(input).uri + "\n"
when /text\/plain/
- OpenTox::Compound.new(:name => input).uri + "\n"
+ OpenTox::Compound.from_name(input).uri + "\n"
else
status 400
"Unsupported MIME type '#{request.content_type}'"
diff --git a/config.ru b/config.ru
index ec0402a..a1aab0d 100644
--- a/config.ru
+++ b/config.ru
@@ -1,4 +1,6 @@
require 'rubygems'
-require 'opentox-ruby-api-wrapper'
+require 'opentox-ruby'
require 'config/config_ru'
run Sinatra::Application
+set :raise_errors, false
+set :show_exceptions, false \ No newline at end of file