summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2015-10-30 08:26:04 +0000
committergebele <gebele@in-silico.ch>2015-10-30 08:26:04 +0000
commita348f222c0b32bbb308083bb03127fe55b1563dc (patch)
tree217ae24e282e7e6737f3763057b19ead5241d781
parentefd241beab11fbfc200f0c32ffb9e198ed406c83 (diff)
fixed weight for multiple database hits in predictionv7-nestec
-rw-r--r--application.rb23
-rw-r--r--views/batch.haml12
-rw-r--r--views/prediction.haml10
3 files changed, 31 insertions, 14 deletions
diff --git a/application.rb b/application.rb
index 1763e3a..fc7e415 100644
--- a/application.rb
+++ b/application.rb
@@ -203,22 +203,33 @@ get '/predict/?:csv?' do
prediction = array[1]
compound = key.smiles
mw = key.molecular_weight
- weight = Compound.from_smiles(compound).mmol_to_mg(prediction[:value], mw)
endpoint = "#{model.endpoint.gsub('_', ' ')} (#{model.species})"
if prediction[:confidence] == "measured"
- type = ""
- pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value]
- confidence = "measured activity"
+ if prediction[:value].is_a?(Array)
+ prediction[:value].each do |value|
+ type = ""
+ weight = Compound.from_smiles(compound).mmol_to_mg(value, mw)
+ pred = value.numeric? ? "#{'%.2e' % value} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : value
+ confidence = "measured activity"
+ @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n"
+ end
+ else
+ type = ""
+ weight = Compound.from_smiles(compound).mmol_to_mg(prediction[:value], mw)
+ pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value]
+ confidence = "measured activity"
+ end
elsif prediction[:neighbors].size > 0
+ weight = Compound.from_smiles(compound).mmol_to_mg(prediction[:value], mw)
type = model.model.class.to_s.match("Classification") ? "Classification" : "Regression"
- pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} #{model.unit} | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value]
+ pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value]
confidence = prediction[:confidence]
else
type = ""
pred = "Not enough similar compounds in training dataset."
confidence = ""
end
- @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n"
+ @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n" unless prediction[:value].is_a?(Array)
end
end
@csv
diff --git a/views/batch.haml b/views/batch.haml
index f593188..9bfa67e 100644
--- a/views/batch.haml
+++ b/views/batch.haml
@@ -33,10 +33,13 @@
%p
- if prediction[:confidence] == "measured"
%p
- / TODO fix scientific notation from database
- %b Measured activity:
- = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value]
- %p Compound is part of the training dataset
+ %b Measured activity:
+ - if prediction[:value].is_a?(Array)
+ = prediction[:value][0].numeric? ? prediction[:value].collect{|v| weight = compound.mmol_to_mg(v, mw); '%.2e' % v + " (#{model.unit})"+" | #{'%.2e' % weight} (mg/kg_bw/day)"}.join("</br>") : prediction[:value].join(", ")
+ - else
+ = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value]
+ %p
+ %b Compound is part of the training dataset
- elsif prediction[:neighbors].size > 0
%p
/ model type (classification|regression)
@@ -44,7 +47,6 @@
= model.model.class.to_s.match("Classification") ? "Classification" : "Regression"
%br
%b Prediction:
- / TODO scientific notation
= prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value]
%br
/ TODO probability
diff --git a/views/prediction.haml b/views/prediction.haml
index 11d542e..a74b95a 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -31,10 +31,14 @@
- if prediction[:confidence] == "measured"
- @dbhit[i] = true
%p
- / TODO fix scientific notation from database
%b Measured activity:
- = (type == "Regression") ? "#{"%.2e" % prediction[:value]} (#{@models[i].unit}) | #{'%.2e' % @compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value]
- %p Compound is part of the training dataset
+ - p prediction[:value]
+ - if prediction[:value].is_a?(Array)
+ = (type == "Regression") ? prediction[:value].collect{|v| weight = Compound.from_smiles(@compound.smiles).mmol_to_mg(v, mw); '%.2e' % v + " (#{@models[i].unit})"+"|#{'%.2e' % weight} (mg/kg_bw/day)"}.join("</br>") : prediction[:value].join(", ")
+ - else
+ = (type == "Regression") ? "#{"%.2e" % prediction[:value]} (#{@models[i].unit}) | #{'%.2e' % @compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value]
+ %p
+ %b Compound is part of the training dataset
- elsif prediction[:neighbors].size > 0
%p
/ model type (classification|regression)