diff options
author | Christoph Helma <helma@in-silico.de> | 2009-09-11 23:53:41 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2009-09-11 23:53:41 +0200 |
commit | 03055c09593a14eb4af24fb85a7be43b52277fca (patch) | |
tree | 59963ab0e654d7ce0fed09cfa7ddac54fbccbd88 | |
parent | 5bbc940778b67b0ced009acd2cc735fd290031fc (diff) |
InChI escaping fixed
-rw-r--r-- | application.rb | 14 | ||||
-rw-r--r-- | dataset.rb | 3 | ||||
-rw-r--r-- | test/test.rb | 55 |
3 files changed, 45 insertions, 27 deletions
diff --git a/application.rb b/application.rb index 5c4722c..ad60764 100644 --- a/application.rb +++ b/application.rb @@ -20,12 +20,22 @@ set :default_content, :yaml helpers do def find - uri = uri(params[:splat].first) + # + charges are dropped + uri = uri(params[:splat].first.gsub(/(InChI.*) (.*)/,'\1+\2')) # reinsert dropped '+' signs in InChIs + #puts uri halt 404, "Dataset \"#{uri}\" not found." unless @set = Dataset.find(uri) end def uri(name) - uri = url_for("/dataset/", :full) + URI.encode(name) +=begin + if name =~ /InChI/ + name = URI.encode(name,/[^#{URI::PATTERN::UNRESERVED}]/) + else + name = URI.encode(name) + end +=end + name = URI.encode(name) + uri = url_for("/dataset/", :full) + name end end @@ -19,6 +19,7 @@ class Dataset end def self.find(uri) + #puts uri if @@redis.set_member? "datasets", uri Dataset.new(uri) else @@ -67,8 +68,6 @@ class Dataset end def weighted_tanimoto(set_uri) - puts set_uri - puts @@redis.set_members(set_uri).to_yaml union = @@redis.set_union(@uri,set_uri) intersect = @@redis.set_intersect(@uri,set_uri) diff --git a/test/test.rb b/test/test.rb index 8da6c88..b6d9a99 100644 --- a/test/test.rb +++ b/test/test.rb @@ -27,7 +27,6 @@ class DatasetsTest < Test::Unit::TestCase get uri assert last_response.ok? get uri + '/name' - puts last_response.body assert last_response.ok? assert_equal "Test dataset", last_response.body delete uri @@ -37,26 +36,36 @@ class DatasetsTest < Test::Unit::TestCase end def test_create_dataset_from_csv - smiles = 'CC(=O)Nc1scc(n1)c1ccc(o1)[N+](=O)[O-]' - compound = OpenTox::Compound.new(:smiles => smiles) - post '/datasets', :name => "Hamster Carcinogenicity" - uri = last_response.body - assert last_response.ok? - post uri + '/import', :file => Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__), "hamster_carcinogenicity.csv"), "text/csv"), :compound_format => "smiles" - get uri - assert last_response.ok? - get uri + '/compounds' - assert last_response.ok? - assert last_response.body.include?(compound.inchi) - get File.join(uri , 'compound', compound.inchi) - assert last_response.ok? - assert last_response.body.include?("Hamster%20Carcinogenicity/classification/true") - get File.join(uri , 'features') - puts last_response.body.to_yaml - delete uri - assert last_response.ok? - get uri - assert !last_response.ok? + [ + ['F[B-](F)(F)F.[Na+]','false'], + ['CC(=O)Nc1scc(n1)c1ccc(o1)[N+](=O)[O-]','true'], + ['NN.OS(=O)(=O)O','true'], + ['[Cd+2].[O-]S(=O)(=O)[O-]','false'] + ].each do |items| + smiles = items[0] + activity = items[1] + + compound = OpenTox::Compound.new(:smiles => smiles) + post '/datasets', :name => "Hamster Carcinogenicity" + uri = last_response.body + assert last_response.ok? + post uri + '/import', :file => Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__), "hamster_carcinogenicity.csv"), "text/csv"), :compound_format => "smiles" + get uri + assert last_response.ok? + get uri + '/compounds' + assert last_response.ok? + assert last_response.body.include?(compound.inchi) + get File.join(uri , 'compound', compound.inchi) + puts last_response.body + assert last_response.ok? + assert last_response.body.include?("Hamster%20Carcinogenicity/classification/#{activity}") + get File.join(uri , 'features') + puts last_response.body.to_yaml + delete uri + assert last_response.ok? + get uri + assert !last_response.ok? + end end =begin @@ -74,8 +83,8 @@ class DatasetsTest < Test::Unit::TestCase #@feature_set = OpenTox::Algorithms::Fminer.new :dataset_uri => @dataset name = "Similarity test dataset" data = { - 'c1ccccc1' => - #'[O-][N+](=O)C/C=C\C(=O)Cc1cc(C#N)ccc1' => + #'c1ccccc1' => + '[O-][N+](=O)C/C=C\C(=O)Cc1cc(C#N)ccc1' => { 'A' => 1.0, 'B' => 0.9, |