summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2016-09-22 10:29:10 +0000
committergebele <gebele@in-silico.ch>2016-09-22 10:29:10 +0000
commit79bcc6575eb30c4fddcc77ffdc183f79d2d1cc0d (patch)
treee29bb2dc768735c978a70ffac02bd8d7f5bd7788
parentd420e64b3869130bc8526ff2659da6fd35bc6548 (diff)
added Ag
-rw-r--r--Gemfile1
-rw-r--r--application.rb52
-rw-r--r--config.ru1
-rw-r--r--public/css/style.css3
-rw-r--r--views/predict.haml38
-rw-r--r--views/prediction.haml41
6 files changed, 83 insertions, 53 deletions
diff --git a/Gemfile b/Gemfile
index 3cde411..a33d28e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,5 +2,6 @@ source "https://rubygems.org"
gemspec
gem "lazar", :path => "../lazar"
gem "sinatra"
+gem 'sinatra-reloader', '~> 1.0'
gem "haml"
gem "rdiscount"
diff --git a/application.rb b/application.rb
index 98e502f..3ffc080 100644
--- a/application.rb
+++ b/application.rb
@@ -18,11 +18,13 @@ get '/predict/?' do
prediction_models = OpenTox::Model::NanoPrediction.all
prediction_models.each{|m| m.model[:feature_selection_algorithm_parameters]["category"] == "P-CHEM" ? @prediction_models[0] = m : @prediction_models[1] = m}
@prediction_models.each_with_index{|m,idx| idx == 0 ? m[:pc_model] = true : m[:pcp_model] = true}
- example = OpenTox::Nanoparticle.all.select{|n| n.core["name"] == "Au"}.sample
- @example_pcp = example
- example = OpenTox::Nanoparticle.all.select{|n| n.core["name"] == "Au"}.sample
- example.physchem_descriptors.delete_if{|k,v| feature = OpenTox::Feature.find_by(:id => k); feature.category != "P-CHEM"}
- @example_pc = example
+ nanoparticles = OpenTox::Nanoparticle.all.select{|n| n.core["name"] == "Au" || n.core["name"] == "Ag"}
+ example = nanoparticles.collect{|n| n if n.physchem_descriptors.size > 16}.compact
+ pcp = example.sample
+ @example_pcp = pcp
+ pc = example.sample
+ pc.physchem_descriptors.delete_if{|k,v| feature = OpenTox::Feature.find_by(:id => k); feature.category != "P-CHEM"}
+ @example_pc = pc
haml :predict
end
@@ -35,32 +37,38 @@ end
post '/predict/?' do
prediction_model = OpenTox::Model::NanoPrediction.find(params[:prediction_model])
size = params[:size].to_i
+ @type = params[:type]
+
+ example_core = eval(params[:example_core])
+ example_coating = eval(params[:example_coating])
example_pc = eval(params[:example_pc])
- pc_descriptors = {}
- (1..size).each{|i| pc_descriptors["#{params["input_key_#{i}"]}"] = [params["input_value_#{i}"].to_f]}
- if example_pc == pc_descriptors
+
+ in_core = eval(params[:in_core])
+ in_core["name"] = params[:input_core]
+ input_core = in_core
+
+ in_coating = eval(params[:in_coating])
+ in_coating[0]["name"] = params[:input_coating]
+ input_coating = in_coating
+
+ input_pc = {}
+ (1..size).each{|i| input_pc["#{params["input_key_#{i}"]}"] = [params["input_value_#{i}"].to_f]}
+ if input_pc == example_pc && input_core == example_core && input_coating == example_coating
# unchanged input = database hit
nanoparticle = OpenTox::Nanoparticle.find_by(:id => params[:example_id])
- nanoparticle.physchem_descriptors = pc_descriptors
+ nanoparticle.physchem_descriptors = input_pc
+ @match = true,@nanoparticle = nanoparticle,@name = nanoparticle.name
else
# changed input = create nanoparticle to predict
nanoparticle = OpenTox::Nanoparticle.new
- nanoparticle.core = eval(params[:core])
- nanoparticle.coating = eval(params[:coating])
- nanoparticle.physchem_descriptors = pc_descriptors
+ nanoparticle.core = input_core
+ nanoparticle.coating = input_coating
+ nanoparticle.physchem_descriptors = input_pc
+ @match = false
end
# output
- @input = pc_descriptors
+ @input = input_pc
@prediction = prediction_model.model.predict_substance nanoparticle
- @match = true,@nanoparticle = nanoparticle,@name = nanoparticle.name if @prediction[:warning] =~ /identical/
- #@prediction[:neighbors].each do |n|
- #puts n
- #puts nano = OpenTox::Nanoparticle.find(n["_id"])
- #puts nano.name
- #puts n["similarity"]
- #puts n["measurements"]
- #puts nano.physchem_descriptors.delete_if{|k,v| feature = OpenTox::Feature.find_by(:id => k); feature.category != "P-CHEM"}.size
- #end
haml :prediction
end
diff --git a/config.ru b/config.ru
index 4f8501e..eec777d 100644
--- a/config.ru
+++ b/config.ru
@@ -3,4 +3,5 @@ SERVICE = "nano-lazar-gui"
require 'bundler'
Bundler.require
require File.expand_path './application.rb'
+require "sinatra/reloader" if development?
run Sinatra::Application
diff --git a/public/css/style.css b/public/css/style.css
index 93500a6..02b1959 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -11,3 +11,6 @@
.tablesorter tbody tr.static td {
background-color: #CCFFCC;
}
+.th5 {
+ display: inline;
+}
diff --git a/views/predict.haml b/views/predict.haml
index 7c25def..ad263d1 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -11,10 +11,10 @@
- @prediction_models.each_with_index do |m, idx|
%li{:class => ("active" if idx == 0)}
%a{:href => "#model_#{idx}", :id => "linkTab#{idx}", data: {toggle:"tab"}}
- = "#{idx+1}. #{m.model.feature_selection_algorithm_parameters[:category].nil? ? "P-CHEM & Proteomics" : "P-CHEM" }"
+ = "#{idx+1}. #{m.model.feature_selection_algorithm_parameters[:category].nil? ? "Physchem & Proteomics" : "Physchem" }"
%div.tab-content
- @prediction_models.each_with_index do |m, idx|
- - m[:pc_model] ? example = @example_pc : example = @example_pcp
+ - m[:pc_model] ? (example = @example_pc; type = "pc") : (example = @example_pcp; type = "pcp")
#model.tab-pane{:id=>"#{idx}", :class => ("active" if idx == 0)}
%b Model:
%br
@@ -64,14 +64,33 @@
= "R square:\t"
= cv.r_squared.round(3) if cv.r_squared
%br
+ %b QSAR report
+ %br
+ %a{:href=>to('/qsar-report/'+m.id)} download
%hr
%form{:id=>idx, :role=>"form", :action=> to("/predict"), :method=>"post"}
%h3.help-block
Please characterise a nanoparticle:
#input
%div.form-group
+ // type pcp || pc
+ %input{:id=>"type",:type=>"hidden",:name=>"type",:value=>"#{type}"}
+ // example data to compare
+ %input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core}"}
+ %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating}"}
+ %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.physchem_descriptors}"}
+ - size = example.physchem_descriptors.size
+ %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
+ %input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id}
+ // input form parameters to transfer
%h5 Core
- %input.input-sm.form-control{:id=>"core_name",:type=>"text",:name=>"core_name",:value=>example.core["name"], :disabled=>"true"}
+ %input.input-sm.form-control{:id=>"core",:type=>"text",:name=>"input_core",:value=>example.core["name"]}
+ %input{:id=>"input_core",:type=>"hidden",:name=>"in_core",:value=>"#{example.core}"}
+ %h5 Coating
+ %input.input-sm.form-control{:id=>"coating",:type=>"text",:name=>"input_coating",:value=>example.coating[0]["name"]}
+ %input{:id=>"input_coating",:type=>"hidden",:name=>"in_coating",:value=>example.coating}
+ // prediction model id
+ %input{:id=>"prediction_model",:type=>"hidden",:name=>"prediction_model",:value=>m.id}
- example.physchem_descriptors.each_with_index do |v,id|
- feature = OpenTox::Feature.find_by(:id => v[0])
- name = feature.name
@@ -82,18 +101,9 @@
- val = v[1]
- id = id + 1
%h5= name
- %input.form-control{:id=>id,:type=>"hidden",:name=>"input_key_#{id}",:value=>v[0]}
+ // input physchem parameters
%input.input-sm.form-control{:id=>id,:type=>"text",:name=>"input_value_#{id}",:value=>val[0]}
- %input.form-control{:id=>id,:type=>"hidden",:name=>"input_key_#{id}",:value=>v[0]}
- %input.input-sm.form-control{:id=>id,:type=>"hidden",:name=>"input_value_#{id}",:value=>val[0]}
- %input.form-control{:id=>"example_id",:type=>"hidden",:name=>"example_id",:value=>example.id}
- %input.form-control{:id=>"core",:type=>"hidden",:name=>"core",:value=>"#{example.core}"}
- %input.form-control{:id=>"coating",:type=>"hidden",:name=>"coating",:value=>example.coating}
- %input.form-control{:id=>"prediction_model",:type=>"hidden",:name=>"prediction_model",:value=>m.id}
- - example_pc = example.physchem_descriptors
- %input.form-control{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example_pc}"}
- - size = example.physchem_descriptors.size
- %input.form-control{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
+ %input{:id=>id,:type=>"hidden",:name=>"input_key_#{id}",:value=>v[0]}
%hr
#predict
%button.btn.btn-success{:id=>"submitbutton", :type=>"submit", :onclick=>"showcircle();"}
diff --git a/views/prediction.haml b/views/prediction.haml
index f8610f5..0438f1f 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -41,7 +41,7 @@
- @input.each do |key|
- feature = OpenTox::Feature.find_by(:id=>key[0])
- name = feature.name
- - if !feature[:conditions]["MEDIUM"].blank?
+ - if (feature[:conditions] && !feature[:conditions]["MEDIUM"].blank?)
- name = feature.name + " / " + feature[:conditions]["MEDIUM"]
- else
- name = feature.name
@@ -66,34 +66,39 @@
/ composition
%td
- if @match
- %h5 Core
+ %h5.th5 Core:
= "["+@nanoparticle[:core]["name"]+"]"
- %h5 Coating
+ %br
+ %h5.th5 Coating:
= @nanoparticle[:coating][0]["name"]
+ %br
- else
- %h5 x
+ %h5.th5 x
/ tox
%td.tox
- if @prediction[:value]
- %h5 Prediction:
+ %h5.th5 Prediction:
= @prediction[:value].round(3)
+ %br
- if @prediction[:rmse]
- %h5 Rmse:
+ %h5.th5 Rmse:
= @prediction[:rmse].round(3)
+ %br
- if @prediction[:r_squared]
- %h5 R_squared:
+ %h5.th5 R_squared:
= @prediction[:r_squared].round(3)
+ %br
- if @prediction[:prediction_interval]
%h5 95% Prediction interval:
- interval = @prediction[:prediction_interval].nil? ? " - - " : @prediction[:prediction_interval].collect{|i| i.round(2)}
= "#{interval[0]} - #{interval[1]}"
- if @prediction[:measurements]
%hr
- %h5 Measurement
+ %h5.th5 Measurement:
- @prediction[:measurements].each do |m|
- %p= m
+ = m
- if !@prediction[:value] && !@prediction[:measurements]
- %h5 not available
+ %h5.th5 not available
/ physchem
- if @prediction[:match]
- sorted = {}
@@ -115,7 +120,7 @@
- if @prediction[:neighbors]
- @prediction[:neighbors].each_with_index do |neighbor,idx|
- nano = OpenTox::Nanoparticle.find(neighbor["_id"])
- - pc_descriptors = nano.physchem_descriptors.delete_if{|k,v| feature = OpenTox::Feature.find_by(:id => k); feature.category != "P-CHEM"}
+ - pc_descriptors = nano.physchem_descriptors.delete_if{|k,v| feature = OpenTox::Feature.find_by(:id => k); feature.category != "P-CHEM"} if @type == "pc"
%tr
/ ID
%td
@@ -126,17 +131,19 @@
%h5= neighbor["similarity"].round(3)
/ Composition
%td
- %h5 Core
+ %h5.th5 Core:
= "["+nano[:core]["name"]+"]"
- %h5 Coating
+ %br
+ %h5.th5 Coating:
= nano[:coating][0]["name"]
/ Tox
%td.tox
- %h5 Measurement
- %p= neighbor["measurements"][0]
+ %h5.th5 Measurement:
+ = neighbor["measurements"][0]
/ Physchem
- - @input.each do |k,v|
+ -#- @input.each do |k,v|
+ - nano.physchem_descriptors.each do |k,v|
%td.physchem
%div
%div{:style=>"display:inline-block;padding-right:20px;"}
- %p= v[0].round(3) unless v.nil?
+ = v[0].round(3) unless v.nil?