From 7fc34ea47526bfd5e23441fc00d9149ee13d3089 Mon Sep 17 00:00:00 2001 From: davor Date: Thu, 29 Oct 2015 13:33:30 +0000 Subject: Added molecular weight to compound and mg conversions Added tests --- lib/compound.rb | 33 +++++++++++++++++++++++++++++++++ test/compound.rb | 14 ++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/compound.rb b/lib/compound.rb index a26528b..a86d2e6 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -21,6 +21,7 @@ module OpenTox field :png_id, type: BSON::ObjectId field :svg_id, type: BSON::ObjectId field :sdf_id, type: BSON::ObjectId + field :molecular_weight, type: Float field :fingerprints, type: Hash, default: {} field :default_fingerprint_size, type: Integer @@ -325,6 +326,38 @@ module OpenTox $mongo["compounds"].aggregate(aggregate).collect{ |r| [r["_id"], r["tanimoto"]] } end + + ## TODO: Should the following conversion functions are in overwrite.rb:class Numeric?! + # Get mg from logmmol (for nch LOAEL/pTD50 data) + # @return [Float] value in mg + def logmmol_to_mg(value, mw) + mg = (10**(-1.0*value.to_f)*(mw.to_f*1000)) + return mg + end + + # Get mg from mmol + # @return [Float] value in mg + def mmol_to_mg(value, mw) + mg = (value.to_f)*(mw.to_f) + return mg + end + + # Get mg from logmg + # @return [Float] value in mg + def logmg_to_mg(value) + mg = 10**value.to_f + return mg + end + + # Calculate molecular weight of Compound with OB and store it in object + # @return [Float] molecular weight + def molecular_weight + if self["molecular_weight"]==0.0 || self["molecular_weight"].nil? + update(:molecular_weight => OpenTox::Algorithm::Descriptor.physchem(self, ["Openbabel.MW"]).first) + end + self["molecular_weight"] + end + private diff --git a/test/compound.rb b/test/compound.rb index 22c152b..3857a85 100644 --- a/test/compound.rb +++ b/test/compound.rb @@ -174,4 +174,18 @@ print c.sdf p neighbors end end + + def test_molecular_weight + c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C" + assert_equal 100.15888, c.molecular_weight + end + + def test_mg_conversions + c = OpenTox::Compound.from_smiles "O" + mw = c.molecular_weight + assert_equal 18.01528, mw + assert_equal 0.8105107141417474, c.logmmol_to_mg(4.34688225631145, mw) + assert_equal 9007.64, c.mmol_to_mg(500, mw) + assert_equal 2437.9999984148976, c.logmg_to_mg(3.387033701) + end end -- cgit v1.2.3 From a4fd760d0dfff96f259ca9097ffe125935cf3df6 Mon Sep 17 00:00:00 2001 From: davor Date: Thu, 29 Oct 2015 15:42:53 +0100 Subject: Removed comment. --- lib/compound.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compound.rb b/lib/compound.rb index a86d2e6..4e62637 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -327,7 +327,6 @@ module OpenTox end - ## TODO: Should the following conversion functions are in overwrite.rb:class Numeric?! # Get mg from logmmol (for nch LOAEL/pTD50 data) # @return [Float] value in mg def logmmol_to_mg(value, mw) -- cgit v1.2.3 From 03614aca09c66b5f98ccd61bb975f91b592d0e86 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 30 Oct 2015 10:09:49 +0000 Subject: added csv encode option windows-1251:utf-8 --- lib/dataset.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index d989bdf..4da8fd6 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -165,7 +165,7 @@ module OpenTox $logger.debug "Skipping import of #{file}, it is already in the database (id: #{dataset.id})." else $logger.debug "Parsing #{file}." - table = CSV.read file, :skip_blanks => true + table = CSV.read file, :skip_blanks => true, :encoding => 'windows-1251:utf-8' dataset = self.new(:source => source, :name => name) dataset.parse_table table, bioassay end -- cgit v1.2.3 From ba2f5c56cb7bb93e41e1bb6b4a447fd8d1d5955f Mon Sep 17 00:00:00 2001 From: Micha Rautenberg Date: Fri, 30 Oct 2015 12:58:17 +0100 Subject: error methods do only accept 1 argument --- lib/rest-client-wrapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index de1b74f..60775e3 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -72,7 +72,7 @@ module OpenTox msg = "Could not parse error response from rest call '#{method}' to '#{uri}':\n#{response}" cause = nil end - Object.method(error[:method]).call msg, uri, cause # call error method + Object.method(error[:method]).call "#{msg}, #{uri}, #{cause}" # call error method else response end -- cgit v1.2.3 From 2081bda2b72f34758847fe699fecf890dae1e3df Mon Sep 17 00:00:00 2001 From: Micha Rautenberg Date: Fri, 30 Oct 2015 14:08:56 +0100 Subject: error methods do only accept 1 argument --- lib/rest-client-wrapper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index 60775e3..6b5d602 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -26,15 +26,15 @@ module OpenTox define_singleton_method method do |uri,payload={},headers={},waiting_task=nil| # check input - bad_request_error "Headers are not a hash: #{headers.inspect}", uri unless headers==nil or headers.is_a?(Hash) + bad_request_error "Headers are not a hash: #{headers.inspect} for #{uri}." unless headers==nil or headers.is_a?(Hash) headers[:subjectid] ||= @@subjectid - bad_request_error "Invalid URI: '#{uri}'", uri unless URI.valid? uri + bad_request_error "Invalid URI: '#{uri}'" unless URI.valid? uri #resource_not_found_error "URI '#{uri}' not found.", uri unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri) # make sure that no header parameters are set in the payload [:accept,:content_type,:subjectid].each do |header| if defined? $aa || URI(uri).host == URI($aa[:uri]).host else - bad_request_error "#{header} should be submitted in the headers", uri if payload and payload.is_a?(Hash) and payload[header] + bad_request_error "#{header} should be submitted in the headers of URI: #{uri}" if payload and payload.is_a?(Hash) and payload[header] end end -- cgit v1.2.3