From 1d6588b35b4ffff16717e24b42a0d396d5347f95 Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 26 Jan 2016 12:53:40 +0000 Subject: batch merge --- application.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 229f3a1..fc7e415 100644 --- a/application.rb +++ b/application.rb @@ -202,21 +202,34 @@ get '/predict/?:csv?' do model = array[0] prediction = array[1] compound = key.smiles + mw = key.molecular_weight endpoint = "#{model.endpoint.gsub('_', ' ')} (#{model.species})" if prediction[:confidence] == "measured" - type = "" - pred = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{model.unit})" : 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}" : 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 -- cgit v1.2.3