helma-opentox-ruby-api-wrapper 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ begin
11
11
  gem.homepage = "http://github.com/helma/opentox-ruby-api-wrapper"
12
12
  gem.authors = ["Christoph Helma"]
13
13
  gem.add_dependency "rest-client"
14
- gem.add_development_dependency "thoughtbot-shoulda"
15
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
15
  end
17
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
@@ -1,4 +1,3 @@
1
-
2
1
  #['rubygems', 'rest_client', 'spork', 'helper' ].each do |lib|
3
2
  ['rubygems', 'rest_client', 'spork' ].each do |lib|
4
3
  require lib
@@ -8,7 +7,7 @@ ENV['OPENTOX_COMPOUND'] = 'http://webservices.in-silico.ch/compound/v0/' unless
8
7
  ENV['OPENTOX_FEATURE'] = 'http://webservices.in-silico.ch/feature/v0/' unless ENV['OPENTOX_FEATURE']
9
8
  ENV['OPENTOX_DATASET'] = 'http://webservices.in-silico.ch/dataset/v0/' unless ENV['OPENTOX_DATASET']
10
9
  ENV['OPENTOX_FMINER'] = 'http://webservices.in-silico.ch/fminer/v0/' unless ENV['OPENTOX_FMINER']
11
- ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR']
10
+ ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR']
12
11
 
13
12
  module OpenTox
14
13
 
@@ -19,6 +18,22 @@ module OpenTox
19
18
  def uri_escape(string)
20
19
  URI.escape(string, /[^\w]/)
21
20
  end
21
+
22
+ # Returns true if object creation has finished (for asynchronous processes)
23
+ def finished?
24
+ YAML.load(RestClient.get(@uri))[:finished]
25
+ end
26
+
27
+ # Get the object name
28
+ def name
29
+ RestClient.get @uri + '/name'
30
+ end
31
+
32
+ # Deletes an object
33
+ def destroy
34
+ RestClient.delete @uri
35
+ end
36
+
22
37
  end
23
38
 
24
39
  class Compound < OpenTox
@@ -74,11 +89,6 @@ module OpenTox
74
89
  RestClient.get @uri + '/' + property
75
90
  end
76
91
 
77
- # Get the name of the feature
78
- def name
79
- RestClient.get @uri + '/name'
80
- end
81
-
82
92
  end
83
93
 
84
94
  class Dataset < OpenTox
@@ -87,23 +97,20 @@ module OpenTox
87
97
  def initialize(params)
88
98
  if params[:uri]
89
99
  @uri = params[:uri].to_s
100
+ elsif params[:name] and params[:filename]
101
+ @uri = `curl -X POST -F file=@#{params[:filename]} -F name="#{params[:name]}" #{ENV['OPENTOX_DATASET']}`
90
102
  elsif params[:name]
91
- @uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name]
103
+ @uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name], :data => params[:data].to_yaml
92
104
  end
93
105
  end
94
106
 
95
- # Get the dataset name
96
- def name
97
- RestClient.get @uri + '/name'
98
- end
99
-
100
107
  # Get all compounds from a dataset
101
108
  def compounds
102
109
  RestClient.get(@uri + '/compounds').split("\n").collect{ |c| Compound.new(:uri => c) }
103
110
  end
104
111
 
105
- # Get all compounds and features from a dataset, returns a hash with compound_uris as keys and arrays of features as values
106
- def all_compounds_and_features
112
+ # Get all compounds and features from a dataset, returns a hash with compound_uris as keys and arrays of feature_uris as values
113
+ def all_compounds_and_features_uris
107
114
  YAML.load(RestClient.get(@uri + '/compounds/features'))
108
115
  end
109
116
 
@@ -119,7 +126,13 @@ module OpenTox
119
126
 
120
127
  # Add a compound and a feature to a dataset
121
128
  def add(compound,feature)
122
- RestClient.post @uri, :compound_uri => compound.uri, :feature_uri => feature.uri
129
+ RestClient.put @uri, :compound_uri => compound.uri, :feature_uri => feature.uri
130
+ end
131
+
132
+ # Tell the dataset that it is complete
133
+ def close
134
+ puts @uri + '/finished'
135
+ RestClient.put @uri + '/finished', nil
123
136
  end
124
137
 
125
138
  end
@@ -143,14 +156,40 @@ module OpenTox
143
156
  def initialize(params)
144
157
  if params[:uri]
145
158
  @uri = params[:uri]
146
- elsif params[:dataset_ur]
147
- @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models/' , :dataset_uri => training_dataset.uri
159
+ elsif params[:dataset_uri]
160
+ @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models' , :dataset_uri => params[:dataset_uri]
148
161
  end
149
162
  end
150
163
 
151
164
  # Predict a compound
152
165
  def predict(compound)
153
- RestClient.post @uri, :compound_uri => compound.uri
166
+ LazarPrediction.new(:uri => RestClient.post(@uri, :compound_uri => compound.uri))
167
+ end
168
+
169
+ end
170
+
171
+ class LazarPrediction < OpenTox
172
+
173
+ def initialize(params)
174
+ if params[:uri]
175
+ @uri = params[:uri]
176
+ end
177
+ end
178
+
179
+ def classification
180
+ YAML.load(RestClient.get @uri)[:classification]
181
+ end
182
+
183
+ def confidence
184
+ YAML.load(RestClient.get @uri)[:confidence]
185
+ end
186
+
187
+ def neighbors
188
+ RestClient.get @uri + '/neighbors'
189
+ end
190
+
191
+ def features
192
+ RestClient.get @uri + '/features'
154
193
  end
155
194
 
156
195
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{opentox-ruby-api-wrapper}
8
- s.version = "0.1.5"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christoph Helma"]
12
- s.date = %q{2009-08-15}
12
+ s.date = %q{2009-08-17}
13
13
  s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)}
14
14
  s.email = %q{helma@in-silico.ch}
15
15
  s.extra_rdoc_files = [
@@ -27,7 +27,9 @@ Gem::Specification.new do |s|
27
27
  "lib/opentox-ruby-api-wrapper.rb",
28
28
  "lib/spork.rb",
29
29
  "opentox-ruby-api-wrapper.gemspec",
30
+ "test/hamster_carcinogenicity.csv",
30
31
  "test/opentox-ruby-api-wrapper_test.rb",
32
+ "test/start-local-webservices.rb",
31
33
  "test/test_helper.rb"
32
34
  ]
33
35
  s.homepage = %q{http://github.com/helma/opentox-ruby-api-wrapper}
@@ -37,7 +39,8 @@ Gem::Specification.new do |s|
37
39
  s.summary = %q{Ruby wrapper for the OpenTox REST API}
38
40
  s.test_files = [
39
41
  "test/test_helper.rb",
40
- "test/opentox-ruby-api-wrapper_test.rb"
42
+ "test/opentox-ruby-api-wrapper_test.rb",
43
+ "test/start-local-webservices.rb"
41
44
  ]
42
45
 
43
46
  if s.respond_to? :specification_version then
@@ -46,13 +49,10 @@ Gem::Specification.new do |s|
46
49
 
47
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
51
  s.add_runtime_dependency(%q<rest-client>, [">= 0"])
49
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
52
  else
51
53
  s.add_dependency(%q<rest-client>, [">= 0"])
52
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
54
  end
54
55
  else
55
56
  s.add_dependency(%q<rest-client>, [">= 0"])
56
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
57
  end
58
58
  end
@@ -0,0 +1,85 @@
1
+ CC=O,true
2
+ C12C3=C(C=CC=C3)CC1=CC(=CC=2)NC(C)=O,true
3
+ O=C(N)\C(C2=CC=CO2)=C/C1=CC=C([N+]([O-])=O)O1,true
4
+ C1(N=CNN=1)N,false
5
+ Br(=O)(=O)[O-].[K+],true
6
+ [Cl-].[Cd+2].[Cl-],false
7
+ O=S(=O)([O-])[O-].[Cd+2],false
8
+ ClC1=CC(=NC(=N1)SCC(=O)O)NC2=CC=CC(=C2C)C,false
9
+ ClCOC,true
10
+ C=C(Cl)C=C,false
11
+ Clc1ccc(cc1)c2ccc(COC(C)(C)C(O)=O)cc2,false
12
+ O=C1OC2=C(C=CC=C2)C=C1,false
13
+ ClC(=C(C1=CC=C(C=C1)Cl)C2=CC=C(C=C2)Cl)Cl,true
14
+ ClC(C(C1=CC=C(C=C1)Cl)C2=CC=C(C=C2)Cl)(Cl)Cl,false
15
+ C=CCN(CC=C)N=O,true
16
+ Cl\C2=C(/Cl)C3(Cl)C1C4CC(C1C2(Cl)C3(Cl)Cl)C5OC45,false
17
+ O=C(N(C)C)Cl,true
18
+ CN(C)N,true
19
+ N(NC)C.[H]Cl.[H]Cl,true
20
+ CCO,false
21
+ O=C(N(CC)N=O)NCCO,true
22
+ O=C(N(CC)N=O)NCC(=O)C,true
23
+ C=O,false
24
+ [O-][N+](=O)C1=CC=C(O1)C2=CSC(=N2)NNC=O,true
25
+ O=CC1=CC=CO1,false
26
+ OCC1CO1,true
27
+ O=C2C1=C(OC)C=C(OC)C(Cl)=C1O[C@]32C(OC)=CC(C[C@@](C)3[H])=O,false
28
+ ClC1=C(C(=C(C(=C1Cl)Cl)Cl)Cl)Cl,true
29
+ NN,true
30
+ OS(=O)(=O)O.NN,true
31
+ CC(=O)N(O)C1=CC2=C(C=C1)C3=CC=CC=C3C2,true
32
+ OCCNN,false
33
+ O=C(C1=CC=NC=C1)NN,false
34
+ OC(=O)C1=CC=NC=C1,false
35
+ O=C(NC1=CC=CC(=C1)Cl)OC(C)C,false
36
+ O=C(NC1=CC=CC=C1)OC(C)C,false
37
+ [O-]C(C)=O.[O-]C(C)=O.[Pb+2].[OH-].[OH-].[Pb+2].[OH-].[OH-].[Pb+2],false
38
+ CN(C)CCN(CC2=CC=CS2)C1=NC=CC=C1.Cl,false
39
+ NC1=C2C(=NC(=N1)N)N=CC(=N2)CN(C3=CC=C(C=C3)C(=O)N[C@@H](CCC(=O)O)C(=O)O)C,false
40
+ CN(N)C=O,true
41
+ O=C(C(=C)C)OC,false
42
+ CNN,true
43
+ O=C(C1=CC=CN=C1)CCCN(N=O)C,false
44
+ CC1=CC(=O)NC(=S)N1,true
45
+ CC(C(O)=O)(OC1=CC=C(C=C1)C2CCCC3=C2C=CC=C3)C,false
46
+ O=N[O-].[Na+],false
47
+ [O-][N+](C1=CC=C(C2=CSC(NC(C)=O)=N2)O1)=O,true
48
+ [O-][N+](=O)C1=CC=C(O1)C2=CSC(=N2)NC=O,true
49
+ O=[N+](C1=CC=C2C3=C1C=CC=C3CC2)[O-],false
50
+ N(CC(CO)O)(CC(O)C)N=O,true
51
+ N(CC(CO)O)(CC(C)=O)N=O,true
52
+ N(CC(CO)O)(CCO)N=O,false
53
+ O=C(C)CN(N=O)CCO,true
54
+ C1C(N(C(CN1N=O)C)C)C,true
55
+ N(CC(C)=O)(CC=C)N=O,true
56
+ N(CC(CO)O)(C)N=O,true
57
+ O=NN1CCOCC1,true
58
+ N1C=CC=C(C=1)C2N(N=O)CCC2,true
59
+ C1=CC=C(C=[N+]1[O-])C2CCCN2N=O,false
60
+ O=NN1CCCCC1,true
61
+ O=NN1CCCC1,true
62
+ O=C(N(CC(C)=O)N=O)NCCCl,true
63
+ N(C(=O)N)(N=O)CC(C)=O,true
64
+ C1(CCN=C=S)=CC=CC=C1,false
65
+ O=C1C(C2=CC=CC=C2)(C(=O)NC(=O)N1)CC,false
66
+ C1=C2C(=CC=C1NC3=CC=CC=C3)C=CC=C2,false
67
+ O=C1N2C(C3=C(C=CC=C3)CC2)CN(C1)C(=O)C4CCCCC4,false
68
+ C1(=CC(=C(O)C=C1)O)C(O)=O,false
69
+ O=C1C2=C(C=C(C=C2O)O)O/C(=C\1O)C3=CC(=C(C=C3)O)O.O.O,false
70
+ C1=C(C=CC(=C1)C(C2=CC=C(N)C(=C2)C)=C3C=CC(=N)C=C3)N.[H]Cl,false
71
+ C(C1=CC=C(C=C1)N)(C2=CC=C(C=C2)N)=C3C=CC(C=C3)=N.[H]Cl,false
72
+ OC2=CC1=C(C(O)=C2)C(C(O[C@@H]4O[C@@H]([C@H]([C@H](O)[C@H]4O)O)CO[C@H]3[C@H](O)[C@H](O)[C@H]([C@H](C)O3)O)=C(C5=CC(O)=C(C=C5)O)O1)=O,false
73
+ ClC(=CCl)Cl,false
74
+ NC(=O)OCC,true
75
+ C=CCl,true
76
+ N#[N+]C1=CC=CC=C1.F[B-](F)(F)F,false
77
+ C1(CN(CC(N1N=O)C)N=O)C,true
78
+ N(CCN(C)C)(C)N=O,true
79
+ C1(CN(N=O)CC(O1)C)C,true
80
+ O1C(N(CC1C)N=O)=O,true
81
+ CCOC(=O)N(C)N=O,true
82
+ C1N(COC1)N=O,true
83
+ O=C(N(CCC1=CC=CC=C1)N=O)N,true
84
+ O=NN1CCC1,true
85
+ F[B-](F)(F)F.[Na+],false
@@ -1,7 +1,46 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class OpentoxRubyApiWrapperTest < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
4
+
5
+ def setup
6
+ if ENV['LOCAL']
7
+ port = 5000
8
+ [ "opentox-compound", "opentox-feature" , "opentox-dataset" , "opentox-fminer" , "opentox-lazar" ].each do |component|
9
+ ENV[component.upcase.gsub(/-/,'_')] = "http://localhost:#{port}/"
10
+ port += 1
11
+ end
12
+ end
13
+ end
14
+
15
+ def test_create_dataset_and_model_and_make_a_prediction
16
+ dataset = OpenTox::Dataset.new :name => "Hamster Carcinogenicity", :filename => "test/hamster_carcinogenicity.csv"
17
+ puts dataset.uri
18
+ wait_for_completion dataset
19
+ assert_match(/#{ENV['OPENTOX_DATASET']}\d+$/,dataset.uri)
20
+ assert_equal("Hamster Carcinogenicity",dataset.name)
21
+ assert_equal(true,dataset.finished?)
22
+ lazar = OpenTox::Lazar.new :dataset_uri => dataset.uri
23
+ puts lazar.uri
24
+ wait_for_completion lazar
25
+ assert_equal(true,lazar.finished?)
26
+ assert_match(/#{ENV['OPENTOX_LAZAR']}model\/\d+$/,lazar.uri)
27
+ query_structure = OpenTox::Compound.new :smiles => 'c1ccccc1NN'
28
+ puts query_structure.uri
29
+ prediction = lazar.predict query_structure
30
+ puts prediction.uri
31
+ wait_for_completion prediction
32
+ puts prediction.classification
33
+ puts prediction.confidence
34
+ puts prediction.neighbors
35
+ puts prediction.features
36
+ assert_equal(true, prediction.classification)
37
+ assert_match(/0\.\d+/, prediction.confidence.to_s)
38
+ end
39
+
40
+ end
41
+
42
+ def wait_for_completion(object)
43
+ while (!object.finished?)
44
+ sleep 1
45
+ end
7
46
  end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ port = 5000
5
+ [ "opentox-compound", "opentox-feature" , "opentox-dataset" , "opentox-fminer" , "opentox-lazar" ].each do |component|
6
+ ENV[component.upcase.gsub(/-/,'_')] = "http://localhost:#{port}/"
7
+ Dir.chdir ENV['HOME'] + '/webservices/' + component
8
+ Dir["test.sqlite3"].each { |f| FileUtils.rm_rf(f) }
9
+ file = 'application.rb'
10
+ pid = fork {`urxvt -title #{component} -e thin --debug --rackup config.ru start -p #{port} -e test`}
11
+ Process.detach(pid)
12
+ port += 1
13
+ end
@@ -1,9 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'shoulda'
4
3
 
5
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
7
  require 'opentox-ruby-api-wrapper'
8
8
 
9
9
  class Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helma-opentox-ruby-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Helma
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-15 00:00:00 -07:00
12
+ date: 2009-08-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,16 +22,6 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- - !ruby/object:Gem::Dependency
26
- name: thoughtbot-shoulda
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
25
  description: Ruby wrapper for the OpenTox REST API (http://www.opentox.org)
36
26
  email: helma@in-silico.ch
37
27
  executables: []
@@ -52,7 +42,9 @@ files:
52
42
  - lib/opentox-ruby-api-wrapper.rb
53
43
  - lib/spork.rb
54
44
  - opentox-ruby-api-wrapper.gemspec
45
+ - test/hamster_carcinogenicity.csv
55
46
  - test/opentox-ruby-api-wrapper_test.rb
47
+ - test/start-local-webservices.rb
56
48
  - test/test_helper.rb
57
49
  has_rdoc: false
58
50
  homepage: http://github.com/helma/opentox-ruby-api-wrapper
@@ -84,3 +76,4 @@ summary: Ruby wrapper for the OpenTox REST API
84
76
  test_files:
85
77
  - test/test_helper.rb
86
78
  - test/opentox-ruby-api-wrapper_test.rb
79
+ - test/start-local-webservices.rb