From 9e99495ecbff147218023c136bade9e56a502fed Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 13 Oct 2016 14:39:04 +0200 Subject: descriptor tests fixed --- lib/compound.rb | 14 ++++++-------- lib/model.rb | 4 ++-- lib/nanoparticle.rb | 2 -- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/compound.rb b/lib/compound.rb index 72882d0..b47364c 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -75,11 +75,7 @@ module OpenTox fingerprints[type] end - def calculated_properties types=["PhysChem::OPENBABEL"] - descriptors = [] - types.each do |t| - descriptors += PhysChem.descriptors OpenTox.const_get(t) - end + def calculate_properties descriptors=PhysChem::OPENBABEL # TODO: speedup java descriptors calculated_ids = properties.keys # BSON::ObjectId instances are not allowed as keys in a BSON document. @@ -98,7 +94,8 @@ module OpenTox end end save - properties.select{|id,v| descriptors.collect{|d| d.id.to_s}.include? id} + descriptors.collect{|d| properties[d.id.to_s]} + #properties.select{|id,v| descriptors.collect{|d| d.id.to_s}.include? id} end def smarts_match smarts, count=false @@ -303,8 +300,9 @@ module OpenTox # Calculate molecular weight of Compound with OB and store it in object # @return [Float] molecular weight def molecular_weight - mw_feature = PhysChem.find_or_create_by(:name => "Openbabel.MW") - calculated_properties[mw_feature.id.to_s] + mw_feature = PhysChem.find_or_create_by(:name => "Openbabel.MW").id.to_s + calculate_properties unless properties[mw_feature] + properties[mw_feature] end private diff --git a/lib/model.rb b/lib/model.rb index 859df8b..7029c31 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -131,7 +131,7 @@ module OpenTox end else # parse independent_variables - if (model.algorithms[:descriptors] & ["PhysChem::OPENBABEL","PhysChem::CDK","PhysChem::JOELIB"]).empty? + if (model.algorithms[:descriptors] & [PhysChem::OPENBABEL,PhysChem::CDK,PhysChem::JOELIB]).empty? properties = model.substances.collect { |s| s.properties } all_property_ids = properties.collect{|p| p.keys}.flatten.uniq model.descriptor_ids = all_property_ids.select{|id| model.algorithms[:descriptors].include? Feature.find(id).category } @@ -139,7 +139,7 @@ module OpenTox # calculate physchem properties else - properties = model.substances.collect { |s| s.calculated_properties(model.algorithms[:descriptors]) } + properties = model.substances.collect { |s| s.calculate_properties(model.algorithms[:descriptors]) } model.descriptor_ids = properties.collect{|p| p.keys}.flatten.uniq model.independent_variables = model.descriptor_ids.collect{|i| properties.collect{|p| p[i]}} end diff --git a/lib/nanoparticle.rb b/lib/nanoparticle.rb index f74f263..23e155c 100644 --- a/lib/nanoparticle.rb +++ b/lib/nanoparticle.rb @@ -6,8 +6,6 @@ module OpenTox field :core, type: Hash, default: {} field :coating, type: Array, default: [] - attr_accessor :scaled_values - def add_feature feature, value, dataset unless feature.name == "ATOMIC COMPOSITION" or feature.name == "FUNCTIONAL GROUP" # redundand case feature.category -- cgit v1.2.3