summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrautenberg <rautenberg@in-silico.ch>2013-10-23 11:26:33 +0200
committerrautenberg <rautenberg@in-silico.ch>2013-10-23 11:26:33 +0200
commit773c75117fecdb6c328ce7ad8c8ce9d89e552f03 (patch)
treed04db264cdb67449f2eaeed08ec130d82635d393
parent1a779e4fab4f42f27d867fcda24bf207cc2ece8a (diff)
extend csv file feature, add ist link
-rw-r--r--application.rb80
-rw-r--r--views/layout.haml3
-rw-r--r--views/style.scss10
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) : "<p><em>No PubChem data</em></p>"
+ 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) : "<p><em>No PubChem data</em></p>"
+ 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) : "<p><em>Insuffucient PubChem data for read across predictions.</em></p>"
+ 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) : "<p><em>Insuffucient PubChem data for read across predictions.</em></p>"
+ 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"} <i style="font-family: serife">in silico</i> 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