summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-06-16 23:52:31 +0200
committermguetlein <martin.guetlein@gmail.com>2011-06-16 23:52:31 +0200
commit654ff16ab0c63c9125785e9fe6546973cfe462a7 (patch)
tree0e13ec00ea7f10ea1328693fbc175d1f94299cc0
parentb542cfbd54901ad86d60fed03c8a05f9151f7616 (diff)
add post forms
-rwxr-xr-xreach_reports/reach_application.rb10
-rwxr-xr-xreport/report_application.rb12
-rwxr-xr-xvalidation/validation_application.rb127
3 files changed, 91 insertions, 58 deletions
diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb
index d914452..aa64ea2 100755
--- a/reach_reports/reach_application.rb
+++ b/reach_reports/reach_application.rb
@@ -54,18 +54,19 @@ get '/reach_report/:type' do
"All REACH reporting types: "+url_for("/reach_report",:full)
description =
"A list of "+type+" reports."
- post_params = ""
+ post_command = nil
case type
when /(?i)QMRF/
related_links += "\n"+
"OpenTox version of QMRF editor: "+QMRF_EDITOR_URI
description += "\n"+
"To create a QMRF report use the POST method."
- post_params = [[[:model_uri]],[["Existing QMRF report, content-type application/qmrf-xml"]]]
+ post_command = OpenTox::PostCommand.new request.url,"Create QMRF report"
+ post_command.attributes << OpenTox::PostAttribute.new("model_uri")
when /(?i)QPRF/
#TODO
end
- OpenTox.text_to_html ReachReports.list_reports(type),@subjectid,related_links,description,post_params
+ OpenTox.text_to_html ReachReports.list_reports(type),@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
ReachReports.list_reports(type)
@@ -78,6 +79,9 @@ post '/reach_report/:type' do
content_type "text/uri-list"
LOGGER.info "creating "+type+" report "+params.inspect
+ raise OpenTox::BadRequestError.new "model_uri missing" if type=~/(?i)QMRF/ and
+ params[:model_uri]!=nil and params[:model_uri].to_s.size==0
+
#puts "creating "+type+" report "+params.inspect
result_uri = ReachReports.create_report(type,params,@subjectid,request.env["rack.input"])
diff --git a/report/report_application.rb b/report/report_application.rb
index 3c8670a..f7780c3 100755
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -61,8 +61,17 @@ get '/report/:report_type' do
description =
"A list of all "+params[:report_type]+" reports. To create a report, use the POST method."
post_params = [[:validation_uris]]
+
+ post_command = OpenTox::PostCommand.new request.url,"Create validation report"
+ val_uri_description = params[:report_type]=="algorithm_comparison" ? "Separate multiple uris with ','" : nil
+ # trick for easy report creation
+ # if searching for a report, ?validation="uri" or ?crossvalidaiton="uri" is given as search param
+ # use this (search param has equal name as report type) as default value for validation_uri
+ post_command.attributes << OpenTox::PostAttribute.new("validation_uris",true,params[params[:report_type]],val_uri_description)
+ post_command.attributes << OpenTox::PostAttribute.new("identifier",true,nil,"Specifiy one identifier for each uri, separated with ','") if
+ params[:report_type]=="algorithm_comparison"
content_type "text/html"
- OpenTox.text_to_html rs.get_all_reports(params[:report_type], params),@subjectid,related_links,description,post_params
+ OpenTox.text_to_html rs.get_all_reports(params[:report_type], params),@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
rs.get_all_reports(params[:report_type], params)
@@ -116,6 +125,7 @@ delete '/report/:type/:id' do
end
post '/report/:type' do
+ raise OpenTox::BadRequestError.new "validation_uris missing" unless params[:validation_uris].to_s.size>0
task = OpenTox::Task.create("Create report",url_for("/report/"+params[:type], :full)) do |task| #,params
perform do |rs|
rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split(/\n|,/):nil,
diff --git a/validation/validation_application.rb b/validation/validation_application.rb
index 5ae6bda..bd55d4c 100755
--- a/validation/validation_application.rb
+++ b/validation/validation_application.rb
@@ -17,9 +17,16 @@ get '/crossvalidation/?' do
description =
"A list of all crossvalidations.\n"+
"Use the POST method to perform a crossvalidation."
- post_params = [[:dataset_uri,:algorithm_uri,:prediction_feature,[:num_folds,10],[:random_seed,1],[:stratified,false],[:algorithm_params,""]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform crossvalidation"
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
+ post_command.attributes << OpenTox::PostAttribute.new("num_folds",false,"10")
+ post_command.attributes << OpenTox::PostAttribute.new("random_seed",false,"1","An equal random seed value ensures the excact same random dataset split.")
+ post_command.attributes << OpenTox::PostAttribute.new("stratified",false,"false","Stratification ensures an equal class-value spread in folds.")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list
@@ -27,14 +34,14 @@ get '/crossvalidation/?' do
end
post '/crossvalidation/?' do
- task = OpenTox::Task.create( "Perform crossvalidation", url_for("/crossvalidation", :full) ) do |task| #, params
- LOGGER.info "creating crossvalidation "+params.inspect
- raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri]
- raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri]
- raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature]
- raise OpenTox::BadRequestError.new "illegal param-value num_folds: '"+params[:num_folds].to_s+"', must be integer >1" unless params[:num_folds]==nil or
- params[:num_folds].to_i>1
+ LOGGER.info "creating crossvalidation "+params.inspect
+ raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
+ raise OpenTox::BadRequestError.new "illegal param-value num_folds: '"+params[:num_folds].to_s+"', must be integer >1" unless params[:num_folds]==nil or
+ params[:num_folds].to_i>1
+ task = OpenTox::Task.create( "Perform crossvalidation", url_for("/crossvalidation", :full) ) do |task| #, params
cv_params = { :dataset_uri => params[:dataset_uri],
:algorithm_uri => params[:algorithm_uri],
:loo => "false" }
@@ -71,14 +78,13 @@ post '/crossvalidation/cleanup/?' do
end
post '/crossvalidation/loo/?' do
+ LOGGER.info "creating loo-crossvalidation "+params.inspect
+ raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
+ raise OpenTox::BadRequestError.new "illegal param: num_folds, stratified, random_seed not allowed for loo-crossvalidation" if params[:num_folds] or
+ params[:stratifed] or params[:random_seed]
task = OpenTox::Task.create( "Perform loo-crossvalidation", url_for("/crossvalidation/loo", :full) ) do |task| #, params
- LOGGER.info "creating loo-crossvalidation "+params.inspect
- raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri]
- raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri]
- raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature]
- raise OpenTox::BadRequestError.new "illegal param: num_folds, stratified, random_seed not allowed for loo-crossvalidation" if params[:num_folds] or
- params[:stratifed] or params[:random_seed]
-
cv_params = { :dataset_uri => params[:dataset_uri],
:algorithm_uri => params[:algorithm_uri],
:loo => "true" }
@@ -104,9 +110,13 @@ get '/crossvalidation/loo/?' do
description =
"A list of all leave one out crossvalidations.\n"+
"Use the POST method to perform a crossvalidation."
- post_params = [[:dataset_uri,:algorithm_uri,:prediction_feature,[:algorithm_params,""]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform leave-one-out-crossvalidation"
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list
@@ -256,7 +266,8 @@ end
post '/test_set_validation' do
LOGGER.info "creating test-set-validation "+params.inspect
- if params[:model_uri] and params[:test_dataset_uri] and !params[:training_dataset_uri] and !params[:algorithm_uri]
+ if params[:model_uri].to_s.size>0 and params[:test_dataset_uri].to_s.size>0 and
+ params[:training_dataset_uri].to_s.size==0 and params[:algorithm_uri].to_s.size==0
task = OpenTox::Task.create( "Perform test-set-validation", url_for("/", :full) ) do |task| #, params
v = Validation::Validation.create :validation_type => "test_set_validation",
:model_uri => params[:model_uri],
@@ -290,9 +301,13 @@ get '/test_set_validation' do
description =
"A list of all test-set-validations.\n"+
"To perform a test-set-validation use the POST method."
- post_params = [[:model_uri, :test_dataset_uri, [:test_target_dataset_uri,"same-as-test_dataset_uri"], [:prediction_feature, "dependent-variable-of-model"]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform test-set-validation"
+ post_command.attributes << OpenTox::PostAttribute.new("model_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("test_dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("test_target_dataset_uri",false,nil,"Specify if target endpoint values are not available in test dataset.")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature",false,nil,"Default is 'dependentVariables' of the model.")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list
@@ -301,7 +316,8 @@ end
post '/training_test_validation/?' do
LOGGER.info "creating training-test-validation "+params.inspect
- if params[:algorithm_uri] and params[:training_dataset_uri] and params[:test_dataset_uri] and params[:prediction_feature] and !params[:model_uri]
+ if params[:algorithm_uri].to_s.size>0 and params[:training_dataset_uri].to_s.size>0 and
+ params[:test_dataset_uri].to_s.size>0 and params[:prediction_feature].to_s.size>0 and params[:model_uri].to_s.size==0
task = OpenTox::Task.create( "Perform training-test-validation", url_for("/", :full) ) do |task| #, params
v = Validation::Validation.create :validation_type => "training_test_validation",
:algorithm_uri => params[:algorithm_uri],
@@ -335,14 +351,15 @@ get '/training_test_validation' do
description =
"A list of all training-test-validations.\n"+
"To perform a training-test-validation use the POST method."
- post_params = [[:algorithm_uri,
- :training_dataset_uri,
- :test_dataset_uri,
- [:test_target_dataset_uri,"same-as-test_dataset_uri"],
- :prediction_feature,
- [:algorithm_params, ""]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform training-test-validation"
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("training_dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("test_dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("test_target_dataset_uri",false,nil,"Specify if target endpoint values are not available in test dataset.")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list
@@ -350,19 +367,21 @@ get '/training_test_validation' do
end
post '/bootstrapping' do
+ LOGGER.info "performing bootstrapping validation "+params.inspect
+ raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
task = OpenTox::Task.create( "Perform bootstrapping validation", url_for("/bootstrapping", :full) ) do |task| #, params
- LOGGER.info "performing bootstrapping validation "+params.inspect
- raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri]
- raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri]
- raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature]
-
params.merge!( Validation::Util.bootstrapping( params[:dataset_uri],
params[:prediction_feature], @subjectid,
params[:random_seed], OpenTox::SubTask.create(task,0,33)) )
+ LOGGER.info "params after bootstrapping: "+params.inspect
v = Validation::Validation.create :validation_type => "bootstrapping",
:test_target_dataset_uri => params[:dataset_uri],
:prediction_feature => params[:prediction_feature],
- :algorithm_uri => params[:algorithm_uri]
+ :algorithm_uri => params[:algorithm_uri],
+ :training_dataset_uri => params[:training_dataset_uri],
+ :test_dataset_uri => params[:test_dataset_uri]
v.subjectid = @subjectid
v.validate_algorithm( params[:algorithm_params], OpenTox::SubTask.create(task,33,100))
v.validation_uri
@@ -385,13 +404,14 @@ get '/bootstrapping' do
description =
"A list of all bootstrapping-validations.\n"+
"To perform a bootstrapping-validation use the POST method."
- post_params = [[:algorithm_uri,
- :dataset_uri,
- :prediction_feature,
- [:algorithm_params, ""],
- [:random_seed, 1]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform bootstrapping-validation"
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
+ post_command.attributes << OpenTox::PostAttribute.new("random_seed",false,"1","An equal random seed value ensures the excact same random dataset split.")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list
@@ -399,13 +419,11 @@ get '/bootstrapping' do
end
post '/training_test_split' do
-
+ LOGGER.info "creating training test split "+params.inspect
+ raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri].to_s.size>0
+ raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
task = OpenTox::Task.create( "Perform training test split validation", url_for("/training_test_split", :full) ) do |task| #, params
- LOGGER.info "creating training test split "+params.inspect
- raise OpenTox::BadRequestError.new "dataset_uri missing" unless params[:dataset_uri]
- raise OpenTox::BadRequestError.new "algorithm_uri missing" unless params[:algorithm_uri]
- raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature]
-
params.merge!( Validation::Util.train_test_dataset_split(params[:dataset_uri], params[:prediction_feature],
@subjectid, params[:split_ratio], params[:random_seed], OpenTox::SubTask.create(task,0,33)))
v = Validation::Validation.create :validation_type => "training_test_split",
@@ -437,14 +455,15 @@ get '/training_test_split' do
description =
"A list of all training-test-split-validations.\n"+
"To perform a training-test-split-validation use the POST method."
- post_params = [[:algorithm_uri,
- :dataset_uri,
- :prediction_feature,
- [:algorithm_params, ""],
- [:random_seed, 1],
- [:split_ratio, 0.66]]]
+ post_command = OpenTox::PostCommand.new request.url,"Perform training-test-split-validation"
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("dataset_uri")
+ post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
+ post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
+ post_command.attributes << OpenTox::PostAttribute.new("random_seed",false,"1","An equal random seed value ensures the excact same random dataset split.")
+ post_command.attributes << OpenTox::PostAttribute.new("split_ratio",false,"0.66","A split ratio of 0.66 implies that two thirds of the compounds are used for training.")
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_params
+ OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
else
content_type "text/uri-list"
uri_list