From f41cb049445a8817298a3a64899c7a70be2c8ee9 Mon Sep 17 00:00:00 2001 From: Micha Rautenberg Date: Mon, 19 Oct 2015 17:49:15 +0200 Subject: add basic compound request --- application.rb | 25 +++++++++++++++++++++++++ test/compound.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/application.rb b/application.rb index 382a183..092369e 100644 --- a/application.rb +++ b/application.rb @@ -89,3 +89,28 @@ get "/algorithm/descriptor/?:descriptor?" do end end +get %r{/compound/(.+)} do |inchi| + inchi = "InChI=#{inchi}" unless inchi.match(/^InChI/) + compound = OpenTox::Compound.from_inchi inchi + response['Content-Type'] = @accept + case @accept + when "application/json" + return compound.to_json + when "chemical/x-daylight-smiles" + return compound.smiles + when "chemical/x-inchi" + return compound.inchi + when "chemical/x-mdl-sdfile" + return compound.sdf + when "chemical/x-mdl-molfile" + when "image/png" + return compound.png + when "image/svg+xml" + return compound.svg + when "text/plain" + return "#{compound.names}\n" + else + return compound.inspect + end +end + diff --git a/test/compound.rb b/test/compound.rb index 914b645..01cd9b5 100644 --- a/test/compound.rb +++ b/test/compound.rb @@ -8,7 +8,46 @@ class CompoundTest < MiniTest::Test def test_00_get_inchi res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "chemical/x-inchi"} assert_equal res.code, 200 + assert_equal res, "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H" + end + def test_01_get_smiles + res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "chemical/x-daylight-smiles"} + assert_equal res.code, 200 + assert_equal res, "c1ccccc1" + end + + def test_02_get_sdf + res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "chemical/x-mdl-sdfile"} + assert_equal res.code, 200 + assert res.include?("OpenBabel10191511303D") + end + + def test_03_get_png + res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "image/png"} + assert_equal res.code, 200 + assert_equal "image/png", res.headers[:content_type] + end + + def test_04_get_svg + res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "image/svg+xml"} + assert_equal res.code, 200 + assert res.include?(" "text/plain"} + assert_equal res.code, 200 + assert res.include?("Benzene") + assert res.include?("401765_ALDRICH") end end -- cgit v1.2.3