summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-11-06 13:43:20 +0000
committergebele <gebele@in-silico.ch>2017-11-06 13:43:20 +0000
commitf9f3faf930a9c348d81646dd9ef60e48821444a7 (patch)
tree654e338ff9f31522cb787d615081f306915f5842
parentb7e1a4bb8b8e47326928171044c0d7b54d62e278 (diff)
various small fixes
-rw-r--r--application.rb23
-rw-r--r--helper.rb20
2 files changed, 20 insertions, 23 deletions
diff --git a/application.rb b/application.rb
index 0957d71..13df650 100644
--- a/application.rb
+++ b/application.rb
@@ -3,12 +3,7 @@ require_relative 'prediction.rb'
require_relative 'helper.rb'
include OpenTox
-configure :production do
- $logger = Logger.new(STDOUT)
- enable :reloader
-end
-
-configure :development do
+configure :production, :development do
$logger = Logger.new(STDOUT)
enable :reloader
end
@@ -31,9 +26,10 @@ get '/?' do
end
get '/predict/?' do
- if params[:tpid] && !params[:tpid].blank?
- pid = params[:tpid].to_i
- Process.kill(9,pid) #if (Process.getpgid(pid) rescue nil).present?
+ begin
+ Process.kill(9,params[:tpid].to_i) if !params[:tpid].blank? #if (Process.getpgid(pid) rescue nil).present?
+ rescue
+ nil
end
@models = Model::Validation.all
@models = @models.delete_if{|m| m.model.name =~ /\b(Net cell association)\b/}
@@ -134,10 +130,12 @@ end
get '/predict/csv/:task/:model/:filename/?' do
response['Content-Type'] = "text/csv"
task = Task.find params[:task].to_s
+ m = Model::Validation.find params[:model].to_s
+ endpoint = (params[:model] == "Cramer") ? "Oral_toxicity_(Cramer_rules)" : (m.endpoint =~ /Mutagenicity/i ? "Consensus_mutagenicity" : "#{m.endpoint}_(#{m.species})")
tempfile = Tempfile.new
tempfile.write(task.csv)
tempfile.rewind
- send_file tempfile, :filename => "#{Time.now.strftime("%Y-%m-%d")}_lazar_batch_prediction_#{params[:model]}_#{params[:filename]}", :type => "text/csv", :disposition => "attachment"
+ send_file tempfile, :filename => "#{Time.now.strftime("%Y-%m-%d")}_lazar_batch_prediction_#{endpoint}_#{params[:filename]}", :type => "text/csv", :disposition => "attachment"
end
post '/predict/?' do
@@ -186,7 +184,7 @@ 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,Unique SMILES,inTrainingSet,Measurements,Prediction #{unit},Prediction #{converted_unit},"\
+ header = "ID,Endpoint,Unique SMILES,inTrainingSet,Measurements #{unit},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"
@@ -204,7 +202,6 @@ post '/predict/?' do
predictions = []
@compounds.each do |compound|
if Prediction.where(compound: compound.id, model: m.id).exists?
- $logger.debug "prediction already exists !"
prediction = Prediction.find_by(compound: compound.id, model: m.id).prediction
else
prediction = m.predict(compound)
@@ -297,8 +294,8 @@ post '/predict/?' do
end#main task
@pid = task.pid
- $logger.debug "application pid: #{@pid}"
+ #@dataset.delete
File.delete File.join("tmp", params[:fileselect][:filename])
return haml :batch
end
diff --git a/helper.rb b/helper.rb
index 12a6ce2..3bd1755 100644
--- a/helper.rb
+++ b/helper.rb
@@ -59,7 +59,7 @@ helpers do
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."
+ "prediction to obtain unbiased results."
end
note = "\"#{prediction[:warnings].uniq.join(" ")}\""
@@ -69,11 +69,11 @@ helpers do
output["db_hit"] = prediction[:info] if prediction[:info]
if prediction[:measurements].is_a?(Array)
- output["measurements"] = (type == "Regression") ? prediction[:measurements].collect{|value| "#{value.delog10.signif(3)} (#{model.unit})"} : prediction[:measurements].collect{|value| "#{value}"}
- output["converted_measurements"] = (type == "Regression") ? prediction[:measurements].collect{|value| "#{compound.mmol_to_mg(value.delog10).signif(3)} #{model.unit =~ /mmol\/L/ ? "(mg/L)" : "(mg/kg_bw/day)"}"} : false
+ output["measurements"] = (type == "Regression") ? prediction[:measurements].collect{|value| "#{value.delog10.signif(3)}"} : prediction[:measurements].collect{|value| "#{value}"}
+ output["converted_measurements"] = (type == "Regression") ? prediction[:measurements].collect{|value| "#{compound.mmol_to_mg(value.delog10).signif(3)}"} : false
else
- output["measurements"] = (type == "Regression") ? "#{prediction[:measurements].delog10.signif(3)} (#{model.unit})}" : "#{prediction[:measurements]}"
- output["converted_measurements"] = (type == "Regression") ? "#{compound.mmol_to_mg(prediction[:measurements].delog10).signif(3)} #{(model.unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : false
+ output["measurements"] = (type == "Regression") ? "#{prediction[:measurements].delog10.signif(3)}" : "#{prediction[:measurements]}"
+ output["converted_measurements"] = (type == "Regression") ? "#{compound.mmol_to_mg(prediction[:measurements].delog10).signif(3)}" : false
end #db_hit
@@ -86,7 +86,7 @@ helpers do
end #prediction interval
line += "#{idx+1},#{output['model_name']},#{compound.smiles},"\
- "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{prediction[:measurements].join("; ") if prediction[:info]}\","\
+ "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{output['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},"\
@@ -117,7 +117,7 @@ helpers do
output['probability'] = prediction[:probabilities] ? prediction[:probabilities].collect{|k,v| "#{k}: #{v.signif(3)}"} : false
line += "#{idx+1},Consensus mutagenicity,#{compound.smiles},"\
- "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{prediction[:measurements].join("; ") if prediction[:info]}\","\
+ "\"#{prediction[:info] ? prediction[:info] : "no"}\",\"#{output['measurements'].join("; ") if prediction[:info]}\","\
"#{sa_prediction[:prediction] == false ? "non-mutagenic" : "mutagenic"},"\
"#{output['confidence']},#{output['sa_matches'] != false ? "\"#{output['sa_matches']}\"" : "none"},"\
"#{output['prediction_value']},"\
@@ -134,7 +134,7 @@ helpers do
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."
+ "prediction to obtain unbiased results."
end
note = "\"#{prediction[:warnings].join(" ")}\""
@@ -143,10 +143,10 @@ helpers do
if type == "Regression"
line += "#{idx+1},#{output['model_name']},#{compound.smiles},#{prediction[:info] ? prediction[:info] : "no"},"\
- "#{prediction[:measurements] if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
+ "#{prediction[:measurements].collect{|m| m.delog10.signif(3)}.join("; ") if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
else
line += "#{idx+1},Consensus mutagenicity,#{compound.smiles},#{prediction[:info] ? prediction[:info] : "no"},"\
- "#{prediction[:measurements] if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
+ "#{prediction[:measurements].join("; ") if prediction[:info]},,,,,,,"+ [inApp,note].join(",")+"\n"
end
end