From 773c75117fecdb6c328ce7ad8c8ce9d89e552f03 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 23 Oct 2013 11:26:33 +0200 Subject: extend csv file feature, add ist link --- application.rb | 80 +++++++++++++++++++++++++++++++++++++++++-------------- views/layout.haml | 3 +++ views/style.scss | 10 +++++++ 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/application.rb b/application.rb index ddc4aa4..02b8978 100644 --- a/application.rb +++ b/application.rb @@ -129,10 +129,41 @@ class Application < Sinatra::Base @assays.sort{|a,b| [b["p_active"],b["p_inactive"]].max <=> [a["p_active"],a["p_inactive"]].max}.each do |assay| out += "\"#{assay['Target Name']}\";\"#{assay['Target GI']}\";\"http://pubchem.ncbi.nlm.nih.gov/assay/assay.cgi?aid=#{assay['AID']}\";\"#{assay['p_active'].to_f.round(3)}\";\"#{assay['p_inactive'].to_f.round(3)}\"\n" end + when "assays" + out = "\"Assay Name\";\"Assay ID\"\n" + @assays.sort{|a,b| a["Assay Name"] <=> b["Assay Name"]}.each do |assay| + out += "\"#{assay['Assay Name']}\";\"http://pubchem.ncbi.nlm.nih.gov/assay/assay.cgi?aid=#{assay['AID']}\"\n" + end + when "predicted_assays" + out = "\"Assay Name\";\"Assay ID\";\"p_active\";\"p_inactive\"\n" + @assays.sort{|a,b| [b["p_active"],b["p_inactive"]].max <=> [a["p_active"],a["p_inactive"]].max}.each do |assay| + out += "\"#{assay['Assay Name']}\";\"http://pubchem.ncbi.nlm.nih.gov/assay/assay.cgi?aid=#{assay['AID']}\";\"#{assay["p_active"].to_f.round(3)}\";\"#{assay["p_inactive"].to_f.round(3)}\"\n" + end + when "neighbors" + out = "\"Compound Name\";\"Similarity\"\n" + idx = 0 + while idx < 10 + neighbors(@cid).each do |n| + unless assays(n,"active").empty? and assays(n,"inactive").empty? + out += "\"#{name n}\";\"#{similarity(@cid,n).round(3)}\"\n" + idx += 1 + end + end + end end out end + def set_accept + case File.extname(params[:file]) + when ".csv" + @accept = "text/csv" + when ".json" + @accept = "application/json" + end + response['Content-Type'] = @accept + end + before '/pug/*' do content_type 'application/json' @result = CACHE.get request.path @@ -174,10 +205,10 @@ class Application < Sinatra::Base end end - get '/cid/:cid/targets/:outcome' do + get '/cid/:cid/targets/:outcome/?:file?' do @assays = targets params[:cid], params[:outcome] + set_accept if params[:file] if @accept == "application/json" - content_type = @accept @assays and !@assays.empty? ? JSON.pretty_generate(@assays) : "No PubChem data\n" elsif @accept == "text/csv" @assays and !@assays.empty? ? csv_file("target") : "No PubChem data\n" @@ -186,25 +217,34 @@ class Application < Sinatra::Base end end - get '/cid/:cid/targets/:outcome/:file' do - response['Content-Type'] = "text/csv" - RestClient.get "#{request.host_with_port}/cid/#{params[:cid]}/targets/#{params[:outcome]}",{:accept => "text/csv"} - end - - get '/cid/:cid/assays/:outcome' do + get '/cid/:cid/assays/:outcome/?:file?' do @assays = assays(params[:cid], params[:outcome]) - targets(params[:cid], params[:outcome]) - @assays and !@assays.empty? ? haml(:assays, :layout => false) : "

No PubChem data

" + set_accept if params[:file] + if @accept == "application/json" + @assays and !@assays.empty? ? JSON.pretty_generate(@assays) : "No PubChem data\n" + elsif @accept == "text/csv" + @assays and !@assays.empty? ? csv_file("assays") : "No PubChem data\n" + else + @assays and !@assays.empty? ? haml(:assays, :layout => false) : "

No PubChem data

" + end end - get '/cid/:cid/prediction/assays/:outcome' do + get '/cid/:cid/prediction/assays/:outcome/?:file?' do @assays = predicted_assays(params[:cid], params[:outcome]) - predicted_targets(params[:cid], params[:outcome]) - @assays and !@assays.empty? ? haml(:predicted_assays, :layout => false) : "

Insuffucient PubChem data for read across predictions.

" + set_accept if params[:file] + if @accept == "application/json" + @assays and !@assays.empty? ? JSON.pretty_generate(@assays) : "No PubChem data\n" + elsif @accept == "text/csv" + @assays and !@assays.empty? ? csv_file("predicted_assays") : "No PubChem data\n" + else + @assays and !@assays.empty? ? haml(:predicted_assays, :layout => false) : "

Insuffucient PubChem data for read across predictions.

" + end end - get '/cid/:cid/prediction/targets/:outcome' do + get '/cid/:cid/prediction/targets/:outcome/?:file?' do @assays = predicted_targets params[:cid], params[:outcome] + set_accept if params[:file] if @accept == "application/json" - content_type = @accept @assays and !@assays.empty? ? JSON.pretty_generate(@assays) : "No PubChem data\n" elsif @accept == "text/csv" @assays and !@assays.empty? ? csv_file("target_readacross") : "No PubChem data\n" @@ -213,13 +253,13 @@ class Application < Sinatra::Base end end - get '/cid/:cid/prediction/targets/:outcome/:file' do - response['Content-Type'] = "text/csv" - RestClient.get "#{request.host_with_port}/cid/#{params[:cid]}/prediction/targets/#{params[:outcome]}",{:accept => "text/csv"} - end - - get '/cid/:cid/neighbors/?' do - haml :neighbors, :layout => false + get '/cid/:cid/neighbors/?:file?' do + set_accept if params[:file] + if @accept == "text/csv" + csv_file("neighbors") + else + haml :neighbors, :layout => false + end end get '/pug/cid/:cid/name' do diff --git a/views/layout.haml b/views/layout.haml index 1e1c7d3..976d172 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -52,3 +52,6 @@ %input{ :type => "submit", :value => "Search" } %em This is an experimental version. Loading data from PubChem can be slow. Please use the "Back" button and retry the offending operation if you have timeout problems. = yield + + .footer + %a{:href => 'http://www.in-silico.ch', :rel => "external"} in silico toxicology gmbh 2013 \ No newline at end of file diff --git a/views/style.scss b/views/style.scss index 77f2f5c..01e3aa6 100644 --- a/views/style.scss +++ b/views/style.scss @@ -101,4 +101,14 @@ img.compound { color: $formborder; radius: 4px; } +} +.footer { + margin: 200px 0px 20px 4px; + width: 99%; + text-align: right; +} +.footer a { + text-decoration: none; + color: #000; + &:hover { color: #900; } } \ No newline at end of file -- cgit v1.2.3