summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavor <vorgrimmlerdavid@gmx.de>2012-05-25 13:37:03 +0200
committerdavor <vorgrimmlerdavid@gmx.de>2012-05-25 13:37:03 +0200
commit2e2bf5590d56fae9aba995f48102c5d7849c0092 (patch)
tree18c7cae21451150d7ab0419751c48ef76217374d
parent7cd2ed8a07efcb22c0e57b0c19d95ce633e85c1c (diff)
Predicted value transformation to mg (for Nestle)
in single predictions.
-rw-r--r--application.rb54
-rw-r--r--views/prediction.haml2
2 files changed, 50 insertions, 6 deletions
diff --git a/application.rb b/application.rb
index eca26a5..34a11e3 100644
--- a/application.rb
+++ b/application.rb
@@ -547,12 +547,54 @@ post '/predict/?' do # post chemical name to model
:error => "Not enough similar compounds in training dataset."
}
else
- @predictions << {
- :title => model.name,
- :model_uri => model.uri,
- :prediction => prediction_dataset.value(@compound),
- :confidence => prediction_dataset.confidence(@compound)
- }
+ if model.name.downcase.include? "ptd50"
+ ds = OpenTox::Dataset.new()
+ ds.save(@subjectid)
+ ds.add_compound(@compound.uri)
+ ds.save(@subjectid)
+ mw_algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"pc/MW")
+ mw_uri = OpenTox::RestClientWrapper.post(mw_algorithm_uri, {:dataset_uri=>ds.uri})
+ ds.delete(@subjectid)
+ mw_ds = OpenTox::Dataset.find(mw_uri, @subjectid)
+ mw = mw_ds.data_entries[@compound.uri][mw_uri.to_s + "/feature/MW"].first
+ mw_ds.delete(@subjectid)
+ td50 = (((10**(-1.0*prediction_dataset.value(@compound)))*(mw.to_f*1000))*1000).round / 1000.0
+ prediction_trans = "TD50: #{td50}"
+ elsif model.name.downcase.include? "loael"
+ if model.name.downcase.include? "mol"
+ ds = OpenTox::Dataset.new()
+ ds.save(@subjectid)
+ ds.add_compound(@compound.uri)
+ ds.save(@subjectid)
+ mw_algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"pc/MW")
+ mw_uri = OpenTox::RestClientWrapper.post(mw_algorithm_uri, {:dataset_uri=>ds.uri})
+ ds.delete(@subjectid)
+ mw_ds = OpenTox::Dataset.find(mw_uri, @subjectid)
+ mw = mw_ds.data_entries[@compound.uri][mw_uri.to_s + "/feature/MW"].first
+ mw_ds.delete(@subjectid)
+ mg = (((10**(-1.0*prediction_dataset.value(@compound)))*(mw.to_f*1000))*1000).round / 1000.0
+ prediction_trans = "mg/kg bw/day: #{mg}"
+ elsif model.name.downcase.include? "mg"
+ mg = ((10**prediction_dataset.value(@compound))*1000).round / 1000.0
+ prediction_trans = "mg/kg bw/day: #{mg}"
+ end
+ end
+ if prediction_trans.nil?
+ @predictions << {
+ :title => model.name,
+ :model_uri => model.uri,
+ :prediction => prediction_dataset.value(@compound),
+ :confidence => prediction_dataset.confidence(@compound)
+ }
+ else
+ @predictions << {
+ :title => model.name,
+ :model_uri => model.uri,
+ :prediction => prediction_dataset.value(@compound),
+ :confidence => prediction_dataset.confidence(@compound),
+ :prediction_transformed => prediction_trans
+ }
+ end
end
end
# TODO failed/unavailable predictions
diff --git a/views/prediction.haml b/views/prediction.haml
index 682b979..b83bc63 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -30,6 +30,8 @@
%br= p[:error]
- else
= activity_markup(p[:prediction], @value_map)
+ - if p[:prediction_transformed]
+ = p[:prediction_transformed]
- if p[:confidence]
%br
(