summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-03-26 11:00:33 +0100
committerChristoph Helma <helma@in-silico.ch>2013-03-26 11:00:33 +0100
commit4c23e95dab563d74b4e86404608cc356a9b20875 (patch)
tree0fffdab89f6d89ca84c6f5c50d0f76f512efbc4b
parent3fd8236e4ce9cbf3232d05661f33def68895b3e0 (diff)
initial adjustments for refactored version
-rw-r--r--lib/format_util.rb4
-rw-r--r--lib/prediction_data.rb2
-rwxr-xr-xreport/report_application.rb4
-rwxr-xr-xreport/validation_access.rb13
-rwxr-xr-xvalidation/validation_application.rb24
-rwxr-xr-xvalidation/validation_service.rb43
6 files changed, 46 insertions, 44 deletions
diff --git a/lib/format_util.rb b/lib/format_util.rb
index d7b737e..61c8ab4 100644
--- a/lib/format_util.rb
+++ b/lib/format_util.rb
@@ -24,11 +24,11 @@ class String
def to_owl_uri
if DC_KEYS.include?(self)
- DC[self].to_s
+ RDF::DC[self].to_s
elsif RDF_KEYS.include?(self)
RDF[self].to_s
else
- OT[self].to_s
+ RDF::OT[self].to_s
end
end
end
diff --git a/lib/prediction_data.rb b/lib/prediction_data.rb
index 95902a9..2f80e8e 100644
--- a/lib/prediction_data.rb
+++ b/lib/prediction_data.rb
@@ -94,7 +94,7 @@ module Lib
internal_server_error "prediction_feature not found in test_dataset\n"+
"prediction_feature: '"+prediction_feature.to_s+"'\n"+
"test_dataset: '"+test_dataset_uri.to_s+"'\n"+
- "available features are: "+test_dataset.features.inspect if test_dataset.find_feature(prediction_feature)==nil
+ "available features are: "+test_dataset.features.inspect if test_dataset.find_feature_uri(prediction_feature)==nil
$logger.debug "test dataset size: "+test_dataset.compounds.size.to_s
internal_server_error "test dataset is empty "+test_dataset_uri.to_s unless test_dataset.compounds.size>0
diff --git a/report/report_application.rb b/report/report_application.rb
index 0890d0e..1273463 100755
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -44,7 +44,7 @@ class Validation::Application < OpenTox::Service
description =
"A list of all report types."
content_type "text/html"
- OpenTox.text_to_html rs.get_report_types,@subjectid,related_links,description
+ rs.get_report_types.to_html(related_links,description)
else
content_type "text/uri-list"
rs.get_report_types
@@ -88,7 +88,7 @@ class Validation::Application < OpenTox::Service
# VAL_ATTR_TTEST_CLASS.join(",")+"', default for regression: '"+VAL_ATTR_TTEST_REGR.join(",")+"'")
# end
content_type "text/html"
- OpenTox.text_to_html rs.get_all_reports(params[:report_type], params),@subjectid,related_links,description#,post_command
+ rs.get_all_reports(params[:report_type], params).to_html related_links,description#,post_command
else
content_type "text/uri-list"
rs.get_all_reports(params[:report_type], params)
diff --git a/report/validation_access.rb b/report/validation_access.rb
index fd1fda3..fe2c401 100755
--- a/report/validation_access.rb
+++ b/report/validation_access.rb
@@ -142,7 +142,7 @@ class Reports::ValidationDB
def training_feature_dataset_uri(validation, subjectid)
m = OpenTox::Model::Generic.find(validation.model_uri, subjectid)
if m
- f = m.metadata[OT.featureDataset]
+ f = m.metadata[RDF::OT.featureDataset]
return f.chomp if f
end
internal_server_error "no feature dataset found"
@@ -153,7 +153,8 @@ class Reports::ValidationDB
test_dataset = Lib::DatasetCache.find( validation.test_dataset_uri, subjectid )
features_found = true
training_features.features.each do |f|
- unless test_dataset.find_feature(f.uri)
+ unless test_dataset.features.include?(f)
+ #unless test_dataset.find_feature_uri(f.uri)
features_found = false
$logger.debug "training-feature are not in test-datset #{f}"
break
@@ -165,12 +166,12 @@ class Reports::ValidationDB
else
m = OpenTox::Model::Generic.find(validation.model_uri, subjectid)
feat_gen = nil
- m.metadata[OT.parameters].each do |h|
- if h[DC.title] and h[DC.title]=~/feature_generation/ and h[OT.paramValue]
- feat_gen = h[OT.paramValue]
+ m.metadata[RDF::OT.parameters].each do |h|
+ if h[RDF::DC.title] and h[RDF::DC.title]=~/feature_generation/ and h[RDF::OT.paramValue]
+ feat_gen = h[RDF::OT.paramValue]
break
end
- end if m and m.metadata[OT.parameters]
+ end if m and m.metadata[RDF::OT.parameters]
internal_server_error "no feature creation alg found" unless feat_gen
feat_gen = File.join(feat_gen,"match") if feat_gen=~/fminer/
uri = OpenTox::RestClientWrapper.post(feat_gen,{:subjectid => subjectid,
diff --git a/validation/validation_application.rb b/validation/validation_application.rb
index af3f827..036b083 100755
--- a/validation/validation_application.rb
+++ b/validation/validation_application.rb
@@ -1,4 +1,3 @@
-
[ 'rubygems', 'sinatra' ].each do |lib|
require lib
end
@@ -46,7 +45,7 @@ class Validation::Application < OpenTox::Service
# 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_command
+ uri_list.to_html(related_links,description)#,post_command
else
content_type "text/uri-list"
uri_list
@@ -140,7 +139,7 @@ class Validation::Application < OpenTox::Service
# 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_command
+ uri_list.to_html related_links,description#,post_command
else
content_type "text/uri-list"
uri_list
@@ -172,7 +171,7 @@ class Validation::Application < OpenTox::Service
description =
"A crossvalidation resource."
content_type "text/html"
- OpenTox.text_to_html crossvalidation.to_rdf_yaml,@subjectid,related_links,description
+ crossvalidation.to_rdf_yaml.to_html related_links,description
when "application/serialize"
content_type "application/serialize"
crossvalidation.inspect # to load all the stuff
@@ -196,7 +195,7 @@ class Validation::Application < OpenTox::Service
description =
"The averaged statistics for the crossvalidation."
content_type "text/html"
- OpenTox.text_to_html v.to_rdf_yaml,@subjectid,related_links,description
+ v.to_rdf_yaml.to_html related_links,description
when "application/rdf+xml"
content_type "application/rdf+xml"
v.to_rdf
@@ -295,7 +294,7 @@ class Validation::Application < OpenTox::Service
"A validation web service for the OpenTox project ( http://opentox.org ).\n"+
"In the root directory (this is where you are now), a list of all validation resources is returned."
content_type "text/html"
- OpenTox.text_to_html uri_list,@subjectid,related_links,description
+ uri_list.to_html related_links,description
else
content_type "text/uri-list"
uri_list
@@ -347,7 +346,7 @@ class Validation::Application < OpenTox::Service
# post_command.attributes << OpenTox::PostAttribute.new("test_dataset_uri")
# 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_command
+ uri_list.to_html related_links,description#,post_command
else
content_type "text/uri-list"
uri_list
@@ -398,7 +397,7 @@ class Validation::Application < OpenTox::Service
# 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_command
+ uri_list.to_html related_links,description#,post_command
else
content_type "text/uri-list"
uri_list
@@ -457,7 +456,7 @@ class Validation::Application < OpenTox::Service
# 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_command
+ uri_list.to_html related_links,description#,post_command
else
content_type "text/uri-list"
uri_list
@@ -470,8 +469,7 @@ class Validation::Application < OpenTox::Service
bad_request_error "algorithm_uri missing" unless params[:algorithm_uri].to_s.size>0
bad_request_error "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
check_stratified(params)
- task = OpenTox::Task.run( "Perform training test split validation", to("/validation/training_test_split", :full) ) do |task| #, params
- #task = OpenTox::Task.create( $task[:uri], nil, RDF::DC.description => "Perform training test split validation") do |task| #, params
+ task = OpenTox::Task.run( "Perform training test split validation", uri("/validation/training_test_split"), @subjectid ) do |task| #, params
$logger.debug "performing train test split"
params.merge!( Validation::Util.train_test_dataset_split(to("/validation/training_test_split", :full), params[:dataset_uri],
(params[:stratified].to_s=~/true/ ? params[:prediction_feature] : nil), @subjectid, params[:stratified], params[:split_ratio],
@@ -515,7 +513,7 @@ class Validation::Application < OpenTox::Service
# 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_command
+ uri_list.to_html related_links,description#,post_command
else
content_type "text/uri-list"
uri_list
@@ -688,7 +686,7 @@ class Validation::Application < OpenTox::Service
"Get validation predictions: "+to("/validation/"+params[:id]+"/predictions",:full)+"\n"+
"All validations: "+to("/validation/",:full)+"\n"+
"All validation reports: "+to("/validation/report/validation",:full)
- OpenTox.text_to_html validation.to_rdf_yaml,@subjectid,related_links,description
+ validation.to_rdf_yaml.to_html related_links,description
when "application/serialize"
content_type "application/serialize"
validation.inspect # to load all the stuff
diff --git a/validation/validation_service.rb b/validation/validation_service.rb
index 3dd06c0..8609f85 100755
--- a/validation/validation_service.rb
+++ b/validation/validation_service.rb
@@ -172,12 +172,12 @@ module Validation
model.get
unless self.algorithm_uri
- self.algorithm_uri = model.metadata[OT.algorithm.to_s]
+ self.algorithm_uri = model.metadata[RDF::OT.algorithm.to_s]
end
if self.prediction_feature.to_s.size==0
- dependentVariables = model.metadata[OT.dependentVariables.to_s]
+ dependentVariables = model.metadata[RDF::OT.dependentVariables.to_s]
internal_server_error "model has no dependentVariables specified, please give prediction_feature for model validation" unless dependentVariables
- self.prediction_feature = model.metadata[OT.dependentVariables.to_s]
+ self.prediction_feature = model.metadata[RDF::OT.dependentVariables.to_s]
end
prediction_dataset_uri = ""
@@ -219,9 +219,9 @@ module Validation
model.get
feature_type = model.feature_type(self.subjectid)
- dependentVariables = model.metadata[OT.dependentVariables.to_s]
+ dependentVariables = model.metadata[RDF::OT.dependentVariables.to_s]
prediction_feature = self.prediction_feature ? nil : dependentVariables
- algorithm_uri = self.algorithm_uri ? nil : model.metadata[OT.algorithm.to_s]
+ algorithm_uri = self.algorithm_uri ? nil : model.metadata[RDF::OT.algorithm.to_s]
predicted_variable = model.predicted_variable(self.subjectid)
predicted_confidence = model.predicted_confidence(self.subjectid)
internal_server_error "cannot determine whether model '"+model.uri.to_s+"' performs classification or regression: '#{feature_type}', "+
@@ -327,9 +327,9 @@ module Validation
if (delete_feature_datasets)
begin
model = OpenTox::Model::Generic.find(v.model_uri)
- if model.metadata[OT.featureDataset.to_s]
- $logger.debug "loo-cleanup> delete feature dataset "+model.metadata[OT.featureDataset.to_s]
- OpenTox::RestClientWrapper.delete model.metadata[OT.featureDataset.to_s],subjectid
+ if model.metadata[RDF::OT.featureDataset.to_s]
+ $logger.debug "loo-cleanup> delete feature dataset "+model.metadata[RDF::OT.featureDataset.to_s]
+ OpenTox::RestClientWrapper.delete model.metadata[RDF::OT.featureDataset.to_s],subjectid
end
rescue
end
@@ -425,8 +425,11 @@ module Validation
Validation.find( :crossvalidation_id => cv.id, :validation_type => "crossvalidation" ).each do |v|
break unless
v.prediction_feature == prediction_feature and
- OpenTox::Dataset.exist?(v.training_dataset_uri,self.subjectid) and
- OpenTox::Dataset.exist?(v.test_dataset_uri,self.subjectid)
+ URI.accessible?(v.training_dataset_uri,self.subjectid) and
+ URI.accessible?(v.test_dataset_uri,self.subjectid)
+ # CH: Dataset.exist? has been removed, URI.accessible? is cheaper because it needs only HEAD requests
+ #OpenTox::Dataset.exist?(v.training_dataset_uri,self.subjectid) and
+ #OpenTox::Dataset.exist?(v.test_dataset_uri,self.subjectid)
#make sure self.id is set
#self.save if self.new?
tmp_val << { :validation_type => "crossvalidation",
@@ -457,7 +460,7 @@ module Validation
train_dataset_uris = []
test_dataset_uris = []
- meta = { DC.creator => self.crossvalidation_uri }
+ meta = { RDF::DC.creator => self.crossvalidation_uri }
case stratified
when "false"
if self.loo=="true"
@@ -485,11 +488,11 @@ module Validation
internal_server_error "internal error, num train compounds not correct, should be '"+(shuffled_compound_indices.size-test_compound_indices.size).to_s+
"', is '"+train_compound_indices.size.to_s+"'" unless shuffled_compound_indices.size - test_compound_indices.size == train_compound_indices.size
datasetname = 'dataset fold '+(n+1).to_s+' of '+self.num_folds.to_s
- meta[DC.title] = "training "+datasetname
+ meta[RDF::DC.title] = "training "+datasetname
$logger.debug "training set: "+datasetname+"_train, compounds: "+train_compound_indices.size.to_s
train_dataset_uri = orig_dataset.split( train_compound_indices, orig_dataset.features, meta, self.subjectid ).uri
train_dataset_uris << train_dataset_uri
- meta[DC.title] = "test "+datasetname
+ meta[RDF::DC.title] = "test "+datasetname
$logger.debug "test set: "+datasetname+"_test, compounds: "+test_compound_indices.size.to_s
test_dataset_uri = orig_dataset.split( test_compound_indices, orig_dataset.features, meta, self.subjectid ).uri
test_dataset_uris << test_dataset_uri
@@ -573,14 +576,14 @@ module Validation
result = {}
result[:training_dataset_uri] = orig_dataset.split( training_compound_indices, orig_dataset.features,
- { DC.title => "Bootstrapping training dataset of "+orig_dataset.title.to_s,
- DC.creator => $url_provider.to('/validation/bootstrapping',:full) },
+ { RDF::DC.title => "Bootstrapping training dataset of "+orig_dataset.title.to_s,
+ RDF::DC.creator => $url_provider.to('/validation/bootstrapping',:full) },
subjectid ).uri
task.progress(66) if task
result[:test_dataset_uri] = orig_dataset.split( test_compound_indices, orig_dataset.features,
- { DC.title => "Bootstrapping test dataset of "+orig_dataset.title.to_s,
- DC.creator => $url_provider.to('/validation/bootstrapping',:full)} ,
+ { RDF::DC.title => "Bootstrapping test dataset of "+orig_dataset.title.to_s,
+ RDF::DC.creator => $url_provider.to('/validation/bootstrapping',:full)} ,
subjectid ).uri
task.progress(100) if task
@@ -616,7 +619,7 @@ module Validation
bad_request_error "prediction feature required for stratified splits" unless prediction_feature
end
- meta = { DC.creator => creator_uri }
+ meta = { RDF::DC.creator => creator_uri }
case stratified
when /true|super/
@@ -643,7 +646,7 @@ module Validation
test_compound_indices = compound_indices[split..-1]
task.progress(33) if task
- meta[DC.title] = "Training dataset split of "+orig_dataset.uri
+ meta[RDF::DC.title] = "Training dataset split of "+orig_dataset.uri
result = {}
train_data = orig_dataset.split( training_compound_indices, orig_dataset.features, meta, subjectid )
est_num_train_compounds = (orig_dataset.compounds.size*split_ratio).round
@@ -652,7 +655,7 @@ module Validation
result[:training_dataset_uri] = train_data.uri
task.progress(66) if task
- meta[DC.title] = "Test dataset split of "+orig_dataset.uri
+ meta[RDF::DC.title] = "Test dataset split of "+orig_dataset.uri
test_data = orig_dataset.split( test_compound_indices, orig_dataset.features, meta, subjectid )
est_num_test_compounds = orig_dataset.compounds.size-est_num_train_compounds
internal_server_error "Test dataset num coumpounds != #{est_num_test_compounds}, instead: "+test_data.compounds.size.to_s unless