summaryrefslogtreecommitdiff
path: root/example.rb
diff options
context:
space:
mode:
Diffstat (limited to 'example.rb')
-rwxr-xr-x[-rw-r--r--]example.rb156
1 files changed, 96 insertions, 60 deletions
diff --git a/example.rb b/example.rb
index ceb1329..07151a8 100644..100755
--- a/example.rb
+++ b/example.rb
@@ -5,15 +5,16 @@ class Example
@@file=File.new("data/hamster_carcinogenicity.yaml","r")
@@file_type="text/x-yaml"
- @@model=File.join @@config[:services]["opentox-model"],"1"
- @@feature= URI.encode("http://localhost/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)")
- @@predicted_feature= URI.encode("http://localhost/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)_lazar_classification")
- @@alg = File.join @@config[:services]["opentox-algorithm"],"lazar"
- @@alg_params = "feature_generation_uri="+File.join(@@config[:services]["opentox-algorithm"],"fminer")
- @@data=File.join @@config[:services]["opentox-dataset"],"1"
- @@train_data=File.join @@config[:services]["opentox-dataset"],"2"
- @@test_data=File.join @@config[:services]["opentox-dataset"],"3"
- @@prediction_data=File.join @@config[:services]["opentox-dataset"],"5"
+ @@model=File.join CONFIG[:services]["opentox-model"],"1"
+ #@@feature= URI.encode("http://local-ot/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)")
+ @@feature= File.join CONFIG[:services]["opentox-dataset"],"1/feature/hamster_carcinogenicity"
+ #@@predicted_feature= URI.encode("http://local-ot/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)_lazar_classification")
+ @@alg = File.join CONFIG[:services]["opentox-algorithm"],"lazar"
+ @@alg_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @@data=File.join CONFIG[:services]["opentox-dataset"],"1"
+ @@train_data=File.join CONFIG[:services]["opentox-dataset"],"2"
+ @@test_data=File.join CONFIG[:services]["opentox-dataset"],"3"
+ @@prediction_data=File.join CONFIG[:services]["opentox-dataset"],"5"
@@css_file="http://apps.ideaconsult.net:8080/ToxPredict/style/global.css"
@@summary=""
@@ -28,7 +29,7 @@ class Example
end
file.close
- sub = { "validation_service" => @@config[:services]["opentox-validation"].chomp("/"),
+ sub = { "validation_service" => CONFIG[:services]["opentox-validation"].chomp("/"),
"validation_id" => "1",
"model_uri" => @@model,
"dataset_uri" => @@data,
@@ -39,10 +40,11 @@ class Example
"algorithm_params" => @@alg_params,
"crossvalidation_id" => "1",
"validation_report_id" => "1",
- "crossvalidation_report_id" => "1",
+ "crossvalidation_report_id" => "2",
"css_file" => @@css_file,
"prediction_dataset_uri" => @@prediction_data,
- "predicted_feature" => @@predicted_feature }
+ #"predicted_feature" => @@predicted_feature,
+ "qmrf_id" => "1"}
sub.each do |k,v|
res.gsub!(/<#{k}>/,v)
@@ -53,55 +55,88 @@ class Example
# creates the resources that are requested by the examples
def self.prepare_example_resources
- @@summary = ""
- #delete validations
- log "delete validations"
- ActiveRecord::Base.logger = Logger.new("/dev/null")
- ActiveRecord::Migrator.migrate('db/migrate', 0 )
- ActiveRecord::Migrator.migrate('db/migrate', 1 )
- ActiveRecord::Migrator.migrate('db/migrate', 2 )
+ #TODO
+ subjectid = nil
- #delete_all(@@config[:services]["opentox-dataset"])
- log OpenTox::RestClientWrapper.delete @@config[:services]["opentox-dataset"]
-
- log "upload dataset"
- halt 400,"File not found: "+@@file.path.to_s unless File.exist?(@@file.path)
- data = File.read(@@file.path)
- data_uri = OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => @@file_type},data).chomp("\n")
-
- log "train-test-validation"
- #delete_all(@@config[:services]["opentox-model"])
- OpenTox::RestClientWrapper.delete @@config[:services]["opentox-model"]
-
- split_params = Validation::Util.train_test_dataset_split(data_uri, URI.decode(@@feature), 0.9, 1)
- v = Validation::Validation.new :training_dataset_uri => split_params[:training_dataset_uri],
- :test_dataset_uri => split_params[:test_dataset_uri],
- :test_target_dataset_uri => data_uri,
- :prediction_feature => URI.decode(@@feature),
- :algorithm_uri => @@alg
- v.validate_algorithm( @@alg_params )
-
- log "crossvalidation"
- cv = Validation::Crossvalidation.new({ :dataset_uri => data_uri, :algorithm_uri => @@alg, :num_folds => 5, :stratified => false })
- cv.create_cv_datasets( URI.decode(@@feature) )
- cv.perform_cv( @@alg_params )
-
- log "create validation report"
- rep = Reports::ReportService.new(File.join(@@config[:services]["opentox-validation"],"report"))
- rep.delete_all_reports("validation")
- rep.create_report("validation",v.validation_uri)
-
- log "create crossvalidation report"
- rep.delete_all_reports("crossvalidation")
- rep.create_report("crossvalidation",cv.crossvalidation_uri)
-
- log "done"
- @@summary
+ task = OpenTox::Task.create("prepare examples", "n/a") do |task|
+ @@summary = ""
+ #delete validations
+ log "delete validations"
+ Lib::Validation.auto_migrate!
+ Lib::Crossvalidation.auto_migrate!
+ #ActiveRecord::Base.logger = Logger.new("/dev/null")
+ #ActiveRecord::Migrator.migrate('db/migrate', 0 )
+ #ActiveRecord::Migrator.migrate('db/migrate', 1 )
+ #ActiveRecord::Migrator.migrate('db/migrate', 2 )
+
+ #delete all qmrf reports
+ ReachReports::QmrfReport.auto_migrate!
+
+ #delete_all(CONFIG[:services]["opentox-dataset"])
+ log OpenTox::RestClientWrapper.delete CONFIG[:services]["opentox-dataset"]
+ task.progress(10)
+
+ log "upload dataset"
+ halt 400,"File not found: "+@@file.path.to_s unless File.exist?(@@file.path)
+ #data = File.read(@@file.path)
+ #data_uri = OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:content_type => @@file_type},data).chomp("\n")
+ data = File.read(@@file.path)
+ dataset = OpenTox::Dataset.create
+ dataset.load_yaml(data)
+ dataset.save
+ data_uri = dataset.uri
+ log "-> "+data_uri
+ task.progress(20)
+
+ log "train-test-validation"
+ #delete_all(CONFIG[:services]["opentox-model"])
+ OpenTox::RestClientWrapper.delete CONFIG[:services]["opentox-model"]
+
+ split_params = Validation::Util.train_test_dataset_split(data_uri, URI.decode(@@feature), 0.9, 1)
+ v = Validation::Validation.new :training_dataset_uri => split_params[:training_dataset_uri],
+ :validation_type => "test_set_validation",
+ :test_dataset_uri => split_params[:test_dataset_uri],
+ :test_target_dataset_uri => data_uri,
+ :prediction_feature => URI.decode(@@feature),
+ :algorithm_uri => @@alg
+ v.validate_algorithm( @@alg_params, OpenTox::SubTask.new(task, 20, 40) )
+
+ log "crossvalidation"
+ cv = Validation::Crossvalidation.new({ :dataset_uri => data_uri, :algorithm_uri => @@alg, :num_folds => 5, :stratified => false })
+ cv.perform_cv( URI.decode(@@feature), @@alg_params, OpenTox::SubTask.new(task, 40, 70) )
+
+ log "create validation report"
+ rep = Reports::ReportService.instance(File.join(CONFIG[:services]["opentox-validation"],"report"))
+ rep.delete_all_reports("validation", subjectid)
+ rep.create_report("validation",v.validation_uri)
+ task.progress(80)
+
+ log "create crossvalidation report"
+ rep.delete_all_reports("crossvalidation", subjectid)
+ rep.create_report("crossvalidation",cv.crossvalidation_uri)
+ task.progress(90)
+
+ log "build qmrf"
+ t = ReachReports.create_report("QMRF",{:model_uri=>@@model})
+ Lib::TestUtil.wait_for_task(t)
+ task.progress(100)
+
+ log "done"
+ @@summary
+ end
+ return_task(task)
end
# performs all curl calls listed in examples after ">>>", next line is added if line ends with "\"
- def self.test_examples
- lines = transform_example.split("\n")
+ def self.test_examples(example_uri=nil)
+
+ if (example_uri)
+ examples = OpenTox::RestClientWrapper.get(example_uri)
+ else
+ examples = transform_example # use local examples
+ end
+
+ lines = examples.split("\n")
curl_call = false
curl_calls = []
@@ -136,12 +171,13 @@ class Example
result = ""
IO.popen(cmd.to_s+" 2> /dev/null") do |f|
while line = f.gets
- result += line
+ result += line if result.size<50
end
end
+ result.chomp!
result.gsub!(/\n/, " \\n ")
if ($?==0)
- if OpenTox::Utils.task_uri?(result)
+ if result.task_uri?
log "wait for task: "+result
result = Lib::TestUtil.wait_for_task(result)
end
@@ -151,7 +187,7 @@ class Example
log "failed ( " +result.to_s[0,50]+" )"
end
end
- log num.to_s+"/"+num.to_s+" curls succeeded"
+ log suc.to_s+"/"+num.to_s+" curls succeeded"
@@summary
end
"testing in background, check log for results"