From 6d6fdf889eace978aaacbde1335264c9fccaa874 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Mon, 21 Oct 2013 11:00:04 +0200 Subject: before @accept --- application.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application.rb b/application.rb index f742442..53fd2f7 100644 --- a/application.rb +++ b/application.rb @@ -116,6 +116,11 @@ class Application < Sinatra::Base end end + before do + @accept = request.env['HTTP_ACCEPT'] + response['Content-Type'] = @accept + end + before '/pug/*' do content_type 'application/json' @result = CACHE.get request.path -- cgit v1.2.3 From 1a779e4fab4f42f27d867fcda24bf207cc2ece8a Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 23 Oct 2013 00:18:26 +0200 Subject: add basic csv download posibilities --- application.rb | 47 ++++++++++++++++++++++++++++++++++++++++++----- views/layout.haml | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/application.rb b/application.rb index 53fd2f7..ddc4aa4 100644 --- a/application.rb +++ b/application.rb @@ -12,6 +12,7 @@ class Application < Sinatra::Base set :root, File.dirname(__FILE__) # doc @ http://pubchem.ncbi.nlm.nih.gov/pug_rest/ + # doc @ http://pubchem.ncbi.nlm.nih.gov/pug_rest/PUG_REST.html PUG_URI = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/" SIMILARITY_THRESHOLD = 90 MAX_NEIGHBORS = 100 @@ -116,9 +117,20 @@ class Application < Sinatra::Base end end - before do - @accept = request.env['HTTP_ACCEPT'] - response['Content-Type'] = @accept + def csv_file type + case type + when "target" + out = "\"Target Name\";\"Target GeneID\";\"Assay IDs\"\n" + @assays.collect{|a| [a["Target Name"],a["Target GI"]]}.uniq.sort{|a,b| a[0] <=> b[0]}.each do |target| + out += "\"#{target.first}\";\"#{target.last}\";\"" + @assays.select{|a| a["Target GI"] == target.last}.collect{|assay| "http://pubchem.ncbi.nlm.nih.gov/assay/assay.cgi?aid=#{assay["AID"]}"}.join(", ") + "\"\n" + end + when "target_readacross" + out = "\"Target Name\";\"Target GeneID\";\"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['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 + end + out end before '/pug/*' do @@ -132,6 +144,7 @@ class Application < Sinatra::Base end before '/cid/:cid/*' do + @accept = request.env['HTTP_ACCEPT'] @cid = params[:cid] end @@ -163,7 +176,19 @@ class Application < Sinatra::Base get '/cid/:cid/targets/:outcome' do @assays = targets params[:cid], params[:outcome] - @assays and !@assays.empty? ? haml(:targets, :layout => false) : "

No PubChem data

" + 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" + else + @assays and !@assays.empty? ? haml(:targets, :layout => false) : "

No PubChem data

" + 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 @@ -178,7 +203,19 @@ class Application < Sinatra::Base get '/cid/:cid/prediction/targets/:outcome' do @assays = predicted_targets params[:cid], params[:outcome] - @assays and !@assays.empty? ? haml(:predicted_targets, :layout => false) : "

Insuffucient PubChem data for read across predictions.

" + 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" + else + @assays and !@assays.empty? ? haml(:predicted_targets, :layout => false) : "

Insuffucient PubChem data for read across predictions.

" + 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 diff --git a/views/layout.haml b/views/layout.haml index 827baaf..1e1c7d3 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -14,7 +14,7 @@ url: uri, //timeout: 120000; success: function(data){ - data = "

"+title+"

"+"" + data; + data = "

"+title+"

"+" (csv)" + data; $(element).html(data); }, error: function(data,textStatus,message){ -- cgit v1.2.3 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 From 9095a48b0e22f51ece2f4e9539e41310ff544052 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 23 Oct 2013 12:27:50 +0200 Subject: IE js replace fix --- views/layout.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/views/layout.haml b/views/layout.haml index 976d172..5160c31 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -14,7 +14,8 @@ url: uri, //timeout: 120000; success: function(data){ - data = "

"+title+"

"+" (csv)" + data; + var slash = new RegExp("/","g"); + data = "

"+title+"

"+" (csv)" + data; $(element).html(data); }, error: function(data,textStatus,message){ -- cgit v1.2.3 From f7c3b817e5de6ce3388caee15d1a4adc12b81334 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Mon, 28 Oct 2013 11:38:33 +0100 Subject: minor style change --- views/style.scss | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/views/style.scss b/views/style.scss index 01e3aa6..225bee8 100644 --- a/views/style.scss +++ b/views/style.scss @@ -39,9 +39,10 @@ h4 { /* tables */ th { - color: #333; + color: #000; text-align: left; - font-size: 1em; + font-size: 1.1em; + padding: 8px 0; } td { vertical-align: top; @@ -111,4 +112,12 @@ img.compound { text-decoration: none; color: #000; &:hover { color: #900; } +} +.tooltip { + background-color: #fff; + border: 2px solid #ccc; + font-size: 0.5em; + padding: 1em; + display: none; + z-index: 50; } \ No newline at end of file -- cgit v1.2.3 From ecae07354c9a6b7f13fdf70ef832ccafc9c64d05 Mon Sep 17 00:00:00 2001 From: gebele Date: Mon, 17 Feb 2014 11:29:47 +0100 Subject: ensure correct loop end --- views/neighbors.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/neighbors.haml b/views/neighbors.haml index c7a181a..5563392 100644 --- a/views/neighbors.haml +++ b/views/neighbors.haml @@ -31,4 +31,4 @@ :javascript hide("Other inactive assays","#inactive_assays#{n}", "/cid/#{n}/assays/inactive"); - - idx += 1 + - idx += 1 -- cgit v1.2.3