From f5a0d4ab14e55a72c4cb182ce0e81f599e4857ed Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 12 Dec 2017 13:57:28 +0000 Subject: prediction object adjusted for single predictions --- application.rb | 9 ++++++--- views/prediction.haml | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/application.rb b/application.rb index 223b81a..04b5aa3 100644 --- a/application.rb +++ b/application.rb @@ -354,7 +354,8 @@ post '/predict/?' do if model.model.name =~ /kazius/ sa_prediction = KaziusAlerts.predict(@compound.smiles) - lazar_mutagenicity = model.predict(@compound) + prediction = model.predict(@compound) + lazar_mutagenicity = prediction confidence = 0 lazar_mutagenicity_val = (lazar_mutagenicity[:value] == "non-mutagenic" ? false : true) if sa_prediction[:prediction] == false && lazar_mutagenicity_val == false @@ -366,9 +367,11 @@ post '/predict/?' do elsif sa_prediction[:prediction] == true && lazar_mutagenicity_val == false confidence = ( 1 - sa_prediction[:error_product] ) - 0.57 end - prediction << [lazar_mutagenicity, {:prediction => sa_prediction, :confidence => confidence}] + prediction["Consensus prediction"] = sa_prediction[:prediction] == false ? "non-mutagenic" : "mutagenic" + prediction["Consensus confidence"] = confidence.signif(3) + prediction["Structural alerts for mutagenicity"] = sa_prediction[:matches].blank? ? "none" : sa_prediction[:matches].collect{|a| a.first}.join("; ") else - prediction << model.predict(@compound) + prediction = model.predict(@compound) end prediction_object[:compound] = @compound.id prediction_object[:model] = model.id diff --git a/views/prediction.haml b/views/prediction.haml index 4660112..b4b51ca 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -25,19 +25,19 @@ - toxtree = @predictions.pop if @toxtree == true - unless @predictions.blank? - @predictions.each_with_index do |prediction,i| - - if prediction.dimension > 0 - - sa_prediction = prediction[1] - - prediction = prediction[0] - - type = @models[i].model.class.to_s.match("Classification") ? "Classification" : "Regression" + - if prediction["Consensus prediction"] + - sa_prediction = true + - type = (@models[i].regression? ? "Regression" : "Classification") - @model_types[i] = type - unit = @models[i].unit %td{:style=>"vertical-align:top;white-space:nowrap;"} %b.title = (sa_prediction ? "Consensus mutagenicity" : "#{@models[i].endpoint.gsub('_', ' ')} (#{@models[i].species})") + %p / check kazius - if sa_prediction - - hash = sa_prediction[:prediction] - - confidence = sa_prediction[:confidence] + - sa_value = prediction["Consensus prediction"] + - confidence = prediction["Consensus confidence"] / check for database hit - if prediction[:info] =~ /\b(identical)\b/i - @dbhit[i] = true @@ -52,21 +52,21 @@ = prediction[:measurements].join("; ") %b Consensus prediction: %br - =(hash[:prediction] == true ? "mutagenic" : "non-mutagenic") + = sa_value %p %b Consensus confidence: %br - =confidence.to_f.signif(3) + = confidence %p %b Structural alerts for mutagenicity: %br - =hash[:matches].blank? ? "none" : hash[:matches].join("; ") + = prediction["Structural alerts for mutagenicity"].gsub(";","
") / check for prediction - %p - / regression - if prediction[:value] - %b.title= ("Lazar #{@models[i].endpoint.gsub('_', ' ').downcase} (#{@models[i].species}):" if sa_prediction) %p + - if sa_prediction + %b.title= ("Lazar #{@models[i].endpoint.gsub('_', ' ').downcase} (#{@models[i].species}):") + %p / check for database hit - if prediction[:info] =~ /\b(identical)\b/i - @dbhit[i] = true -- cgit v1.2.3