From 610aaaf543fbc06ed3173011750b48001dc5003c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 11 Dec 2012 12:22:52 +0100 Subject: working version with proxy --- application.rb | 94 +++++++++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 50 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 68bb8d2..9162fcf 100644 --- a/application.rb +++ b/application.rb @@ -1,25 +1,21 @@ +require "./pug.rb" require "./pubchem.rb" -require 'rack/session/dalli' -require "rack/cache" module OpenTox - class Application < Service + class Application < Sinatra::Base + set :static, true set :root, File.dirname(__FILE__) - also_reload './pubchem.rb' - - @@pug_uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/" - before do - #cache_control :public, :max_age => 3600 + configure :development do + register Sinatra::Reloader + also_reload './pubchem.rb' end before '/cid/:cid/*' do - #cache_control :public, :max_age => 3600 - session[:compound] = PubChemCompound.new params[:cid] unless session[:compound] and session[:compound].cid == params[:cid] + @compound = PubChemCompound.new params[:cid] end get '/?' do - #cache_control :public, :no_cache haml :index end @@ -28,58 +24,71 @@ module OpenTox end get '/search/?' do - #cache_control :public, :no_cache - begin - cids = RestClient.get(File.join(@@pug_uri,"compound","name",CGI.escape(params[:name]),"cids","TXT")).split("\n") - if cids.size == 1 - session[:compound] = PubChemCompound.new cids.first - haml :compound - elsif cids.size > 1 - @compounds = cids.collect{|cid| PubChemCompound.new cid } - haml :select - end - rescue + @compounds = PubChemCompound.from_name params[:name] + if @compounds.nil? haml :not_found + elsif @compounds.is_a? Array + haml :select + else + @compound = @compounds + haml :compound end end get '/cid/:cid/targets/?' do - @assays = session[:compound].targets - haml :targets, :layout => false + @assays = @compound.targets + if @assays.empty? + "
No PubChem data
" + else + haml :targets, :layout => false + end end get '/cid/:cid/nontargets/?' do - @assays = session[:compound].non_targets - haml :targets, :layout => false + @assays = @compound.non_targets + if @assays.empty? + "
No PubChem data
" + else + haml :targets, :layout => false + end end get '/cid/:cid/other_active_assays/?' do - @assays = session[:compound].active_assays - session[:compound].targets - haml :assays, :layout => false + @assays = @compound.active_assays - @compound.targets + if @assays.empty? + "
No PubChem data
" + else + haml :assays, :layout => false + end end get '/cid/:cid/other_inactive_assays/?' do - @assays = session[:compound].inactive_assays - session[:compound].non_targets - haml :assays, :layout => false + @assays = @compound.inactive_assays - @compound.non_targets + if @assays.empty? + "
No PubChem data
" + else + haml :assays, :layout => false + end end get '/cid/:cid/predicted_targets/?' do - @assays = session[:compound].predicted_targets + @assays = @compound.predicted_targets + puts @assays.inspect haml :predicted_targets, :layout => false end get '/cid/:cid/predicted_nontargets/?' do - @assays = session[:compound].predicted_non_targets + @assays = @compound.predicted_non_targets haml :predicted_targets, :layout => false end get '/cid/:cid/other_predicted_active_assays/?' do - @assays = session[:compound].predicted_active_assays - session[:compound].predicted_targets + @assays = @compound.predicted_active_assays - @compound.predicted_targets haml :predicted_assays, :layout => false end get '/cid/:cid/other_predicted_inactive_assays/?' do - @assays = session[:compound].predicted_inactive_assays - session[:compound].predicted_non_targets + @assays = @compound.predicted_inactive_assays - @compound.predicted_non_targets haml :predicted_assays, :layout => false end @@ -88,23 +97,8 @@ module OpenTox end get '/cid/:cid/cosine/:cid2/?' do - session[:compound].cosine(PubChemCompound.new(params[:cid2])).round(3).to_s - end - -=begin - get '/aid/:aid/?' do - puts File.join(@@pug_uri, "assay", "aid", params[:aid].to_s, "description", "JSON") - json = RestClient.get File.join(@@pug_uri, "assay", "aid", params[:aid].to_s, "description", "JSON") - @description = JSON.parse(json)["PC_AssayContainer"][0]["assay"]["descr"] - haml :assay_description, :layout => false - end - - get '/pubchem_proxy/*' do |path| - puts path.inspect - puts "http://pubchem.ncbi.nlm.nih.gov/rest/pug/#{path}" - RestClientWrapper.get "http://pubchem.ncbi.nlm.nih.gov/rest/pug/#{path}" + @compound.cosine(PubChemCompound.new(params[:cid2])).round(3).to_s end -=end get '/fp/?' do @fp = [] -- cgit v1.2.3