From 43792e2322ded616c7eefb4b52083ba64e48e63c Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 16 Nov 2016 13:43:59 +0100 Subject: adapt code to lazar 1.0.0 --- lib/compound.rb | 8 ++++---- lib/model.rb | 2 +- test/aa.rb | 4 ++++ test/descriptor.rb | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/compound.rb b/lib/compound.rb index 9390a96..01ba036 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -23,14 +23,14 @@ post "/compound/descriptor/?" do descriptors.each do |descriptor| physchem_descriptors << PhysChem.find_by(:name => descriptor) end - result = compound.physchem physchem_descriptors - csv = result.collect{|k,v| "\"#{PhysChem.find(k).name}\",#{v}" }.join("\n") - csv = "SMILES,#{params[:identifier]}\n#{csv}" if params[:identifier] + result = compound.calculate_properties physchem_descriptors + csv = (0..result.size-1).collect{|i| "\"#{physchem_descriptors[i].name}\",#{result[i]}"}.join("\n") + csv = "SMILES,\"#{params[:identifier]}\"\n#{csv}" if params[:identifier] case @accept when "text/csv","application/csv" return csv when "application/json" - result_hash = result.collect{|k,v| {"#{PhysChem.find(k).name}" => "#{v}"}} # result.collect{|k,v| "\"#{PhysChem.find(k).name}\"" => "#{v}"}.join(",") + result_hash = (0..result.size-1).collect{|i| {"#{physchem_descriptors[i].name}" => "#{result[i]}"}} data = {"compound" => {"SMILES" => "#{params[:identifier]}"}} data["compound"]["InChI"] = "#{compound.inchi}" if compound.inchi data["compound"]["results"] = result_hash diff --git a/lib/model.rb b/lib/model.rb index db0c190..a20850b 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -24,7 +24,7 @@ get "/model/:id/?" do model = Model::Lazar.find params[:id] resource_not_found_error "Model with id: #{params[:id]} not found." unless model model[:URI] = uri("/model/#{model.id}") - model[:neighbor_algorithm_parameters][:feature_dataset_uri] = uri("/dataset/#{model[:neighbor_algorithm_parameters][:feature_dataset_id]}") if model[:neighbor_algorithm_parameters][:feature_dataset_id] + # model[:neighbor_algorithm_parameters][:feature_dataset_uri] = uri("/dataset/#{model[:neighbor_algorithm_parameters][:feature_dataset_id]}") if model[:neighbor_algorithm_parameters][:feature_dataset_id] model[:training_dataset_uri] = uri("/dataset/#{model.training_dataset_id}") if model.training_dataset_id model[:prediction_feature_uri] = uri("/dataset/#{model.prediction_feature_id}") if model.prediction_feature_id return model.to_json diff --git a/test/aa.rb b/test/aa.rb index 927bc35..f785900 100644 --- a/test/aa.rb +++ b/test/aa.rb @@ -2,6 +2,10 @@ require_relative "setup.rb" class AATest < MiniTest::Test + def self.test_order + :alpha + end + def test_0_login res = RestClientWrapper.post(File.join($host,"aa/authenticate"),{:username=>"guest", :password => "guest"},{:Accept => "text/plain"}) assert_equal res.code, 200 diff --git a/test/descriptor.rb b/test/descriptor.rb index eae3ebf..db4b6c7 100644 --- a/test/descriptor.rb +++ b/test/descriptor.rb @@ -27,13 +27,13 @@ class DescriptorTest < MiniTest::Test result = RestClientWrapper.get File.join($host, "compound/descriptor", bsonid), {}, {:accept => "application/json"} json = JSON.parse(result) assert_equal json["name"], "Openbabel.HBA1" - assert_equal json["numeric"], true + assert_equal json["calculated"], true end def test_04_post_descriptor 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,CC(=O)CC(C)C#N\n\"Joelib.LogP\",2.65908", result + assert_equal "SMILES,\"CC(=O)CC(C)C#N\"\n\"Joelib.LogP\",2.65908", result end # currently not applicable -- cgit v1.2.3