summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-09-08 14:19:12 +0200
committerChristoph Helma <helma@in-silico.de>2009-09-08 14:19:12 +0200
commit07e9efa51faece0aa562d7eeab7c61b8ab8d102a (patch)
treefad31aec011354d409a524ad292cbd336486725a
parent72ab8d7589b9f775b25071bd9e9f6d9727a25bdb (diff)
adapted for new dataset service
-rw-r--r--Rakefile4
-rw-r--r--application.rb40
-rw-r--r--config.ru10
-rw-r--r--test/.test.rb.swpbin0 -> 12288 bytes
-rw-r--r--test/hamster_carcinogenicity.csv85
-rw-r--r--test/test.rb30
6 files changed, 142 insertions, 27 deletions
diff --git a/Rakefile b/Rakefile
index 2a61a3f..2e52a8c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake'
+require 'tasks/opentox'
desc "Install required gems and fminer"
task :install do
@@ -25,7 +26,6 @@ end
desc "Run tests"
task :test do
- puts "No tests for fminer."
- #load 'test.rb'
+ load 'test/test.rb'
end
diff --git a/application.rb b/application.rb
index 6b1d69c..e3985ee 100644
--- a/application.rb
+++ b/application.rb
@@ -1,6 +1,7 @@
-['rubygems', 'sinatra', 'opentox-ruby-api-wrapper', 'libfminer/fminer'].each do |lib|
- require lib
-end
+require 'rubygems'
+require 'sinatra'
+require 'libfminer/fminer'
+require 'opentox-ruby-api-wrapper'
ENV['FMINER_SMARTS'] = 'true'
ENV['FMINER_PVALUES'] = 'true'
@@ -8,24 +9,26 @@ ENV['FMINER_PVALUES'] = 'true'
post '/?' do
- training_dataset = OpenTox::Dataset.new :uri => params[:dataset_uri]
-
- compounds = training_dataset.compounds
- endpoint_name = training_dataset.name
+ dataset = OpenTox::Dataset.find :uri => params[:dataset_uri]
id = 1
compound_list = []
- compounds.each do |c|
+ dataset.compounds.each do |c|
+ begin
+ activities = dataset.features(c,'activity')
+ rescue
+ puts "could not get activities for #{c.uri}"
+ next
+ end
smiles = c.smiles
- activity_features = training_dataset.features(c)
- activity_features.each do |feature|
+ activities.each do |feature|
activity = feature.value('classification')
case activity.to_s
when 'true'
- compound_list[id] = c
+ compound_list[id] = c.uri
@@fminer.AddCompound(smiles,id)
@@fminer.AddActivity(true, id)
when 'false'
- compound_list[id] = c
+ compound_list[id] = c.inchi
@@fminer.AddCompound(smiles,id)
@@fminer.AddActivity(false, id)
end
@@ -39,14 +42,14 @@ post '/?' do
(0 .. @@fminer.GetNoRootNodes()-1).each do |j|
result = @@fminer.MineRoot(j)
(0 .. result.size-1).each do |i|
+ #puts result[i]
features << YAML.load(result[i])[0]
end
end
@@fminer.Reset
- smarts_dataset = OpenTox::Dataset.new(:name => endpoint_name + ' BBRC fragments')
-
+ smarts_features = {}
features.each do |f|
smarts = f[0]
p = f[1]
@@ -57,13 +60,12 @@ post '/?' do
effect = 'deactivating'
end
ids.each do |id|
- compound = compound_list[id]
- smarts_feature = OpenTox::Feature.new(:name => smarts, :values => {:p_value => p, :effect => effect})
- smarts_dataset.add(compound,smarts_feature)
+ smarts_features[compound_list[id]] = [] unless smarts_features[compound_list[id]]
+ smarts_features[compound_list[id]] << OpenTox::Feature.new(:name => smarts, :values => {:p_value => p, :effect => effect}).uri
end
end
- smarts_dataset.close
- smarts_dataset.uri
+ dataset.add_features(smarts_features,"BBRC_representatives")
+ dataset.uri
end
diff --git a/config.ru b/config.ru
index 95e58ae..02ca8b3 100644
--- a/config.ru
+++ b/config.ru
@@ -2,11 +2,9 @@ require 'rubygems'
require 'sinatra'
require 'application.rb'
-if ENV["RACK_ENV"] == 'production'
- FileUtils.mkdir_p 'log' unless File.exists?('log')
- log = File.new("log/sinatra.log", "a")
- $stdout.reopen(log)
- $stderr.reopen(log)
-end
+FileUtils.mkdir_p 'log' unless File.exists?('log')
+log = File.new("log/#{ENV["RACK_ENV"]}.log", "a")
+$stdout.reopen(log)
+$stderr.reopen(log)
run Sinatra::Application
diff --git a/test/.test.rb.swp b/test/.test.rb.swp
new file mode 100644
index 0000000..6a53d9c
--- /dev/null
+++ b/test/.test.rb.swp
Binary files differ
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/test.rb b/test/test.rb
new file mode 100644
index 0000000..183c6fc
--- /dev/null
+++ b/test/test.rb
@@ -0,0 +1,30 @@
+require 'application'
+require 'test/unit'
+require 'rack/test'
+
+set :environment, :test
+
+class FminerTest < Test::Unit::TestCase
+ include Rack::Test::Methods
+
+ def app
+ Sinatra::Application
+ end
+
+ def setup
+ end
+
+ def teardown
+ @dataset.delete
+ end
+
+ def test_create_bbrc
+ @dataset = OpenTox::Dataset.create :name => "Hamster Carcinogenicity"
+ @dataset.import :csv => File.join(File.dirname(__FILE__), "hamster_carcinogenicity.csv"), :compound_format => "smiles", :feature_type => "activity"
+ post '/', :dataset_uri => @dataset.uri
+ assert last_response.ok?
+ response = `curl "#{File.join(@dataset.uri , 'compound/InChI=1S/C12H9NO2/c14-13(15)11-7-6-9-5-4-8-2-1-3-10(11)12(8)9/h1-3,6-7H,4-5H2/BBRC_representatives')}"`
+ assert response != nil
+ puts response
+ end
+end