diff options
author | rautenberg <rautenberg@in-silico.ch> | 2016-09-02 12:00:19 +0200 |
---|---|---|
committer | rautenberg <rautenberg@in-silico.ch> | 2016-09-02 12:00:19 +0200 |
commit | 8220c743b1ed446e9fd857c783375bbc094b60a5 (patch) | |
tree | 0f0dafef99b47fb0925d5b4871c5892014bdf950 | |
parent | 2f399ac5af0a855220fa20d7fbbc1cc97d0bf529 (diff) |
add nanoparticle route
-rw-r--r-- | api/api.json | 89 | ||||
-rw-r--r-- | lib/lazar-rest.rb | 1 | ||||
-rw-r--r-- | lib/nanoparticle.rb | 25 | ||||
-rw-r--r-- | test/descriptor.rb | 8 | ||||
-rw-r--r-- | test/setup.rb | 2 |
5 files changed, 120 insertions, 5 deletions
diff --git a/api/api.json b/api/api.json index e253fe7..e30ff98 100644 --- a/api/api.json +++ b/api/api.json @@ -369,6 +369,91 @@ } } }, + "/nanoparticle": { + "get": { + "tags": [ + "nanoparticle" + ], + "description": "Get a list of all nanoparticles", + "parameters": [ + { + "name": "accept", + "in": "header", + "description": "requested Content-Type", + "required": true, + "type": "string", + "enum": [ + "text/uri-list", + "application/json" + ] + } + ], + "produces": [ + "text/uri-list", + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "404": { + "$ref": "#/responses/404" + }, + "500": { + "$ref": "#/responses/500" + } + } + } + }, + "/nanoparticle/{id}": { + "get": { + "tags": [ + "nanoparticle" + ], + "description": "Get nanoparticle representation", + "parameters": [ + { + "name": "Content-Type", + "in": "header", + "description": "body Content-Type", + "required": true, + "type": "string", + "enum": [ + "application/json" + ] + }, + { + "$ref": "#/parameters/id" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "403": { + "$ref": "#/responses/403" + }, + "404": { + "$ref": "#/responses/404" + } + } + } + }, "/feature": { "get": { "tags": [ @@ -894,6 +979,10 @@ "description": "Substance" }, { + "name": "nanoparticle", + "description": "Nanoparticle" + }, + { "name": "feature", "description": "Feature" } diff --git a/lib/lazar-rest.rb b/lib/lazar-rest.rb index c0ea639..1e173fc 100644 --- a/lib/lazar-rest.rb +++ b/lib/lazar-rest.rb @@ -28,6 +28,7 @@ end "dataset.rb", "feature.rb", "model.rb", + "nanoparticle.rb", "substance.rb", "validation.rb" ].each{ |f| require_relative f } diff --git a/lib/nanoparticle.rb b/lib/nanoparticle.rb new file mode 100644 index 0000000..f32d834 --- /dev/null +++ b/lib/nanoparticle.rb @@ -0,0 +1,25 @@ +# Get all Nanoparticles +get "/nanoparticle/?" do + nanoparticles = Nanoparticle.all + case @accept + when "text/uri-list" + uri_list = nanoparticles.collect{|nanoparticle| uri("/nanoparticle/#{nanoparticle.id}")} + return uri_list.join("\n") + "\n" + when "application/json" + nanoparticles = JSON.parse nanoparticles.to_json + nanoparticles.each_index do |idx| + nanoparticles[idx][:URI] = uri("/nanoparticle/#{nanoparticles[idx]["_id"]["$oid"]}") + end + return nanoparticles.to_json + else + bad_request_error "Mime type #{@accept} is not supported." + end +end + +# Get a nanoparticle +get "/nanoparticle/:id/?" do + nanoparticle = Nanoparticle.find :id => params[:id] + resource_not_found_error "Nanoparticle with id: #{params[:id]} not found." unless nanoparticle + nanoparticle[:URI] = uri("/nanoparticle/#{nanoparticle.id}") + return nanoparticle.to_json +end
\ No newline at end of file diff --git a/test/descriptor.rb b/test/descriptor.rb index 8438898..834d56b 100644 --- a/test/descriptor.rb +++ b/test/descriptor.rb @@ -6,27 +6,27 @@ $host = "#{$host}" class DescriptorTest < MiniTest::Test def test_00_get_descriptors - result = RestClientWrapper.get File.join($host, "algorithm/descriptor"), {}, {:accept => "text/plain"} + result = RestClientWrapper.get File.join($host, "compound/descriptor"), {}, {:accept => "text/plain"} assert_equal result.code, 200 assert result.include?("Joelib.KierShape1: no description available\nJoelib.KierShape2: no description available"), "Descriptor list is not complete." assert_equal 110, result.lines.count end def test_01_get_descriptor - result = RestClientWrapper.get File.join($host, "algorithm/descriptor", "Openbabel.MW"), {}, {:accept => "text/plain"} + result = RestClientWrapper.get File.join($host, "compound/descriptor", "Openbabel.MW"), {}, {:accept => "text/plain"} assert_equal result.code, 200 assert_equal result, "Molecular Weight filter" end def test_02_post_descriptor - result = RestClientWrapper.post File.join($host, "algorithm/descriptor"), {:identifier => "CC(=O)CC(C)C#N", :descriptor => "Joelib.LogP"}, {:accept => "application/csv"} + result = RestClientWrapper.post File.join($host, "compound/descriptor"), {:identifier => "CC(=O)CC(C)C#N", :descriptor => "Joelib.LogP"}, {:accept => "application/csv"} assert_equal result.code, 200 assert_equal "SMILES,Joelib.LogP\nCC(=O)CC(C)C#N,2.65908\n", result end def test_03_post_descriptor_file file = File.join(DATA_DIR, "hamster_carcinogenicity.mini.csv") - result = RestClientWrapper.post File.join($host, "algorithm/descriptor"), {:file => File.open(file), :descriptor => "Openbabel.logP,Cdk.AtomCount,Cdk.CarbonTypes,Joelib.LogP"}, {:accept => "application/json"} + result = RestClientWrapper.post File.join($host, "compound/descriptor"), {:file => File.open(file), :descriptor => "Openbabel.logP,Cdk.AtomCount,Cdk.CarbonTypes,Joelib.LogP"}, {:accept => "application/json"} assert_equal result.code, 200 proof_result = File.read(File.join(REST_DATA_DIR, "test_03_post_descriptor_file.result")) assert_equal result, proof_result.strip diff --git a/test/setup.rb b/test/setup.rb index b670fdd..1c47dff 100644 --- a/test/setup.rb +++ b/test/setup.rb @@ -2,7 +2,7 @@ require 'minitest/autorun' require_relative '../../lazar/lib/lazar.rb' require_relative '../../lazar/test/setup.rb' -$host = "https://mr-test.in-silico.ch" +$host = "https://enm.in-silico.ch" include OpenTox REST_TEST_DIR ||= File.expand_path(File.dirname(__FILE__)) REST_DATA_DIR ||= File.join(REST_TEST_DIR,"data") |