From 347d49d5a0697cba6c8644914f51feb9ff4ecf35 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 17 Aug 2011 14:12:16 +0200 Subject: add subjectids where missing and some code cleanup --- application.rb | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 3b88700..a60e597 100644 --- a/application.rb +++ b/application.rb @@ -81,7 +81,7 @@ end get '/models/?' do @models = ToxCreateModel.all.sort(:order => "DESC") @models.each{|m| raise "internal redis error: model is nil" unless m} - subjectstring = session[:subjectid] ? "?subjectid=#{CGI.escape(session[:subjectid])}" : "" + subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" haml :models, :locals=>{:models=>@models, :subjectstring => subjectstring} end @@ -145,7 +145,7 @@ end get '/model/:id/:view/?' do response['Content-Type'] = 'text/plain' model = ToxCreateModel.get(params[:id]) - subjectstring = session[:subjectid] ? "?subjectid=#{CGI.escape(session[:subjectid])}" : "" + subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" begin case params[:view] when "model" @@ -199,7 +199,7 @@ end post '/feature' do session[:dataset] = params[:dataset] @features = [] - OpenTox::Dataset.new(params[:dataset]).load_features.each do |uri,metadata| + OpenTox::Dataset.new(params[:dataset], @subjectid).load_features(@subjectid).each do |uri,metadata| @features << OpenTox::Feature.find(uri, @subjectid) if metadata[OWL.sameAs].match(/#{session[:echa]}/) end haml :feature @@ -218,18 +218,16 @@ post '/models' do # create a new model redirect url_for('/create') end - subjectid = session[:subjectid] ? session[:subjectid] : nil - if params[:dataset] and params[:prediction_feature] - @dataset = OpenTox::Dataset.new(params[:dataset],subjectid) + @dataset = OpenTox::Dataset.new(params[:dataset], @subjectid) name = @dataset.load_metadata[DC.title] - @prediction_feature = OpenTox::Feature.find params[:prediction_feature], subjectid + @prediction_feature = OpenTox::Feature.find params[:prediction_feature], @subjectid @dataset.load_compounds elsif params[:file][:filename] name = params[:file][:filename].sub(/\..*$/,"") end - @model = ToxCreateModel.create(:name => name, :subjectid => subjectid) + @model = ToxCreateModel.create(:name => name, :subjectid => @subjectid) @model.update :web_uri => url_for("/model/#{@model.id}", :full), :warnings => "" task = OpenTox::Task.create("Toxcreate Task - Uploading dataset and creating lazar model",url_for("/models",:full)) do |task| @@ -238,33 +236,33 @@ post '/models' do # create a new model unless params[:dataset] and params[:prediction_feature] begin - @dataset = OpenTox::Dataset.create(nil, subjectid) + @dataset = OpenTox::Dataset.create(nil, @subjectid) # check format by extension - not all browsers provide correct content-type]) case File.extname(params[:file][:filename]) when ".csv" csv = params[:file][:tempfile].read - @dataset.load_csv(csv, subjectid) + @dataset.load_csv(csv, @subjectid) when ".xls", ".xlsx" excel_file = params[:file][:tempfile].path + File.extname(params[:file][:filename]) File.rename(params[:file][:tempfile].path, excel_file) # add extension, spreadsheet does not read files without extensions - @dataset.load_spreadsheet(Excel.new excel_file, subjectid) + @dataset.load_spreadsheet(Excel.new excel_file, @subjectid) if @dataset.metadata[OT.Errors] raise "Incorrect file format. Please follow the instructions for #{link_to "Excel", "/help"} or #{link_to "CSV", "/help"} formats." end when ".sdf" sdf = params[:file][:tempfile].read - @dataset.load_sdf(sdf, subjectid) + @dataset.load_sdf(sdf, @subjectid) else raise "#{params[:file][:filename]} has an unsupported file type." end - @dataset.save(subjectid) + @dataset.save(@subjectid) rescue => e error "Dataset creation failed '#{e.message}'",e end if @dataset.features.keys.size != 1 error "More than one feature in dataset #{params[:file][:filename]}. Please delete irrelvant columns and try again." else - @prediction_feature = OpenTox::Feature.find(@dataset.features.keys.first,subjectid) + @prediction_feature = OpenTox::Feature.find(@dataset.features.keys.first,@subjectid) end end @@ -276,7 +274,7 @@ post '/models' do # create a new model @model.update :warnings => @dataset.metadata[OT.Warnings] unless @dataset.metadata[OT.Warnings] and @dataset.metadata[OT.Warnings].empty? task.progress(15) begin - lazar = OpenTox::Model::Lazar.create( {:dataset_uri => @dataset.uri, :prediction_feature => @prediction_feature.uri, :subjectid => subjectid}, + lazar = OpenTox::Model::Lazar.create( {:dataset_uri => @dataset.uri, :prediction_feature => @prediction_feature.uri, :subjectid => @subjectid}, OpenTox::SubTask.new(task,15,25)) rescue => e error "Model creation failed",e # Please check if the input file is in a valid #{link_to "Excel", "/help"} or #{link_to "CSV", "/help"} format." @@ -297,7 +295,7 @@ post '/models' do # create a new model crossvalidation = OpenTox::Crossvalidation.create( { :algorithm_uri => lazar.metadata[OT.algorithm], :dataset_uri => lazar.parameter("dataset_uri"), - :subjectid => subjectid, + :subjectid => @subjectid, :prediction_feature => lazar.parameter("prediction_feature"), :algorithm_params => "feature_generation_uri=#{lazar.parameter("feature_generation_uri")}" }, nil, OpenTox::SubTask.new(task,25,80)) @@ -306,7 +304,7 @@ post '/models' do # create a new model LOGGER.debug "Validation URI: #{@model.validation_uri}" # create summary - validation = crossvalidation.statistics(subjectid) + validation = crossvalidation.statistics(@subjectid) @model.update(:nr_predictions => validation.metadata[OT.numInstances].to_i - validation.metadata[OT.numUnpredicted].to_i) if validation.metadata[OT.classificationStatistics] @model.update(:correct_predictions => validation.metadata[OT.classificationStatistics][OT.percentCorrect].to_f) @@ -332,9 +330,9 @@ post '/models' do # create a new model begin @model.update :status => "Creating validation report" - validation_report_uri = crossvalidation.find_or_create_report(subjectid, OpenTox::SubTask.new(task,80,90)) #unless @model.dirty? + validation_report_uri = crossvalidation.find_or_create_report(@subjectid, OpenTox::SubTask.new(task,80,90)) #unless @model.dirty? @model.update :validation_report_uri => validation_report_uri, :status => "Creating QMRF report" - qmrf_report = OpenTox::Crossvalidation::QMRFReport.create(@model.uri, subjectid, OpenTox::SubTask.new(task,90,99)) + qmrf_report = OpenTox::Crossvalidation::QMRFReport.create(@model.uri, @subjectid, OpenTox::SubTask.new(task,90,99)) @model.update(:validation_qmrf_uri => qmrf_report.uri, :status => "Completed") rescue => e error "Model report creation failed",e @@ -353,7 +351,7 @@ post '/models' do # create a new model end post '/predict/?' do # post chemical name to model - subjectid = session[:subjectid] ? session[:subjectid] : nil + @identifier = params[:identifier] unless params[:selection] and params[:identifier] != '' flash[:notice] = "Please enter a compound identifier and select an endpoint from the list." @@ -372,15 +370,15 @@ post '/predict/?' do # post chemical name to model confidence = nil title = nil db_activities = [] - lazar = OpenTox::Model::Lazar.find model.uri - prediction_dataset_uri = lazar.run({:compound_uri => @compound.uri, :subjectid => subjectid}) + lazar = OpenTox::Model::Lazar.find model.uri, @subjectid + prediction_dataset_uri = lazar.run({:compound_uri => @compound.uri, :subjectid => @subjectid}) LOGGER.debug "Prediction dataset_uri: #{prediction_dataset_uri}" if lazar.value_map @value_map = lazar.value_map else @value_map = nil end - prediction_dataset = OpenTox::LazarPrediction.find(prediction_dataset_uri, subjectid) + prediction_dataset = OpenTox::LazarPrediction.find(prediction_dataset_uri, @subjectid) if prediction_dataset.metadata[OT.hasSource].match(/dataset/) @predictions << { :title => model.name, @@ -388,7 +386,7 @@ post '/predict/?' do # post chemical name to model } else predicted_feature = prediction_dataset.metadata[OT.dependentVariables] - prediction = OpenTox::Feature.find(predicted_feature, subjectid) + prediction = OpenTox::Feature.find(predicted_feature, @subjectid) if prediction.metadata[OT.error] @predictions << { :title => model.name, @@ -418,14 +416,14 @@ post "/lazar/?" do # get detailed prediction @page = 0 @page = params[:page].to_i if params[:page] @model_uri = params[:model_uri] - lazar = OpenTox::Model::Lazar.find @model_uri - prediction_dataset_uri = lazar.run(:compound_uri => params[:compound_uri], :subjectid => session[:subjectid]) + lazar = OpenTox::Model::Lazar.find @model_uri, @subjectid + prediction_dataset_uri = lazar.run(:compound_uri => params[:compound_uri], :subjectid => @subjectid) if lazar.value_map @value_map = lazar.value_map else @value_map = nil end - @prediction = OpenTox::LazarPrediction.find(prediction_dataset_uri, session[:subjectid]) + @prediction = OpenTox::LazarPrediction.find(prediction_dataset_uri, @subjectid) @compound = OpenTox::Compound.new(params[:compound_uri]) haml :lazar end -- cgit v1.2.3 From 12b3295738445c941b03b15c34ec9e7f2fb56816 Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 18 Aug 2011 13:06:04 +0200 Subject: optimize ToxCreateModel deletion --- application.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index a60e597..8ace27c 100644 --- a/application.rb +++ b/application.rb @@ -31,7 +31,7 @@ helpers do private def delete_model(model, subjectid=nil) - task = OpenTox::Task.create("Deleting model: #{model.uri}",url_for("/delete",:full)) do |task| + task = OpenTox::Task.create("Deleting model: #{model.web_uri}", url_for("/delete",:full)) do |task| begin OpenTox::RestClientWrapper.put(File.join(model.task_uri, "Cancelled"), "Cancelled",{:subjectid => subjectid}) if model.task_uri rescue LOGGER.warn "Cannot cancel task #{model.task_uri}" end task.progress(15) delete_dependent(model.uri, subjectid) if model.uri @@ -49,15 +49,25 @@ helpers do if model.feature_dataset delete_dependent(model.feature_dataset, subjectid) if model.feature_dataset.match(CONFIG[:services]["opentox-dataset"]) end + task.progress(95) + model.delete + unless ToxCreateModel.get(model.id) + begin + aa = OpenTox::Authorization.delete_policies_from_uri(model.web_uri, @subjectid) + LOGGER.debug "Policy deleted for ToxCreateModel URI: #{model.web_uri} with result: #{aa}" + rescue + LOGGER.warn "Policy delete error for ToxCreateModel URI: #{model.web_uri}" + end + end task.progress(100) - "" + url_for("/models",:full) end end def delete_dependent(uri, subjectid=nil) begin - RestClient.delete(uri, :subjectid => subjectid) if subjectid - RestClient.delete(uri) if !subjectid + OpenTox::RestClientWrapper.delete(uri, :subjectid => subjectid) if subjectid + OpenTox::RestClientWrapper.delete(uri) if !subjectid rescue LOGGER.warn "Can not delete uri: #{uri}" end @@ -451,18 +461,10 @@ delete '/model/:id/?' do model = ToxCreateModel.get(params[:id]) raise OpenTox::NotFoundError.new("Model with id: #{params[:id]} not found!") unless model begin - delete_model(model, @subjectid) - model.delete - unless ToxCreateModel.get(params[:id]) - begin - aa = OpenTox::Authorization.delete_policies_from_uri(model.web_uri, @subjectid) - LOGGER.debug "Policy deleted for Dataset URI: #{uri} with result: #{aa}" - rescue - LOGGER.warn "Policy delete error for Dataset URI: #{uri}" - end - end + delete_model(model, @subjectid) flash[:notice] = "#{model.name} model deleted." rescue + LOGGER.error "#{model.name} model delete error." flash[:notice] = "#{model.name} model delete error." end redirect url_for('/models') -- cgit v1.2.3 From b41552185b21f706e7f507020925f3253c38321d Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 22 Aug 2011 11:25:06 +0200 Subject: unify cookies --- application.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index a60e597..ac19da5 100644 --- a/application.rb +++ b/application.rb @@ -9,8 +9,9 @@ require 'ftools' require File.join(File.dirname(__FILE__),'model.rb') require File.join(File.dirname(__FILE__),'helper.rb') -use Rack::Session::Cookie, :expire_after => 28800, - :secret => "ui6vaiNi-change_me" +#moved to wrapper->environment +#use Rack::Session::Cookie, :expire_after => 28800, +# :secret => "ui6vaiNi-change_me" use Rack::Flash set :lock, true -- cgit v1.2.3 From a4b6e68acf76949a1765177b6d5b8c454990cb8a Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 22 Aug 2011 12:20:12 +0200 Subject: replace weighted_auc with average_auc [2] --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index d2ee131..eb86916 100644 --- a/application.rb +++ b/application.rb @@ -320,7 +320,7 @@ post '/models' do # create a new model if validation.metadata[OT.classificationStatistics] @model.update(:correct_predictions => validation.metadata[OT.classificationStatistics][OT.percentCorrect].to_f) @model.update(:confusion_matrix => validation.confusion_matrix.to_yaml) - @model.update(:weighted_area_under_roc => validation.metadata[OT.classificationStatistics][OT.weightedAreaUnderRoc].to_f) + @model.update(:average_area_under_roc => validation.metadata[OT.classificationStatistics][OT.averageAreaUnderRoc].to_f) validation.metadata[OT.classificationStatistics][OT.classValueStatistics].each do |m| if m[OT.classValue] =~ TRUE_REGEXP #HACK: estimate true feature value correctly -- cgit v1.2.3 From c71f69b610b270b9c25cf58e84a035078905fa46 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 22 Aug 2011 15:28:27 +0200 Subject: remove subjectidstring for unified cookies --- application.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index eb86916..9ef50f8 100644 --- a/application.rb +++ b/application.rb @@ -92,8 +92,7 @@ end get '/models/?' do @models = ToxCreateModel.all.sort(:order => "DESC") @models.each{|m| raise "internal redis error: model is nil" unless m} - subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" - haml :models, :locals=>{:models=>@models, :subjectstring => subjectstring} + haml :models, :locals=>{:models=>@models} end get '/model/:id/status/?' do @@ -156,13 +155,12 @@ end get '/model/:id/:view/?' do response['Content-Type'] = 'text/plain' model = ToxCreateModel.get(params[:id]) - subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" begin case params[:view] when "model" - haml :model, :locals=>{:model=>model,:subjectstring => subjectstring}, :layout => false + haml :model, :locals=>{:model=>model}, :layout => false when /validation/ - haml :validation, :locals=>{:model=>model,:subjectstring => subjectstring}, :layout => false + haml :validation, :locals=>{:model=>model}, :layout => false else return "unable to render model: id #{params[:id]}, view #{params[:view]}" end -- cgit v1.2.3 From c242bfc291a7dab733c424968509709813e6e331 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 30 Aug 2011 17:07:56 +0200 Subject: add model sorting --- application.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 9ef50f8..c03915c 100644 --- a/application.rb +++ b/application.rb @@ -90,7 +90,20 @@ get '/login' do end get '/models/?' do - @models = ToxCreateModel.all.sort(:order => "DESC") + @page = params[:page] ? params[:page].to_i : 0 + order = params["order"] == "ASC" ? "ASC" : "DESC" + params["order"] = order + sort_by = params["sort_by"] + if sort_by + case sort_by + when "name", "created_at", "type", "id" + @models = ToxCreateModel.all.sort_by(sort_by.to_sym, :order => "#{order} ALPHA") + end + else + params["sort_by"] = "id" + end + + @models = ToxCreateModel.all.sort(:order => "DESC") unless @models @models.each{|m| raise "internal redis error: model is nil" unless m} haml :models, :locals=>{:models=>@models} end -- cgit v1.2.3 From aeb03ab4a64353d51830d14dbd82f5d19c7254c6 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 31 Aug 2011 11:22:21 +0200 Subject: sorting for id --- application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index c03915c..13bc02d 100644 --- a/application.rb +++ b/application.rb @@ -96,8 +96,10 @@ get '/models/?' do sort_by = params["sort_by"] if sort_by case sort_by - when "name", "created_at", "type", "id" + when "name", "created_at", "type" @models = ToxCreateModel.all.sort_by(sort_by.to_sym, :order => "#{order} ALPHA") + when "id" + @models = ToxCreateModel.all.sort(:order => "#{order}") end else params["sort_by"] = "id" -- cgit v1.2.3 From c6e75e0028c8e3d45a236b8d79f3c0d15092da61 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 31 Aug 2011 12:47:42 +0200 Subject: optimize models navigation | put authorized to view model to application.rb --- application.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 13bc02d..12784f0 100644 --- a/application.rb +++ b/application.rb @@ -107,6 +107,7 @@ get '/models/?' do @models = ToxCreateModel.all.sort(:order => "DESC") unless @models @models.each{|m| raise "internal redis error: model is nil" unless m} + @models.delete_if{|m| !is_authorized(m.web_uri, "GET")} haml :models, :locals=>{:models=>@models} end -- cgit v1.2.3 From e967ffe75370d39d0928e440a9023e2da6e35ae3 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 21 Sep 2011 11:16:28 +0200 Subject: remove id from sort tab --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index 12784f0..2b320e0 100644 --- a/application.rb +++ b/application.rb @@ -102,7 +102,7 @@ get '/models/?' do @models = ToxCreateModel.all.sort(:order => "#{order}") end else - params["sort_by"] = "id" + params["sort_by"] = "created_at" end @models = ToxCreateModel.all.sort(:order => "DESC") unless @models -- cgit v1.2.3