summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-10-20 12:50:37 +0000
committergebele <gebele@in-silico.ch>2017-10-20 12:50:37 +0000
commita1e050bb6b4b4ddd37881daa74d7f12dccce0b0f (patch)
treea22832322dee98bcb2ee282a31df011b8aa8f054
parent315db036a63defb5465178279cbc3cbffde375eb (diff)
adjusted order of elements
-rw-r--r--application.rb59
-rw-r--r--views/batch.haml34
-rw-r--r--views/predict.haml2
-rw-r--r--views/prediction.haml42
4 files changed, 71 insertions, 66 deletions
diff --git a/application.rb b/application.rb
index a4f632a..dc46bf7 100644
--- a/application.rb
+++ b/application.rb
@@ -135,14 +135,13 @@ get '/batch/:model/' do
end
if prediction[:value]
- inApp = prediction[:neighbors] ? "yes" : "no"
- inT = prediction[:info] =~ /\b(identical)\b/i ? "yes" : "no"
+ inApp = (prediction[:warnings].join(" ") =~ /Cannot/ ? "no" : (prediction[:warnings].join(" ") =~ /may|Insufficient/ ? "maybe" : "yes"))
if prediction[:info] =~ /\b(identical)\b/i
prediction[:info] = "This compound was part of the training dataset. All information "\
"from this compound was removed from the training data before the "\
"prediction, to obtain unbiased results."
end
- note = "\"#{prediction[:warnings].uniq.join(" ")}" + ( prediction[:info] ? "#{prediction[:info]}\"" : "\"" )
+ note = "\"#{prediction[:warnings].uniq.join(" ")}\""
output["prediction_value"] = (type == "Regression") ? "#{prediction[:value].delog10.signif(3)}" : "#{prediction[:value]}"
output["converted_value"] = "#{compound.mmol_to_mg(prediction[:value].delog10).signif(3)}" if type == "Regression"
@@ -166,14 +165,15 @@ get '/batch/:model/' do
output['converted_interval'] = "#{compound.mmol_to_mg(interval[1].delog10).signif(3)} - #{compound.mmol_to_mg(interval[0].delog10).signif(3)}"
end #prediction interval
- csv = "#{idx+1},#{output['model_name']},#{output['model_type']},#{compound.smiles},"\
- "#{output['prediction_value'] != false ? output['prediction_value'] : "-"},"\
- "#{output['converted_value'] != false ? output['converted_value'] : "-"},"\
+ csv = "#{idx+1},#{output['model_name']},#{compound.smiles},"\
+ "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{prediction[:measurements].join("; ") if prediction[:info]}\","\
+ "#{output['prediction_value'] != false ? output['prediction_value'] : ""},"\
+ "#{output['converted_value'] != false ? output['converted_value'] : ""},"\
"#{output['interval'].split(" - ").first.strip unless output['interval'] == false},"\
"#{output['interval'].split(" - ").last.strip unless output['interval'] == false},"\
"#{output['converted_interval'].split(" - ").first.strip unless output['converted_interval'] == false},"\
"#{output['converted_interval'].split(" - ").last.strip unless output['converted_interval'] == false},"\
- "#{inApp},#{inT},#{note.nil? ? "" : note.chomp}\n"
+ "#{inApp},#{note.nil? ? "" : note.chomp}\n"
else # Classification
# consensus mutagenicity
@@ -191,19 +191,20 @@ get '/batch/:model/' do
elsif sa_prediction[:prediction] == true && lazar_mutagenicity_val == false
confidence = ( 1 - sa_prediction[:error_product] ) - 0.57
end
- output["sa_prediction"] = sa_prediction
- output["sa_matches"] = sa_prediction[:matches].flatten.first unless sa_prediction[:matches].blank?
- output["confidence"] = confidence.signif(3)
- output["model_name"] = "Lazar #{model.endpoint.gsub('_', ' ').downcase} (#{model.species}):"
- output["probability"] = prediction[:probabilities] ? prediction[:probabilities].collect{|k,v| "#{k}: #{v.signif(3)}"} : false
+ output['sa_prediction'] = sa_prediction
+ output['sa_matches'] = sa_prediction[:matches].flatten unless sa_prediction[:matches].blank?
+ output['confidence'] = confidence.signif(3)
+ output['model_name'] = "Lazar #{model.endpoint.gsub('_', ' ').downcase} (#{model.species}):"
+ output['probability'] = prediction[:probabilities] ? prediction[:probabilities].collect{|k,v| "#{k}: #{v.signif(3)}"} : false
csv = "#{idx+1},Consensus mutagenicity,#{compound.smiles},"\
- "#{output['sa_prediction']['prediction'] == false ? "non-mutagenic" : "mutagenic"},"\
- "#{output['confidence']},#{output['sa_matches'] != false ? "\"#{output['sa_matches']}\"" : "none"}, ,"\
- "#{output['model_type']},#{output['prediction_value']},"\
+ "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{prediction[:measurements].join("; ") if prediction[:info]}\","\
+ "#{sa_prediction[:prediction] == false ? "non-mutagenic" : "mutagenic"},"\
+ "#{output['confidence']},#{output['sa_matches'] != false ? "\"#{output['sa_matches'].join("; ")}\"" : "none"},"\
+ "#{output['prediction_value']},"\
"#{output['probability'][0] != false ? output['probability'][0].split(":").last : ""},"\
"#{output['probability'][1] != false ? output['probability'][1].split(":").last : ""},"\
- "#{inApp},#{inT},#{note.nil? ? "" : note}\n"
+ "#{inApp},#{note.nil? ? "" : note}\n"
end
@@ -211,21 +212,22 @@ get '/batch/:model/' do
else #no prediction value
inApp = "no"
- inT = prediction[:info] =~ /\b(identical)\b/i ? "yes" : "no"
if prediction[:info] =~ /\b(identical)\b/i
prediction[:info] = "This compound was part of the training dataset. All information "\
"from this compound was removed from the training data before the "\
"prediction, to obtain unbiased results."
end
- note = "\"#{prediction[:warnings].join(" ")}\"" + ( prediction[:info] ? "\"#{prediction[:info]}\"" : "" )
+ note = "\"#{prediction[:warnings].join(" ")}\""
output["warnings"] = prediction[:warnings]
output["info"] = prediction[:info] if prediction[:info]
if type == "Regression"
- csv = "#{idx+1},#{output['model_name']},#{output['model_type']},#{compound.smiles},,,,,,,"+ [inApp,inT,note].join(",")+"\n"
+ csv = "#{idx+1},#{output['model_name']},#{compound.smiles},#{prediction[:info] ? prediction[:info] : "no"},"\
+ "#{prediction[:measurements] if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
else
- csv = "#{idx+1},Consensus mutagenicity,#{compound.smiles},,,,,#{output['model_type']},,,,"+ [inApp,inT,note].join(",")+"\n"
+ csv = "#{idx+1},Consensus mutagenicity,#{compound.smiles},#{prediction[:info] ? prediction[:info] : "no"},"\
+ "#{prediction[:measurements] if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
end
end #prediction value
@@ -256,7 +258,9 @@ post '/predict/?' do
$logger.debug "save dataset #{params[:fileselect][:filename]}"
if input.class == OpenTox::Dataset
@dataset = Dataset.find input
+ $logger.debug "get compounds"
@compounds = @dataset.compounds
+ $logger.debug "get compounds finish"
else
bad_request_error "Could not serialize file '#{@filename}'."
end
@@ -272,6 +276,7 @@ post '/predict/?' do
@models = params[:selection].keys
@tmppaths = {}
+ $logger.debug "get endpoint"
@models.each do |model|
m = Model::Validation.find model
type = (m.regression? ? "Regression" : "Classification") unless model == "Cramer"
@@ -279,21 +284,23 @@ post '/predict/?' do
if type == "Regression"
unit = (type == "Regression") ? "(#{m.unit})" : ""
converted_unit = (type == "Regression") ? "#{m.unit =~ /\b(mmol\/L)\b/ ? "(mg/L)" : "(mg/kg_bw/day)"}" : ""
- header = "ID,Endpoint,Type,Unique SMILES,Prediction #{unit},Prediction #{converted_unit},"\
- "Interval Low #{unit},Interval High #{unit},Interval Low #{converted_unit},Interval High #{converted_unit},"\
- "inApplicabilityDomain,inTrainningSet,Note\n"
+ header = "ID,Endpoint,Unique SMILES,inTrainingSet,Measurements,Prediction #{unit},Prediction #{converted_unit},"\
+ "Prediction Interval Low #{unit},Prediction Interval High #{unit},"\
+ "Prediction Interval Low #{converted_unit},Prediction Interval High #{converted_unit},"\
+ "inApplicabilityDomain,Note\n"
end
# add header for classification
if type == "Classification"
av = m.prediction_feature.accept_values
- header = "ID,Endpoint,Unique SMILES,Structural alerts prediction,Structural alerts confidence,"\
- "Structural alerts for mutagenicity,Lazar mutagenicity (Salmonella typhimurium),Type,Prediction,"\
- "predProbability #{av[0]},predProbability #{av[1]},inApplicabilityDomain,inTrainningSet,Note\n"
+ header = "ID,Endpoint,Unique SMILES,inTrainingSet,Measurements,Consensus Prediction,Consensus Confidence,"\
+ "Structural alerts for mutagenicity,Lazar Prediction,"\
+ "Lazar predProbability #{av[0]},Lazar predProbability #{av[1]},inApplicabilityDomain,Note\n"
end
path = File.join("tmp", "#{Time.now.strftime("%Y-%m-%d")}_#{SecureRandom.urlsafe_base64(5)}")
File.open(path, "w"){|f| f.write(header) if header}
@tmppaths[model] = path.split("/").last
end
+ $logger.debug "get endpoint finished"
File.delete File.join("tmp", params[:fileselect][:filename])
return haml :batch
diff --git a/views/batch.haml b/views/batch.haml
index aaa09bf..fccd88c 100644
--- a/views/batch.haml
+++ b/views/batch.haml
@@ -26,10 +26,10 @@
// create request
if (model == "Cramer"){
var dataset = '#{@dataset.id}';
- var uri = "#{to("/batch/")}" + model + '/?dataset=' + escape(dataset) + '&tmppath=' + tmppath + '&last=' + last;
+ var uri = "#{to("/batch/")}" + model + '/?dataset=' + escape(dataset) + '&tmppath=' + tmppath;
} else {
var dataset = '#{@dataset.id}';
- var uri = "#{to("/batch/")}" + model + '/?compound=' + escape(compound) + '&dataset=' + dataset + '&idx=' + idx + '&tmppath=' + tmppath + '&last=' + last;
+ var uri = "#{to("/batch/")}" + model + '/?compound=' + escape(compound) + '&dataset=' + dataset + '&idx=' + idx + '&tmppath=' + tmppath;
};
var aClient = new HttpClient();
aClient.get(uri, function(res) {
@@ -56,15 +56,20 @@
if (response['db_hit'] != false){
var value = document.createTextNode(response['db_hit']);
p.appendChild(value);
+ var h2 = document.createElement("h5");
+ var t = document.createTextNode("Measurements:");
+ h2.appendChild(t);
+ p.appendChild(h2);
+ for (var i=0; i<response['measurements'].length; i++){
+ var value = document.createTextNode(response['measurements'][i]);
+ var br = document.createElement("br");
+ p.appendChild(value);
+ p.appendChild(br);
+ };
};
- // Structural alerts
- var h2 = document.createElement("h5");
- var t = document.createTextNode("Structural alerts:");
- h2.appendChild(t);
- p.appendChild(h2);
- // prediction
+ // Consensus prediction
var h3 = document.createElement("h5");
- var t = document.createTextNode("Prediction:");
+ var t = document.createTextNode("Consensus prediction:");
if (response['sa_prediction']['prediction'] == false){
var value = document.createTextNode("non-mutagenic");
};
@@ -74,9 +79,9 @@
h3.appendChild(t);
p.appendChild(h3);
p.appendChild(value);
- // confidence
+ // Consensus confidence
var h4 = document.createElement("h5");
- var t = document.createTextNode("Confidence:");
+ var t = document.createTextNode("Consensus confidence:");
var value = document.createTextNode(response['confidence']);
h4.appendChild(t);
p.appendChild(h4);
@@ -110,13 +115,6 @@
var value = document.createTextNode(response['model_name']);
h.appendChild(value);
p.appendChild(h);
- } else if (val == "type") {
- var t = document.createTextNode("Type: ");
- var value = document.createTextNode(response['model_type']);
- h.appendChild(t);
- p.appendChild(h);
- p.appendChild(value);
- h.style.display = "inline";
} else if (val == "db_hit" && response['db_hit'] != false && response['sa_prediction'] == false) {
var value = document.createTextNode(response['db_hit']);
p.appendChild(value);
diff --git a/views/predict.haml b/views/predict.haml
index eb9047b..6b1c462 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -130,7 +130,7 @@
%a.btn.glyphicon.glyphicon-info-sign{:href=>"javascript:void(0)", :title=>"File format", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"auto", html:"true", content:"One column with compounds and keyword SMILES or InChI in the first row."}}
%br
%span.btn.btn-default.btn-file
- %input{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>"text/csv"}
+ %input{:type=>"file", :name=> "fileselect", :id=>"fileselect", :autocomplete=>"off", :accept=>"text/csv"}
%fieldset#middle.well
%h2 2. Select one or more endpoints
diff --git a/views/prediction.haml b/views/prediction.haml
index b5a7e82..872ee1e 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -38,39 +38,34 @@
- if sa_prediction
- hash = sa_prediction[:prediction]
- confidence = sa_prediction[:confidence]
- %p
- %b Structural alerts:
- %p
/ check for database hit
- if prediction[:info] =~ /\b(identical)\b/i
- @dbhit[i] = true
- / show message about dbhit and measurements
%p
:plain
This compound was part of the training dataset. <i>All</i> information </br>
from this compound was removed from the training data before the </br>
prediction, to obtain unbiased results.
%p
- %b Prediction:
+ %b Measured activity:
+ %br
+ = prediction[:measurements].join("; ")
+ %b Consensus prediction:
%br
=(hash[:prediction] == true ? "mutagenic" : "non-mutagenic")
%p
- %b Confidence:
+ %b Consensus confidence:
%br
=confidence.to_f.signif(3)
%p
%b Structural alerts for mutagenicity:
%br
- =hash[:matches].flatten.first
- %p
+ =hash[:matches].blank? ? "none" : hash[:matches].join("; ")
/ check for prediction
+ %p
- if prediction[:neighbors] and !prediction[:value].nil?
%b.title= ("Lazar #{@models[i].endpoint.gsub('_', ' ').downcase} (#{@models[i].species}):" if sa_prediction)
%p
- / show model type (classification|regression)
- %b Type:
- = type
- %p
/ check for database hit
- if prediction[:info] =~ /\b(identical)\b/i
- @dbhit[i] = true
@@ -81,14 +76,14 @@
This compound was part of the training dataset. <i>All</i> information </br>
from this compound was removed from the training data before the </br>
prediction, to obtain unbiased results.
- %p
+ %p
%b Measured activity:
%br
- if prediction[:measurements].is_a?(Array)
= (type == "Regression") ? prediction[:measurements].collect{|value| "#{value.delog10.signif(3)} (#{unit})</br>#{@compound.mmol_to_mg(value.delog10).signif(3)} #{unit =~ /mmol\/L/ ? "(mg/L)" : "(mg/kg_bw/day)"}"}.join("</br>") : prediction[:measurements].join(", ")
- else
= (type == "Regression") ? "#{prediction[:measurements].delog10.signif(3)} (#{unit})</br>#{@compound.mmol_to_mg(prediction[:measurements].delog10).signif(3)} #{(unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:measurements]
-
+
- else
- @dbhit[i] = false
@@ -116,16 +111,23 @@
%br
= "#{prediction[:probabilities].keys[1]}: #{prediction[:probabilities].values[1].signif(3)}"
+ %p
+ - if !prediction[:warnings].blank?
+ %b Warnings:
+ %br
+ =prediction[:warnings].join("</br>")
+
- else
%p
- if !prediction[:info].blank?
- %b Info:
- %br
- %p=prediction[:info].sub(/\'.*\'/,"").sub(/,/, ",<br>")
+ :plain
+ This compound was part of the training dataset. <i>All</i> information </br>
+ from this compound was removed from the training data before the </br>
+ prediction, to obtain unbiased results.
- if !prediction[:warnings].blank?
%b Warnings:
- - prediction[:warnings].uniq.each do |warning|
- %p=warning.sub(/,/, ",<br>")
+ %br
+ =prediction[:warnings].join("</br>")
/ show Cramer rules if checked
- if @toxtree == true
@@ -143,5 +145,3 @@
/ always show the neighbors table, message is given there. Except only Cramer is selected.
- unless @predictions.blank?
= haml :neighbors, :layout => false
-
-