From 40bd4a94087d1306ab71774484464312f6fd9320 Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 1 Nov 2017 14:53:38 +0000 Subject: serial batch prediction with task; TODO cleanup code to methods; include helper file --- application.rb | 71 +++++++++++++++++++++++++++++++++++++++++++++----------- views/style.scss | 3 +++ views/task.haml | 3 --- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/application.rb b/application.rb index 4f73ad6..b46c5d2 100644 --- a/application.rb +++ b/application.rb @@ -207,27 +207,51 @@ get '/task/?' do smiles = compound.smiles task = Task.find(params[:predictions].to_s) unless task.predictions[params[:model]].nil? - array = [] html = "" html += "" string = "" html += "#{string}
#{image}
#{smiles}
" prediction = task.predictions[params[:model]][pageNumber.to_i] - sort = [] + sorter = [] if prediction[:info] - sort << {"info" => prediction[:info]} - sort << {"measurements" => prediction[:measurements].join("
")} - prediction.delete("info") - prediction.delete("measurements") + sorter << {"Info" => prediction[:info]} + if prediction[:measurements_string].kind_of?(Array) + sorter << {"Measured activity" => "#{prediction[:measurements_string].join(";")}
#{prediction[:converted_measurements].join(";")}"} + else + sorter << {"Measured activity" => "#{prediction[:measurements_string]}
#{prediction[:converted_measurements]}"} + end + end + + # regression + if prediction[:prediction_interval] + sorter << {"Prediction" => "#{prediction[:prediction_value]}
#{prediction[:converted_prediction_value]}"} + sorter << {"95% Prediction interval" => "#{prediction[:interval]}
#{prediction[:converted_interval]}"} + sorter << {"Warnings" => prediction[:warnings].join("
")} + # classification + elsif prediction[:probabilities] + sorter << {"Consensus prediction" => prediction["Consensus prediction"]} + sorter << {"Consensus confidence" => prediction["Consensus confidence"]} + sorter << {"Structural alerts for mutagenicity" => prediction["Structural alerts for mutagenicity"]} + sorter << {"Lazar mutagenicity (Salmonella typhimurium)" => ""} + sorter << {"Prediction" => prediction[:value]} + sorter << {"Probability" => prediction[:probabilities].collect{|k,v| "#{k}: #{v.signif(3)}"}.join("
")} + else + sorter << {"Warnings" => prediction[:warnings].join("
")} end - task.predictions[params[:model]][pageNumber.to_i].each do |k,v| - string += " "\ - "" + sorter.each_with_index do |hash,idx| + k = hash.keys[0] + v = hash.values[0] + string += (idx == 0 ? "" : "")+(k =~ /lazar/i ? "" end string += "
#{(k=="value" ? "prediction" : k).capitalize}:#{v.blank? ? "none" : (v.kind_of?(Array) ? v.join("\
") : v)}
" : "") + # keyword + string += "#{k}:" + string += "" + # values + string += "#{v}" + string += "
" - array << [html] end - return JSON.pretty_generate(:predictions => array) + return JSON.pretty_generate(:predictions => [html]) end end @@ -338,9 +362,30 @@ post '/predict/?' do end prediction["Consensus prediction"] = sa_prediction[:prediction] == false ? "non-mutagenic" : "mutagenic" prediction["Consensus confidence"] = confidence.signif(3) - prediction["Structural alerts for mutagenicity"] = sa_prediction[:matches] ? sa_prediction[:matches].collect{|a| a.first}.join("; ") : "none" + prediction["Structural alerts for mutagenicity"] = sa_prediction[:matches].blank? ? "none" : sa_prediction[:matches].collect{|a| a.first}.join("; ") + end + # regression + unless prediction[:value].blank? + if type == "Regression" + prediction[:prediction_value] = "#{prediction[:value].delog10.signif(3)} #{unit}" + prediction["converted_prediction_value"] = "#{compound.mmol_to_mg(prediction[:value].delog10).signif(3)} #{converted_unit}" + end + end + unless prediction[:prediction_interval].blank? + interval = prediction[:prediction_interval] + prediction[:interval] = "#{interval[1].delog10.signif(3)} - #{interval[0].delog10.signif(3)} #{unit}" + prediction[:converted_interval] = "#{compound.mmol_to_mg(interval[1].delog10).signif(3)} - #{compound.mmol_to_mg(interval[0].delog10).signif(3)} #{converted_unit}" + end + prediction["unit"] = unit + prediction["converted_unit"] = converted_unit + if prediction[:measurements].is_a?(Array) + prediction["measurements_string"] = (type == "Regression") ? prediction[:measurements].collect{|value| "#{value.delog10.signif(3)} #{unit}"} : prediction[:measurements].join("
") + prediction["converted_measurements"] = prediction[:measurements].collect{|value| "#{compound.mmol_to_mg(value.delog10).signif(3)} #{unit =~ /mmol\/L/ ? "(mg/L)" : "(mg/kg_bw/day)"}"} if type == "Regression" + else + output["measurements_string"] = (type == "Regression") ? "#{prediction[:measurements].delog10.signif(3)} #{unit}}" : prediction[:measurements] + output["converted_measurements"] = "#{compound.mmol_to_mg(prediction[:measurements].delog10).signif(3)} #{(unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" if type == "Regression" end - predictions << prediction.delete_if{|k,v| k =~ /neighbors|prediction_feature_id/i} + predictions << prediction.delete_if{|k,v| k =~ /neighbors|prediction_feature_id|r_squared|rmse/i} t.update_percent((counter*p).ceil) counter += 1 end diff --git a/views/style.scss b/views/style.scss index 2510864..46c57c6 100644 --- a/views/style.scss +++ b/views/style.scss @@ -105,6 +105,9 @@ supporters{ table-layout: fixed; width: 100%; } +tr.hide-top > td { + border-top: 0px !important; +} .footer{ margin-top:3em; } diff --git a/views/task.haml b/views/task.haml index f88bdc2..a81f764 100644 --- a/views/task.haml +++ b/views/task.haml @@ -84,9 +84,6 @@ $('#pager_'+id).hide(); }; }; - $("a").click(function(event) { - event.preventDefault(); - }); %div.well %a.btn.btn-warning{:href => to('/predict')} %span.glyphicon.glyphicon-menu-left{:aria=>{:hidden=>"true"}} -- cgit v1.2.3