summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2011-01-27 18:18:39 +0100
committerChristoph Helma <helma@in-silico.ch>2011-01-27 18:18:39 +0100
commit5f0d5b9ffa13f54b52fa0a41dd2d7f2ab55978f5 (patch)
tree2293044b3b8eefa86f9fc3e223fac9627a6f1dc7
parenta59432d06412e919d6877f20420e27a72e7536e2 (diff)
parentfdea4a4f126072c6dbd0fda54e1fa5cf114577b0 (diff)
Merge remote branch 'rautenberg/master'
-rw-r--r--algorithm.rb3
-rw-r--r--authorization.rb11
-rw-r--r--dataset.rb52
-rw-r--r--feature.rb2
-rw-r--r--fminer.rb16
-rw-r--r--lazar.rb16
-rw-r--r--parser.rb4
-rw-r--r--validate-owl.rb6
8 files changed, 62 insertions, 48 deletions
diff --git a/algorithm.rb b/algorithm.rb
index 055f0a2..94f3b5c 100644
--- a/algorithm.rb
+++ b/algorithm.rb
@@ -6,6 +6,7 @@ require "./validate-owl.rb"
class AlgorithmTest < Test::Unit::TestCase
def setup
+ @@subjectid = OpenTox::Authorization.authenticate(TEST_USER,TEST_PW)
@algorithms = [
File.join(CONFIG[:services]["opentox-algorithm"],"fminer","bbrc"),
File.join(CONFIG[:services]["opentox-algorithm"],"fminer","last"),
@@ -20,7 +21,7 @@ class AlgorithmTest < Test::Unit::TestCase
def test_metadata
@algorithms.each do |algorithm|
puts algorithm
- validate_owl(algorithm)
+ validate_owl(algorithm, @@subjectid)
end
end
diff --git a/authorization.rb b/authorization.rb
index 0d3508b..3772638 100644
--- a/authorization.rb
+++ b/authorization.rb
@@ -85,7 +85,16 @@ class TestOpenToxAuthorizationLDAP < Test::Unit::TestCase
logout(tok_anonymous)
end
-
+ def test_03_check_different_uris
+ res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
+ assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
+ assert OpenTox::Authorization.authorize(TEST_URI, "GET", @@subjectid), "GET request"
+ policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
+ policies.each do |policy|
+ assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
+ end
+
+ end
end
diff --git a/dataset.rb b/dataset.rb
index 812a060..d15baf7 100644
--- a/dataset.rb
+++ b/dataset.rb
@@ -29,7 +29,7 @@ class DatasetTest < Test::Unit::TestCase
=begin
def test_save_external
- @dataset = OpenTox::Dataset.find "http://apps.ideaconsult.net:8080/ambit2/dataset/2698"
+ @dataset = OpenTox::Dataset.find "http://apps.ideaconsult.net:8080/ambit2/dataset/2698", @@subjectid
#File.open("test.rdf","w+"){|f| f.puts @dataset.to_rdfxml}
@dataset.uri = "http://apps.ideaconsult.net:8080/ambit2/dataset"
uri = @dataset.save(@@subjectid)
@@ -47,7 +47,7 @@ class DatasetTest < Test::Unit::TestCase
end
def test_all
- datasets = OpenTox::Dataset.all
+ datasets = OpenTox::Dataset.all(CONFIG[:services]["opentox-dataset"], @@subjectid)
assert_kind_of Array, datasets
end
@@ -59,36 +59,36 @@ class DatasetTest < Test::Unit::TestCase
end
def test_from_yaml
- @dataset = OpenTox::Dataset.new
+ @dataset = OpenTox::Dataset.new nil, @@subjectid
@dataset.load_yaml(File.open("data/hamster_carcinogenicity.yaml").read)
hamster_carc?
end
def test_rest_csv
uri = OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:accept => "text/uri-list"}, {:file => File.new("data/hamster_carcinogenicity.csv"), :subjectid => @@subjectid}).to_s.chomp
- @dataset = OpenTox::Dataset.new uri
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new uri, @@subjectid
+ @dataset.load_all(@@subjectid)
hamster_carc?
end
def test_multicolumn_csv
uri = OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:accept => "text/uri-list"}, {:file => File.new("data/multicolumn.csv"), :subjectid => @@subjectid}).to_s.chomp
- @dataset = OpenTox::Dataset.new uri
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new uri, @@subjectid
+ @dataset.load_all(@@subjectid)
assert_equal 5, @dataset.features.size
assert_equal 4, @dataset.compounds.size
end
def test_from_csv
- @dataset = OpenTox::Dataset.new
+ @dataset = OpenTox::Dataset.new(nil, @@subjectid)
@dataset.load_csv(File.open("data/hamster_carcinogenicity.csv").read, @@subjectid)
hamster_carc?
@dataset.delete(@@subjectid)
end
def test_from_excel
- @dataset = OpenTox::Dataset.new
+ @dataset = OpenTox::Dataset.new(nil, @@subjectid)
@dataset.load_spreadsheet(Excel.new("data/hamster_carcinogenicity.xls"), @@subjectid)
hamster_carc?
@dataset.delete(@@subjectid)
@@ -96,39 +96,39 @@ class DatasetTest < Test::Unit::TestCase
def test_load_metadata
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.find(uri)
+ @dataset = OpenTox::Dataset.find(uri, @@subjectid)
assert @dataset.metadata.size != 0
end
end
def test_load_compounds
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_compounds
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_compounds(@@subjectid)
assert_equal @dataset.compounds.size,data[:nr_compounds]
end
end
def test_load_features
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_features
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_features(@@subjectid)
assert_equal @dataset.features.keys.size,data[:nr_dataset_features]
end
end
def test_load_all
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
validate data
end
end
def test_yaml
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
#@dataset = YAML.load @dataset.to_yaml
validate data
end
@@ -136,8 +136,8 @@ class DatasetTest < Test::Unit::TestCase
def test_csv
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
csv = @dataset.to_csv.split("\n")
assert_equal csv.size, data[:nr_compounds]+1
assert_equal csv.first.split(", ").size, data[:nr_dataset_features]+1
@@ -146,8 +146,8 @@ class DatasetTest < Test::Unit::TestCase
def test_excel
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
book = @dataset.to_spreadsheet
assert_kind_of Spreadsheet::Workbook, book
#File.open("#{@dataset.id}.xls","w+"){|f| book.write f.path}
@@ -156,16 +156,16 @@ class DatasetTest < Test::Unit::TestCase
def test_ntriples
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
assert_kind_of String, @dataset.to_ntriples
end
end
def test_owl
@datasets.each do |uri,data|
- @dataset = OpenTox::Dataset.new(uri)
- @dataset.load_all
+ @dataset = OpenTox::Dataset.new(uri, @@subjectid)
+ @dataset.load_all(@@subjectid)
assert_kind_of String, @dataset.to_rdfxml
end
end
diff --git a/feature.rb b/feature.rb
index 9a9d9ab..7ed600c 100644
--- a/feature.rb
+++ b/feature.rb
@@ -25,7 +25,7 @@ class FeatureTest < Test::Unit::TestCase
def test_owl
#@features.each do |uri|
- validate_owl @features.first
+ validate_owl @features.first, @@subjectid
# Ambit does not validate
#end
end
diff --git a/fminer.rb b/fminer.rb
index a8552d7..de447bf 100644
--- a/fminer.rb
+++ b/fminer.rb
@@ -10,8 +10,8 @@ class FminerTest < Test::Unit::TestCase
def test_bbrc
feature = @@classification_training_dataset.features.keys.first
dataset_uri = OpenTox::Algorithm::Fminer::BBRC.new.run({:dataset_uri => @@classification_training_dataset.uri, :prediction_feature => feature, :subjectid => @@subjectid}).to_s
- d =OpenTox::Dataset.new dataset_uri
- d.load_features
+ d =OpenTox::Dataset.new dataset_uri, @@subjectid
+ d.load_features(@@subjectid)
assert_equal 41, d.features.size
#validate_owl
d.delete(@@subjectid)
@@ -20,8 +20,8 @@ class FminerTest < Test::Unit::TestCase
def test_last
feature = @@classification_training_dataset.features.keys.first
dataset_uri = OpenTox::Algorithm::Fminer::LAST.new.run({:dataset_uri => @@classification_training_dataset.uri, :prediction_feature => feature, :subjectid => @@subjectid}).to_s
- d =OpenTox::Dataset.new dataset_uri
- d.load_features
+ d =OpenTox::Dataset.new dataset_uri, @@subjectid
+ d.load_features(@@subjectid)
assert_equal 36, d.features.size
#validate_owl
d.delete(@@subjectid)
@@ -30,8 +30,8 @@ class FminerTest < Test::Unit::TestCase
def test_regression_bbrc
feature = File.join @@regression_training_dataset.uri,"feature/LC50_mmol"
dataset_uri = OpenTox::Algorithm::Fminer::BBRC.new.run({:dataset_uri => @@regression_training_dataset.uri, :prediction_feature => feature, :subjectid => @@subjectid}).to_s
- d =OpenTox::Dataset.new dataset_uri
- d.load_features
+ d =OpenTox::Dataset.new dataset_uri, @@subjectid
+ d.load_features(@@subjectid)
assert_equal 222, d.features.size
d.delete(@@subjectid)
end
@@ -39,8 +39,8 @@ class FminerTest < Test::Unit::TestCase
def test_regression_last
feature = File.join @@regression_training_dataset.uri,"feature/LC50_mmol"
dataset_uri = OpenTox::Algorithm::Fminer::LAST.new.run({:dataset_uri => @@regression_training_dataset.uri, :prediction_feature => feature, :subjectid => @@subjectid}).to_s
- d =OpenTox::Dataset.new dataset_uri
- d.load_features
+ d =OpenTox::Dataset.new dataset_uri, @@subjectid
+ d.load_features(@@subjectid)
assert_equal 16, d.features.size
d.delete(@@subjectid)
end
diff --git a/lazar.rb b/lazar.rb
index 0ee7a43..280f917 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -14,11 +14,11 @@ class LazarTest < Test::Unit::TestCase
=end
def test_create_regression_model
model_uri = OpenTox::Algorithm::Lazar.new.run({:dataset_uri => @@regression_training_dataset.uri, :subjectid => @@subjectid}).to_s
- lazar = OpenTox::Model::Lazar.find model_uri
+ lazar = OpenTox::Model::Lazar.find model_uri, @@subjectid
assert_equal lazar.features.size, 222
compound = OpenTox::Compound.from_smiles("c1ccccc1NN")
prediction_uri = lazar.run(:compound_uri => compound.uri, :subjectid => @@subjectid)
- prediction = OpenTox::LazarPrediction.find(prediction_uri)
+ prediction = OpenTox::LazarPrediction.find(prediction_uri, @@subjectid)
assert_equal prediction.value(compound).round_to(4), 0.149518871336721.round_to(4)
assert_equal prediction.confidence(compound).round_to(4), 0.615246530364447.round_to(4)
assert_equal prediction.neighbors(compound).size, 81
@@ -29,12 +29,12 @@ class LazarTest < Test::Unit::TestCase
def test_default_classification_model
# create model
model_uri = OpenTox::Algorithm::Lazar.new.run({:dataset_uri => @@classification_training_dataset.uri, :subjectid => @@subjectid}).to_s
- lazar = OpenTox::Model::Lazar.find model_uri
+ lazar = OpenTox::Model::Lazar.find model_uri, @@subjectid
assert_equal lazar.features.size, 41
# single prediction
compound = OpenTox::Compound.from_smiles("c1ccccc1NN")
prediction_uri = lazar.run(:compound_uri => compound.uri, :subjectid => @@subjectid)
- prediction = OpenTox::LazarPrediction.find(prediction_uri)
+ prediction = OpenTox::LazarPrediction.find(prediction_uri, @@subjectid)
assert_equal prediction.value(compound), false
assert_equal prediction.confidence(compound).round_to(4), 0.25857114104619.round_to(4)
assert_equal prediction.neighbors(compound).size, 15
@@ -42,7 +42,7 @@ class LazarTest < Test::Unit::TestCase
# dataset activity
compound = OpenTox::Compound.from_smiles("CNN")
prediction_uri = lazar.run(:compound_uri => compound.uri, :subjectid => @@subjectid)
- prediction = OpenTox::LazarPrediction.find prediction_uri
+ prediction = OpenTox::LazarPrediction.find prediction_uri, @@subjectid
assert !prediction.measured_activities(compound).empty?
puts prediction.measured_activities(compound).first.inspect
assert_equal prediction.measured_activities(compound).first, true
@@ -50,9 +50,13 @@ class LazarTest < Test::Unit::TestCase
prediction.delete(@@subjectid)
# dataset prediction
test_dataset = OpenTox::Dataset.create_from_csv_file("data/multicolumn.csv", @@subjectid)
- prediction = OpenTox::LazarPrediction.find lazar.run(:dataset_uri => test_dataset.uri, :subjectid => @@subjectid)
+ prediction = OpenTox::LazarPrediction.find lazar.run(:dataset_uri => test_dataset.uri, :subjectid => @@subjectid), @@subjectid
assert_equal prediction.compounds.size, 4
compound = OpenTox::Compound.new prediction.compounds.first
+ puts "compound"
+ puts compound.inspect
+ puts "prediction"
+ puts prediction.value(compound).inspect
assert_equal prediction.value(compound), false
prediction.delete(@@subjectid)
lazar.delete(@@subjectid)
diff --git a/parser.rb b/parser.rb
index 06f3709..7bae783 100644
--- a/parser.rb
+++ b/parser.rb
@@ -32,8 +32,8 @@ class ParserTest < Test::Unit::TestCase
def test_dataset
@datasets.each do |uri,properties|
- parser = OpenTox::Parser::Owl::Dataset.new uri
- @dataset = parser.load_uri
+ parser = OpenTox::Parser::Owl::Dataset.new uri, @@subjectid
+ @dataset = parser.load_uri(@@subjectid)
validate properties
end
end
diff --git a/validate-owl.rb b/validate-owl.rb
index 569813f..736531b 100644
--- a/validate-owl.rb
+++ b/validate-owl.rb
@@ -1,9 +1,9 @@
#require 'nokogiri'
-def validate_owl(uri)
+def validate_owl(uri, subjectid=nil)
if validator_available?
- owl = OpenTox::RestClientWrapper.get(uri,:accept => "application/rdf+xml")
- html = OpenTox::RestClientWrapper.post("http://www.mygrid.org.uk/OWL/Validator",{:rdf => owl, :level => "DL"})
+ owl = OpenTox::RestClientWrapper.get(uri,{:accept => "application/rdf+xml",:subjectid => subjectid})
+ html = OpenTox::RestClientWrapper.post("http://www.mygrid.org.uk/OWL/Validator",{:rdf => owl, :level => "DL",:subjectid => subjectid})
assert_match(/YES/,html)
else
puts "http://www.mygrid.org.uk/OWL/Validator offline"