From 120ae520e6a72bb9f32bd904767decb87882b260 Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 1 Nov 2017 15:41:34 +0000 Subject: fixed cramer --- application.rb | 99 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 40 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index b46c5d2..e4b9e38 100644 --- a/application.rb +++ b/application.rb @@ -207,49 +207,61 @@ get '/task/?' do smiles = compound.smiles task = Task.find(params[:predictions].to_s) unless task.predictions[params[:model]].nil? - html = "" - html += "" - string = "
#{image}
#{smiles}
" - prediction = task.predictions[params[:model]][pageNumber.to_i] - sorter = [] - if prediction[:info] - 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]}"} + if params[:model] == "Cramer" + prediction = task.predictions[params[:model]] + html = "
" + html += "" + string = "" + html += "#{string}
#{image}
#{smiles}
" + string += "" + string += "" + string += "
Cramer rules:#{prediction["Cramer rules"][pageNumber.to_i]}
Cramer rules, with extensions:#{prediction["Cramer rules, with extensions"][pageNumber.to_i]}
" + else + html = "" + html += "" + string = "" + html += "#{string}
#{image}
#{smiles}
" + prediction = task.predictions[params[:model]][pageNumber.to_i] + sorter = [] + $logger.debug prediction + if prediction[:info] + 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 - 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 - sorter.each_with_index do |hash,idx| - k = hash.keys[0] - v = hash.values[0] - string += (idx == 0 ? "" : "")+(k =~ /lazar/i ? "" + # 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 + sorter.each_with_index do |hash,idx| + k = hash.keys[0] + v = hash.values[0] + string += (idx == 0 ? "" : "")+(k =~ /lazar/i ? "" + end + string += "
" : "") - # keyword - string += "#{k}:" - string += "" - # values - string += "#{v}" - string += "
" : "") + # keyword + string += "#{k}:" + string += "" + # values + string += "#{v}" + string += "
" end - string += "
" - html += "#{string}" end return JSON.pretty_generate(:predictions => [html]) end @@ -409,6 +421,13 @@ post '/predict/?' do "#{output["cramer_rules"][idx] != "nil" ? output["cramer_rules"][idx] : "none" },"\ "#{output["cramer_rules_extensions"][idx] != "nil" ? output["cramer_rules_extensions"][idx] : "none"}\n" end + #predictions = [] + #predictions << {"Cramer rules" => output["cramer_rules"]} + #predictions << {"Cramer rules, with extensions" => output["cramer_rules_extensions"]} + predictions = {} + predictions["Cramer rules"] = output["cramer_rules"].collect{|rule| rule != "nil" ? rule : "none"} + predictions["Cramer rules, with extensions"] = output["cramer_rules_extensions"].collect{|rule| rule != "nil" ? rule : "none"} + # write csv t[:csv] = csv # write predictions -- cgit v1.2.3