summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-07-14 13:56:50 +0200
committerChristoph Helma <helma@in-silico.ch>2010-07-14 13:56:50 +0200
commitfc0f9e5fa3b521397d2026e649c4873600026838 (patch)
treef5bb033210085328e47ba3acac0c0f6906b30519
parent5eec83b4196c84b32817d045d31b0815db38fb05 (diff)
model creation working, validation report generation fails for large datasets
-rw-r--r--application.rb22
-rw-r--r--model.rb49
-rw-r--r--views/regression_validation.haml14
3 files changed, 57 insertions, 28 deletions
diff --git a/application.rb b/application.rb
index c18a394..5d5435e 100644
--- a/application.rb
+++ b/application.rb
@@ -51,21 +51,27 @@ end
get '/model/:id/:view/?' do
response['Content-Type'] = 'text/plain'
model = ToxCreateModel.get(params[:id])
- model = model.process
+ model.process
+ model.save
begin
case params[:view]
when "model"
haml :model, :locals=>{:model=>model}, :layout => false
- when "classification_validation"
- haml :classification_validation, :locals=>{:model=>model}, :layout => false
- when "regression_validation"
- haml :regression_validation, :locals=>{:model=>model}, :layout => false
+ when /validation/
+ if model.type == "classification"
+ haml :classification_validation, :locals=>{:model=>model}, :layout => false
+ elsif model.type == "regression"
+ haml :regression_validation, :locals=>{:model=>model}, :layout => false
+ else
+ return "Unknown model type '#{model.type}'"
+ end
else
- return "render error"
+ return "unable to render model: id #{params[:id]}, view #{params[:view]}"
+ #return "render error"
end
rescue
- return "unable to render model"
+ return "unable to render model: id #{params[:id]}, view #{params[:view]}"
end
end
@@ -145,7 +151,7 @@ post '/upload' do # create a new model
@model.warnings += "<p>Duplicated structures (all structures/activities used for model building, please make sure, that the results were obtained from <em>independent</em> experiments):</p>" + duplicate_warnings unless duplicate_warnings.empty?
@model.save
- flash[:notice] = "Model creation started. Please be patient - model building may take up to several hours depending on the number and size of the input molecules."
+ flash[:notice] = "Model creation and validation started - this may last up to several hours depending on the number and size of the training compounds."
redirect url_for('/models')
# TODO: check for empty model
diff --git a/model.rb b/model.rb
index 6430933..5b68558 100644
--- a/model.rb
+++ b/model.rb
@@ -15,7 +15,11 @@ class ToxCreateModel
property :created_at, DateTime
def status
- RestClient.get(File.join(@task_uri, 'hasStatus')).body
+ #begin
+ RestClient.get(File.join(@task_uri, 'hasStatus')).body
+ #rescue
+ # "Service offline"
+ #end
end
def validation_status
@@ -107,36 +111,47 @@ class ToxCreateModel
def process
- if !@uri and status == "Completed"
- @uri = RestClient.get(File.join(@task_uri, 'resultURI')).body
+ if @uri.nil? and status == "Completed"
+ update :uri => RestClient.get(File.join(@task_uri, 'resultURI')).body
lazar = YAML.load(RestClient.get(@uri, :accept => "application/x-yaml").body)
case lazar.dependentVariables
when /classification/
- @type = "classification"
+ update :type => "classification"
when /regression/
- @type = "regression"
+ update :type => "regression"
else
- @type = "unknown"
+ update :type => "unknown"
end
- save
- end
- if !@validation_uri and validation_status == "Completed"
+ elsif @validation_uri.nil? and validation_status == "Completed"
begin
- @validation_uri = RestClient.get(File.join(@validation_task_uri, 'resultURI')).body
+ update :validation_uri => RestClient.get(File.join(@validation_task_uri, 'resultURI')).body
LOGGER.debug "Validation URI: #{@validation_uri}"
- @validation_report_task_uri = RestClient.post(File.join(@@config[:services]["opentox-validation"],"/report/crossvalidation"), :validation_uris => @validation_uri).body
+ update :validation_report_task_uri => RestClient.post(File.join(@@config[:services]["opentox-validation"],"/report/crossvalidation"), :validation_uris => @validation_uri).body
LOGGER.debug "Validation Report Task URI: #{@validation_report_task_uri}"
- save
rescue
+ LOGGER.warn "Cannot create Validation Report Task #{@validation_report_task_uri} for Validation URI #{@validation_uri} from Task #{@validation_task_uri}"
+ end
+
+ elsif @validation_report_uri.nil? and validation_report_status == "Completed"
+ begin
+ LOGGER.debug File.join(@validation_report_task_uri, 'resultURI')
+ LOGGER.debug "Report URI: "+RestClient.get(File.join(@validation_report_task_uri, 'resultURI')).body
+ update :validation_report_uri => RestClient.get(File.join(@validation_report_task_uri, 'resultURI')).body
+ rescue
+ LOGGER.warn "Cannot create Validation Report for Task URI #{@validation_report_task_uri} "
end
end
- if @validation_report_task_uri and !@validation_report_uri and validation_report_status == 'Completed'
- @validation_report_uri = RestClient.get(File.join(@validation_report_task_uri, 'resultURI')).body
- end
- end
- self
+ #LOGGER.debug self.to_yaml
+ #LOGGER.debug @uri
+ #LOGGER.debug @validation_uri
+ #LOGGER.debug @validation_uri.nil?
+ #LOGGER.debug validation_status
+ #LOGGER.debug self.validation_report_task_uri
+ #LOGGER.debug self.validation_report_uri
+ #self.save
+ end
end
diff --git a/views/regression_validation.haml b/views/regression_validation.haml
index 983599b..6f9e106 100644
--- a/views/regression_validation.haml
+++ b/views/regression_validation.haml
@@ -11,9 +11,17 @@
= v
- else
%dl
- %dt Number of predictions:
- %dd= v[:n]
- %p= v.inspect
+ %dt Number of predictions
+ %dd= v[:num_instances] - v[:num_unpredicted]
+ %dt
+ %a{:href => "http://en.wikipedia.org/wiki/R-squared"} R-squared
+ %dd= sprintf '%.03g', v[:regression_statistics][:r_square]
+ %dt
+ %a{:href => "http://en.wikipedia.org/wiki/Root_mean_square_deviation"} Root Mean Square Error
+ %dd= sprintf '%.03g', v[:regression_statistics][:root_mean_squared_error]
+ %dt
+ %a{:href => "http://en.wikipedia.org/wiki/Mean_absolute_error"} Mean Absolute Error
+ %dd= sprintf '%.03g', v[:regression_statistics][:mean_absolute_error]
- else
= image_tag("/snake_transparent.gif") if model.validation_status == "Running"
%a{:href => model.validation_task_uri} #{model.validation_status}