summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile1
-rw-r--r--lib/opentox-ruby-api-wrapper.rb31
-rw-r--r--opentox-ruby-api-wrapper.gemspec6
-rw-r--r--test/hamster_carcinogenicity.csv85
-rw-r--r--test/opentox-ruby-api-wrapper_test.rb63
-rw-r--r--test/test_helper.rb2
6 files changed, 174 insertions, 14 deletions
diff --git a/Rakefile b/Rakefile
index 72eebcf..5d13273 100644
--- a/Rakefile
+++ b/Rakefile
@@ -11,7 +11,6 @@ begin
gem.homepage = "http://github.com/helma/opentox-ruby-api-wrapper"
gem.authors = ["Christoph Helma"]
gem.add_dependency "rest-client"
- gem.add_development_dependency "thoughtbot-shoulda"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb
index 81a7292..001c9ac 100644
--- a/lib/opentox-ruby-api-wrapper.rb
+++ b/lib/opentox-ruby-api-wrapper.rb
@@ -1,4 +1,3 @@
-
#['rubygems', 'rest_client', 'spork', 'helper' ].each do |lib|
['rubygems', 'rest_client', 'spork' ].each do |lib|
require lib
@@ -8,7 +7,7 @@ ENV['OPENTOX_COMPOUND'] = 'http://webservices.in-silico.ch/compound/v0/' unless
ENV['OPENTOX_FEATURE'] = 'http://webservices.in-silico.ch/feature/v0/' unless ENV['OPENTOX_FEATURE']
ENV['OPENTOX_DATASET'] = 'http://webservices.in-silico.ch/dataset/v0/' unless ENV['OPENTOX_DATASET']
ENV['OPENTOX_FMINER'] = 'http://webservices.in-silico.ch/fminer/v0/' unless ENV['OPENTOX_FMINER']
-ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR']
+ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR']
module OpenTox
@@ -19,6 +18,20 @@ module OpenTox
def uri_escape(string)
URI.escape(string, /[^\w]/)
end
+
+ def finished?
+ YAML.load(RestClient.get(@uri))[:finished]
+ end
+
+ def finished
+ print "closing "
+ puts @uri + '/finished'
+ RestClient.post @uri + '/finished'
+ end
+
+ def destroy
+ RestClient.delete @uri
+ end
end
class Compound < OpenTox
@@ -87,11 +100,19 @@ module OpenTox
def initialize(params)
if params[:uri]
@uri = params[:uri].to_s
- elsif params[:name]
+ elsif params[:name] and params[:filename]
+ @uri = `curl -X POST -F file=@#{params[:filename]} -F name="#{params[:name]}" #{ENV['OPENTOX_DATASET']}`
+ elsif params[:name]
@uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name]
end
end
+ def finished
+ print "closing "
+ puts @uri + '/finished'
+ RestClient.post(@uri + '/finished',nil)
+ end
+
# Get the dataset name
def name
RestClient.get @uri + '/name'
@@ -143,8 +164,8 @@ module OpenTox
def initialize(params)
if params[:uri]
@uri = params[:uri]
- elsif params[:dataset_ur]
- @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models/' , :dataset_uri => training_dataset.uri
+ elsif params[:dataset_uri]
+ @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models' , :dataset_uri => params[:dataset_uri]
end
end
diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec
index a583120..0e5ab5e 100644
--- a/opentox-ruby-api-wrapper.gemspec
+++ b/opentox-ruby-api-wrapper.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Christoph Helma"]
- s.date = %q{2009-08-15}
+ s.date = %q{2009-08-16}
s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)}
s.email = %q{helma@in-silico.ch}
s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
"lib/opentox-ruby-api-wrapper.rb",
"lib/spork.rb",
"opentox-ruby-api-wrapper.gemspec",
+ "test/hamster_carcinogenicity.csv",
"test/opentox-ruby-api-wrapper_test.rb",
"test/test_helper.rb"
]
@@ -46,13 +47,10 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
else
s.add_dependency(%q<rest-client>, [">= 0"])
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
else
s.add_dependency(%q<rest-client>, [">= 0"])
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
end
diff --git a/test/hamster_carcinogenicity.csv b/test/hamster_carcinogenicity.csv
new file mode 100644
index 0000000..009808f
--- /dev/null
+++ b/test/hamster_carcinogenicity.csv
@@ -0,0 +1,85 @@
+CC=O,true
+C12C3=C(C=CC=C3)CC1=CC(=CC=2)NC(C)=O,true
+O=C(N)\C(C2=CC=CO2)=C/C1=CC=C([N+]([O-])=O)O1,true
+C1(N=CNN=1)N,false
+Br(=O)(=O)[O-].[K+],true
+[Cl-].[Cd+2].[Cl-],false
+O=S(=O)([O-])[O-].[Cd+2],false
+ClC1=CC(=NC(=N1)SCC(=O)O)NC2=CC=CC(=C2C)C,false
+ClCOC,true
+C=C(Cl)C=C,false
+Clc1ccc(cc1)c2ccc(COC(C)(C)C(O)=O)cc2,false
+O=C1OC2=C(C=CC=C2)C=C1,false
+ClC(=C(C1=CC=C(C=C1)Cl)C2=CC=C(C=C2)Cl)Cl,true
+ClC(C(C1=CC=C(C=C1)Cl)C2=CC=C(C=C2)Cl)(Cl)Cl,false
+C=CCN(CC=C)N=O,true
+Cl\C2=C(/Cl)C3(Cl)C1C4CC(C1C2(Cl)C3(Cl)Cl)C5OC45,false
+O=C(N(C)C)Cl,true
+CN(C)N,true
+N(NC)C.[H]Cl.[H]Cl,true
+CCO,false
+O=C(N(CC)N=O)NCCO,true
+O=C(N(CC)N=O)NCC(=O)C,true
+C=O,false
+[O-][N+](=O)C1=CC=C(O1)C2=CSC(=N2)NNC=O,true
+O=CC1=CC=CO1,false
+OCC1CO1,true
+O=C2C1=C(OC)C=C(OC)C(Cl)=C1O[C@]32C(OC)=CC(C[C@@](C)3[H])=O,false
+ClC1=C(C(=C(C(=C1Cl)Cl)Cl)Cl)Cl,true
+NN,true
+OS(=O)(=O)O.NN,true
+CC(=O)N(O)C1=CC2=C(C=C1)C3=CC=CC=C3C2,true
+OCCNN,false
+O=C(C1=CC=NC=C1)NN,false
+OC(=O)C1=CC=NC=C1,false
+O=C(NC1=CC=CC(=C1)Cl)OC(C)C,false
+O=C(NC1=CC=CC=C1)OC(C)C,false
+[O-]C(C)=O.[O-]C(C)=O.[Pb+2].[OH-].[OH-].[Pb+2].[OH-].[OH-].[Pb+2],false
+CN(C)CCN(CC2=CC=CS2)C1=NC=CC=C1.Cl,false
+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
+CN(N)C=O,true
+O=C(C(=C)C)OC,false
+CNN,true
+O=C(C1=CC=CN=C1)CCCN(N=O)C,false
+CC1=CC(=O)NC(=S)N1,true
+CC(C(O)=O)(OC1=CC=C(C=C1)C2CCCC3=C2C=CC=C3)C,false
+O=N[O-].[Na+],false
+[O-][N+](C1=CC=C(C2=CSC(NC(C)=O)=N2)O1)=O,true
+[O-][N+](=O)C1=CC=C(O1)C2=CSC(=N2)NC=O,true
+O=[N+](C1=CC=C2C3=C1C=CC=C3CC2)[O-],false
+N(CC(CO)O)(CC(O)C)N=O,true
+N(CC(CO)O)(CC(C)=O)N=O,true
+N(CC(CO)O)(CCO)N=O,false
+O=C(C)CN(N=O)CCO,true
+C1C(N(C(CN1N=O)C)C)C,true
+N(CC(C)=O)(CC=C)N=O,true
+N(CC(CO)O)(C)N=O,true
+O=NN1CCOCC1,true
+N1C=CC=C(C=1)C2N(N=O)CCC2,true
+C1=CC=C(C=[N+]1[O-])C2CCCN2N=O,false
+O=NN1CCCCC1,true
+O=NN1CCCC1,true
+O=C(N(CC(C)=O)N=O)NCCCl,true
+N(C(=O)N)(N=O)CC(C)=O,true
+C1(CCN=C=S)=CC=CC=C1,false
+O=C1C(C2=CC=CC=C2)(C(=O)NC(=O)N1)CC,false
+C1=C2C(=CC=C1NC3=CC=CC=C3)C=CC=C2,false
+O=C1N2C(C3=C(C=CC=C3)CC2)CN(C1)C(=O)C4CCCCC4,false
+C1(=CC(=C(O)C=C1)O)C(O)=O,false
+O=C1C2=C(C=C(C=C2O)O)O/C(=C\1O)C3=CC(=C(C=C3)O)O.O.O,false
+C1=C(C=CC(=C1)C(C2=CC=C(N)C(=C2)C)=C3C=CC(=N)C=C3)N.[H]Cl,false
+C(C1=CC=C(C=C1)N)(C2=CC=C(C=C2)N)=C3C=CC(C=C3)=N.[H]Cl,false
+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
+ClC(=CCl)Cl,false
+NC(=O)OCC,true
+C=CCl,true
+N#[N+]C1=CC=CC=C1.F[B-](F)(F)F,false
+C1(CN(CC(N1N=O)C)N=O)C,true
+N(CCN(C)C)(C)N=O,true
+C1(CN(N=O)CC(O1)C)C,true
+O1C(N(CC1C)N=O)=O,true
+CCOC(=O)N(C)N=O,true
+C1N(COC1)N=O,true
+O=C(N(CCC1=CC=CC=C1)N=O)N,true
+O=NN1CCC1,true
+F[B-](F)(F)F.[Na+],false
diff --git a/test/opentox-ruby-api-wrapper_test.rb b/test/opentox-ruby-api-wrapper_test.rb
index 6f7f82e..256a06a 100644
--- a/test/opentox-ruby-api-wrapper_test.rb
+++ b/test/opentox-ruby-api-wrapper_test.rb
@@ -1,7 +1,64 @@
require 'test_helper'
class OpentoxRubyApiWrapperTest < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
+
+ def setup
+ @pids = []
+ port = 5000
+ [ "opentox-compound", "opentox-feature" , "opentox-dataset" , "opentox-fminer" , "opentox-lazar" ].each do |component|
+ ENV[component.upcase.gsub(/-/,'_')] = "http://localhost:#{port}/"
+=begin
+ Dir.chdir ENV['HOME'] + '/webservices/' + component
+ Dir["test.sqlite3"].each { |f| FileUtils.rm_rf(f) }
+ file = 'application.rb'
+ @pids << fork {`urxvt -title #{component} -e thin --debug --rackup config.ru start -p #{port} -e test`}
+ Process.detach(@pids.last)
+=end
+ port += 1
+ end
+ end
+
+=begin
+ def teardown
+ @pids.each do |pid|
+ begin
+ Process.kill(9,pid)
+ puts "killed " + pid.to_s
+ rescue
+ puts "failed to kill process" + pid.to_s
+ end
+ end
+ end
+=end
+
+ def test_create_dataset_and_model_and_make_a_prediction
+ #sleep 15
+ dataset = OpenTox::Dataset.new :name => "Hamster Carcinogenicity", :filename => "test/hamster_carcinogenicity.csv"
+ puts dataset.uri
+ wait_for_completion dataset
+ assert_match(/#{ENV['OPENTOX_DATASET']}\d+$/,dataset.uri)
+ assert_equal("Hamster Carcinogenicity",dataset.name)
+ lazar = OpenTox::Lazar.new :dataset_uri => dataset.uri
+ puts lazar.uri
+ wait_for_completion lazar
+ assert_match(/#{ENV['OPENTOX_LAZAR']}model\/\d+$/,lazar.uri)
+ query_structure = OpenTox::Compound.new :smiles => 'c1ccccc1NN'
+ prediction = lazar.predict query_structure
+ puts prediction.uri
+ wait_for_completion prediction
+ puts prediction.to_yaml
+ assert_equal(true, prediction.classification)
+ assert_match(/\d+/, prediction.classification)
+ end
+
+end
+
+def wait_for_completion(object)
+ timeout = 60
+ time = 0
+ while (!object.finished? and time < timeout)
+ sleep 1
+ time += 1
+ end
+ puts "timeout" if timeout >= 60
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 837ad16..4911cf4 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,9 +1,9 @@
require 'rubygems'
require 'test/unit'
-require 'shoulda'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+
require 'opentox-ruby-api-wrapper'
class Test::Unit::TestCase