summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-01-17 22:30:07 +0000
committergebele <gebele@in-silico.ch>2017-01-17 22:30:07 +0000
commitc9621a800143dc841c2a106f76ca4b9db09a1106 (patch)
tree39ebb4dea50c180592a29b13ab9068d87159c69c
parent1a883fb3789400df592e7f38f7cd1d3f296c6754 (diff)
enable multiple coating;better way for dbhit
-rw-r--r--application.rb41
-rw-r--r--views/predict.haml75
-rw-r--r--views/prediction.haml15
3 files changed, 85 insertions, 46 deletions
diff --git a/application.rb b/application.rb
index a821c7f..c409a42 100644
--- a/application.rb
+++ b/application.rb
@@ -95,7 +95,7 @@ get '/predict/?' do
# select relevant features for each model
@fingerprint_relevant_features = @prediction_models[0].model.substance_ids.collect{|id| Substance.find(id)}
fingerprint = $coating_list.sample
- fingerprint.properties.delete_if{|id,v| !@fingerprint_relevant_features.include?(Feature.find(id))}
+ #fingerprint.properties.delete_if{|id,v| !@fingerprint_relevant_features.include?(Feature.find(id))}
@example_fingerprint = fingerprint
@physchem_relevant_features = @prediction_models[1].model.descriptor_ids.collect{|id, v| Feature.find(id)}
@@ -126,28 +126,23 @@ post '/predict/?' do
@type = params[:type]
example_core = params[:example_core]
- example_coating = params[:example_coating]
- example_pc = eval(params[:example_pc])
+ #example_coating = params[:example_coating]
+ example_coating = params.collect{|k,v| v if k =~ /example_coating_/}.compact
input_core = params[:input_core]
- input_coating = params[:input_coating]
+ input_coating = params.collect{|k,v| v if k =~ /input_coating_/}.compact
+ example_pc = eval(params[:example_pc])
input_pc = {}
if @type =~ /physchem|proteomics/
(1..size).each{|i| input_pc["#{params["input_key_#{i}"]}"] = [params["input_value_#{i}"].to_f] unless params["input_value_#{i}"].blank?}
end
- # define relevant_features by input
- (@type == "fingerprint") ? (@fingerprint_relevant_features = input_pc.collect{|id,v| Feature.find(id)}) : (@physchem_relevant_features = [])
- (@type == "physchem") ? (@physchem_relevant_features = input_pc.collect{|id,v| Feature.find(id)}) : (@physchem_relevant_features = [])
- (@type == "proteomics") ? (@proteomics_relevant_features = input_pc.collect{|id,v| Feature.find(id)}) : (@proteomics_relevant_features = [])
+ if @type == "fingerprint"
+ @fingerprint_relevant_features = []
+ nanoparticle = (input_core == example_core && input_coating == example_coating) ? Nanoparticle.find(params[:example_id]) : nil
-
- if @type =~ /physchem|proteomics/
- if input_pc == example_pc && input_core == example_core #&& input_coating == example_coating
- # unchanged input = database hit
- nanoparticle = Nanoparticle.find_by(:id => params[:example_id])
- nanoparticle.properties = input_pc
+ if !nanoparticle.nil?
@match = true
@nanoparticle = nanoparticle
@name = nanoparticle.name
@@ -155,16 +150,21 @@ post '/predict/?' do
# changed input = create nanoparticle to predict
nanoparticle = Nanoparticle.new
nanoparticle.core_id = Compound.find_by(:name=>input_core).id.to_s
- #nanoparticle.coating_ids = [Compound.find_by(:name=>input_coating).id.to_s] if input_coating
- nanoparticle.properties = input_pc
+ nanoparticle.coating_ids = []
+ input_coating.each{|ic| nanoparticle.coating_ids << Compound.find_by(:name=>ic).id.to_s}
@match = false
@nanoparticle = nanoparticle
end
end
- if @type == "fingerprint"
- nanoparticle = $coating_list.find{|n| n.core.name == input_core && n.coating[0].name == input_coating}
- if !nanoparticle.nil?
+ if @type =~ /physchem|proteomics/
+ (@type == "physchem") ? (@physchem_relevant_features = input_pc.collect{|id,v| Feature.find(id)}.compact) : (@physchem_relevant_features = [])
+ (@type == "proteomics") ? (@proteomics_relevant_features = input_pc.collect{|id,v| Feature.find(id)}.compact) : (@proteomics_relevant_features = [])
+
+ if input_pc == example_pc && input_core == example_core #&& input_coating == example_coating
+ # unchanged input = database hit
+ nanoparticle = Nanoparticle.find_by(:id => params[:example_id])
+ nanoparticle.properties = input_pc
@match = true
@nanoparticle = nanoparticle
@name = nanoparticle.name
@@ -172,7 +172,8 @@ post '/predict/?' do
# changed input = create nanoparticle to predict
nanoparticle = Nanoparticle.new
nanoparticle.core_id = Compound.find_by(:name=>input_core).id.to_s
- nanoparticle.coating_ids = [Compound.find_by(:name=>input_coating).id.to_s]
+ #nanoparticle.coating_ids = [Compound.find_by(:name=>input_coating).id.to_s] if input_coating
+ nanoparticle.properties = input_pc
@match = false
@nanoparticle = nanoparticle
end
diff --git a/views/predict.haml b/views/predict.haml
index a438f7f..206ee63 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -7,6 +7,46 @@
function showcircle() {
$("img.circle").show();
};
+
+ function addCoating(type, coatings) {
+ //console.log(type, coatings);
+ var allCoatings = coatings;
+ var usedCoatings = [];
+ var removedCoating = [];
+ var div = document.getElementById("coatings");
+ var selectChilds = div.getElementsByTagName("select");
+ console.log(selectChilds);
+ // iterate the whole select elements and decide to add or remove;
+ // last coating should be always present; remove all used coatings
+ // from the option list for new elements, but add them back if a
+ // select element was removed;
+ for(i=0; i < selectChilds.length; i++){
+ id = selectChilds[i].id;
+ console.log(selectChilds[i].id);
+ value = selectChilds[i].value;
+ console.log(selectChilds[i].value);
+
+ if (type === "add"){
+ var element = document.getElementById(id);
+ var clone = element.cloneNode(true);
+ console.log(i);
+ console.log(i+1);
+ clone.id = "selCoating" + (selectChilds.length + 1);
+ clone.name = "input_coating_" + (selectChilds.length + 1);
+ console.log(clone.name);
+ div.appendChild(clone);
+ break;
+ };
+ if (type === "remove" && i !== 0){
+ var id = selectChilds[selectChilds.length - 1].id
+ document.getElementById(id).remove();
+ break;
+ }else{
+ //alert("One coating is required.")
+ };
+ };
+ };
+
$(document).ready(function(){
$('#selCore1').change(function(){
var selection = $(this).val();
@@ -138,16 +178,14 @@
- if type == "fingerprint"
- // core
%div.form-group
// type = fingerprint
// send hidden example data to compare
%input{:id=>"type",:type=>"hidden",:name=>"type",:value=>"#{type}"}
%input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core["name"]}"}
- %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating[0]["name"]}"}
- %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.properties}"}
- - size = relevant_features.size
- %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
+ - example.coating.each_with_index do |ex_coating, idx|
+ %input{:id=>"example_coating_#{idx}",:type=>"hidden",:name=>"example_coating_#{idx}",:value=>"#{ex_coating["name"]}"}
+ %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"{}"}
%input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id}
// input form parameters to transfer
@@ -159,13 +197,18 @@
%option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
// coating
- %div.form-group
+ - coatings = $coating_list.collect{|nano| nano.coating.collect{|co| co["name"]}}.flatten.compact.uniq.sort_by(&:downcase)
+ %div.form-group{:id=>"coatings"}
%label{:for=>"selCoating#{idx}"} Coating
- %select.form-control{:id=>"selCoating#{idx}", :autocomplete=>"off", :name=>"input_coating",:value=>example.coating[0]["name"]}
- - coatings = $coating_list.collect{|co| co.coating[0]["name"]}.uniq
- - coatings.each do |co|
- %option{:selected => ("selected" if example.coating[0]["name"] == co), :value => co}
- = co
+ - example.coating.each_with_index do |ex_coating, idx|
+ %select.form-control{:id=>"selCoating#{idx}", :autocomplete=>"off", :name=>"input_coating_#{idx}",:value=>ex_coating["name"]}
+ - coatings.each do |co|
+ %option{:selected => ("selected" if ex_coating["name"] == co), :value => co}
+ = co
+
+ %div{:id=>"coating_buttons"}
+ %span.btn.glyphicon.glyphicon-plus{:onclick=>"addCoating(\"add\", #{coatings});"}
+ %span.btn.glyphicon.glyphicon-minus{:onclick=>"addCoating(\"remove\", #{coatings});"}
- if type =~ /physchem/
%div.form-group
@@ -186,11 +229,6 @@
%select.form-control{:id=>"selCore#{idx}", :autocomplete=>"off", :name=>"input_core",:value=>example.core["name"]}
%option{:selected => ("selected" if example.core["name"] == "Ag"), :value => "Ag"} Ag
%option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
-
- // coating
- //%h5 Coating
- //%input.input-sm.form-control{:id=>"coating",:type=>"text",:disabled=>"disabled",:name=>"coating",:value=>example.coating[0]["name"]}
- //%input.input-sm.form-control{:id=>"coating",:type=>"hidden",:name=>"input_coating",:value=>example.coating[0]["name"]}
// relevant features
- relevant_features.sort_by{|f| f.name}.each_with_index do |relf,id|
@@ -231,11 +269,6 @@
%option{:selected => ("selected" if example.core["name"] == "Ag"), :value => "Ag"} Ag
%option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
- // coating
- //%h5 Coating
- //%input.input-sm.form-control{:id=>"coating",:type=>"text",:disabled=>"disabled",:name=>"coating",:value=>example.coating[0]["name"]}
- //%input.input-sm.form-control{:id=>"coating",:type=>"hidden",:name=>"input_coating",:value=>example.coating[0]["name"]}
-
// relevant features
- relevant_features.sort_by{|f| f.name}.each_with_index do |relf,id|
- feature = relf
diff --git a/views/prediction.haml b/views/prediction.haml
index 08fe4ba..55d9b8e 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -76,10 +76,12 @@
%a{:href=>core.source, :rel=>"external"}= "["+core.name+"]"
%br
- if @type == "fingerprint"
- - coating = Substance.find @nanoparticle[:coating_ids][0]
+ - coating = []
+ - @nanoparticle[:coating_ids].each{|id| coating << Substance.find(id) }
%h5.th5 Coating:
- %a{:href=>coating.source, :rel=>"external"}= coating.name
- %br
+ - coating.each do |co|
+ %a{:href=>co.source, :rel=>"external"}= co.name
+ %br
/ tox
%td.tox
- if @prediction[:value]
@@ -117,7 +119,8 @@
- @prediction[:neighbors].each_with_index do |neighbor,idx|
- nano = Nanoparticle.find(neighbor[:id])
- core = Substance.find nano.core_id
- - coating = Substance.find nano.coating_ids[0]
+ - coating = []
+ - nano.coating_ids.each{|id| coating << Substance.find(id)}
%tr
/ ID
%td
@@ -132,7 +135,9 @@
%a{:href=>core.source, :rel=> "external"}= "["+core.name+"]"
%br
%h5.th5 Coating:
- %a{:href=>coating.source, :rel=>"external"}= coating.name
+ - coating.each do |co|
+ %a{:href=>co.source, :rel=>"external"}= co.name
+ %br
/ Tox
%td.tox
%h5.th5 Measurement: