summaryrefslogtreecommitdiff
path: root/test/model.rb
blob: 027c9df6a9c3a2bf7ccbeca7a8f19fc3a54650b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require_relative "setup.rb"

begin
  puts "Service URI is: #{$model[:uri]}"
rescue
  puts "Configuration Error: $model[:uri] is not defined in: " + File.join(ENV["HOME"],".opentox","config","test.rb")
  exit
end

class ModelTest < MiniTest::Test

  def test_01_create_and_set_parameters
    a = OpenTox::Model::Generic.new 
    a.title = "test model"
    a.parameters = [
      {RDF::DC.title => "test", RDF::OT.paramScope => "mandatory"},
      {RDF::DC.title => "test2", RDF::OT.paramScope => "optional"}
    ]
    assert_equal 2, a.parameters.size
    p = a.parameters.collect{|p| p if p[RDF::DC.title] == "test"}.compact.first
    assert_equal "mandatory", p[RDF::OT.paramScope] 
    a[RDF::OT.featureCalculationAlgorithm] = "http://webservices.in-silico.ch/algorithm/substucture/match_hits"
    a[RDF::OT.predictionAlgorithm] = "http://webservices.in-silico.ch/algorithm/regression/local_svm"
    a[RDF::OT.similarityAlgorithm] = "http://webservices.in-silico.ch/algorithm/similarity/tanimoto"
    a[RDF::OT.trainingDataset] = "http://webservices.in-silico.ch/dataset/4944"
    a[RDF::OT.dependentVariables] = "http://webservices.in-silico.ch/feature/LC50_mmol"
    a[RDF::OT.featureDataset] = "http://webservices.in-silico.ch/dataset/4964"
    a.put
    a = OpenTox::Model::Generic.new a.uri
    assert_equal "test model", a.title
    assert_equal 2, a.parameters.size
    p = a.parameters.collect{|p| p if p[RDF::DC.title] == "test"}.compact.first
    assert_equal "mandatory", p[RDF::OT.paramScope].to_s
    #a.run :compound_uri => OpenTox::Compound.from_smiles("c1ccccc1NN").uri
    a.delete
  end
  
  def test_02_create_and_edit_metadata
    a = OpenTox::Model::Generic.new 
    a.title = "test model"
    a.parameters = [
      {RDF::DC.title => "test", RDF::OT.paramScope => "mandatory"},
      {RDF::DC.title => "test2", RDF::OT.paramScope => "optional"}
    ]
    assert_equal 2, a.parameters.size
    p = a.parameters.collect{|p| p if p[RDF::DC.title] == "test"}.compact.first
    assert_equal "mandatory", p[RDF::OT.paramScope] 
    a[RDF::OT.featureCalculationAlgorithm] = "http://webservices.in-silico.ch/algorithm/substucture/match_hits"
    a[RDF::OT.predictionAlgorithm] = "http://webservices.in-silico.ch/algorithm/regression/local_svm"
    a[RDF::OT.similarityAlgorithm] = "http://webservices.in-silico.ch/algorithm/similarity/tanimoto"
    a[RDF::OT.trainingDataset] = "http://webservices.in-silico.ch/dataset/4944"
    a[RDF::OT.dependentVariables] = "http://webservices.in-silico.ch/feature/LC50_mmol"
    a[RDF::OT.featureDataset] = "http://webservices.in-silico.ch/dataset/4964"
    a.put
    a = OpenTox::Model::Generic.new a.uri
    assert_equal "test model", a.title
    assert_equal 2, a.parameters.size
    p = a.parameters.collect{|p| p if p[RDF::DC.title] == "test"}.compact.first
    assert_equal "mandatory", p[RDF::OT.paramScope].to_s
    #a.run :compound_uri => OpenTox::Compound.from_smiles("c1ccccc1NN").uri
    
    b = OpenTox::Model::Generic.new a.uri
    b.metadata
    b.parameters
    b.metadata[RDF.type] << "http://www.opentox.org/echaEndpoints.owl#Endpoint"
    b.put
    c = OpenTox::Model::Generic.new b.uri
    c.metadata
    assert c.type.to_s =~ /Endpoint/
    puts c.uri
    # necessary since model.all method is abolished
    urilist = `curl -k GET -H accept:text/plain -H 'subjectid:#{OpenTox::RestClientWrapper.subjectid}' #{$model[:uri]}`.chomp
    assert_match c.uri, urilist
    a.delete
    urilist = `curl -k GET -H accept:text/plain  -H 'subjectid:#{OpenTox::RestClientWrapper.subjectid}' #{$model[:uri]}`.chomp
    refute_match c.uri, urilist 
  end
end