From 710031f953429c6e1a76aff4984ee76f7a1ee485 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 9 Jun 2017 11:08:45 +0000 Subject: added addressable gem to avoid URI::InvalidURIError --- lazar.gemspec | 1 + lib/lazar.rb | 1 + lib/overwrite.rb | 2 +- lib/rest-client-wrapper.rb | 1 + test/compound.rb | 4 +++- 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lazar.gemspec b/lazar.gemspec index 90f1cf2..3c704c8 100644 --- a/lazar.gemspec +++ b/lazar.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |s| # specify any dependencies here; for example: s.add_runtime_dependency 'bundler' s.add_runtime_dependency 'rest-client' + s.add_runtime_dependency 'addressable' s.add_runtime_dependency 'nokogiri' s.add_runtime_dependency 'rserve-client' s.add_runtime_dependency 'mongoid' diff --git a/lib/lazar.rb b/lib/lazar.rb index a756742..fff5598 100644 --- a/lib/lazar.rb +++ b/lib/lazar.rb @@ -1,6 +1,7 @@ require 'rubygems' require "bundler/setup" require "rest-client" +require 'addressable' require 'yaml' require 'json' require 'logger' diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 91bc9e1..89e57a0 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -197,7 +197,7 @@ module URI # @param [String] # @return [TrueClass,FalseClass] def self.valid? uri - u = URI.parse(uri) + u = Addressable::URI.parse(uri) u.scheme!=nil and u.host!=nil rescue URI::InvalidURIError false diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index f76a296..c9fd40f 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -26,6 +26,7 @@ module OpenTox define_singleton_method method do |uri,payload={},headers={},waiting_task=nil| + uri = Addressable::URI.encode(uri) # check input bad_request_error "Headers are not a hash: #{headers.inspect} for #{uri}." unless headers==nil or headers.is_a?(Hash) headers[:subjectid] ||= @@subjectid diff --git a/test/compound.rb b/test/compound.rb index bdfb749..c4e6161 100644 --- a/test/compound.rb +++ b/test/compound.rb @@ -61,7 +61,9 @@ print c.sdf def test_chemblid c = OpenTox::Compound.from_inchi "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H" - assert_equal "CHEMBL277500", c.chemblid + assert_equal "CHEMBL1531487", c.chemblid + c = OpenTox::Compound.from_smiles "OC[C@](c1onc(n1)c1ncn2c1CN(C)C(=O)c1c2cccc1Cl)(O)C" + assert_equal "CHEMBL145418", c.chemblid end def test_sdf_storage -- cgit v1.2.3 From 7e04c510f44f8ced9fdc5bd21438ec4fc16caed2 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 30 Jun 2017 14:18:04 +0000 Subject: consistend use of RestClientWrapper to import datasets --- lib/import.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/import.rb b/lib/import.rb index 96e7ad1..0857717 100644 --- a/lib/import.rb +++ b/lib/import.rb @@ -10,18 +10,17 @@ module OpenTox def self.import # time critical step: JSON parsing (>99%), Oj brings only minor speed gains (~1%) datasets = {} - bundles = JSON.parse(RestClientWrapper.get('https://data.enanomapper.net/bundle?media=application%2Fjson'))["dataset"] + bundles = JSON.parse(RestClientWrapper.get('https://data.enanomapper.net/bundle', {}, {accept: :json}))["dataset"] bundles.each do |bundle| datasets[bundle["URI"]] = Dataset.find_or_create_by(:source => bundle["URI"],:name => bundle["title"].strip) $logger.debug bundle["title"].strip - nanoparticles = JSON.parse(RestClientWrapper.get(bundle["dataset"]+"?media=application%2Fjson"))["dataEntry"] + nanoparticles = JSON.parse(RestClientWrapper.get(bundle["dataset"], {}, {accept: :json}))["dataEntry"] nanoparticles.each_with_index do |np,n| core_id = nil coating_ids = [] np["composition"].each do |c| uri = c["component"]["compound"]["URI"] - uri = CGI.escape File.join(uri,"&media=application/json") - data = JSON.parse(RestClientWrapper.get "https://data.enanomapper.net/query/compound/url/all?media=application/json&search=#{uri}") + data = JSON.parse(RestClientWrapper.get("https://data.enanomapper.net/query/compound/url/all?search=#{uri}", {}, {accept: :json})) source = data["dataEntry"][0]["compound"]["URI"] smiles = data["dataEntry"][0]["values"]["https://data.enanomapper.net/feature/http%3A%2F%2Fwww.opentox.org%2Fapi%2F1.1%23SMILESDefault"] names = [] @@ -52,7 +51,7 @@ module OpenTox nanoparticle.dataset_ids << datasets[bundle_uri].id end - studies = JSON.parse(RestClientWrapper.get(File.join(np["compound"]["URI"],"study")))["study"] + studies = JSON.parse(RestClientWrapper.get(File.join(np["compound"]["URI"],"study"), {}, {accept: :json}))["study"] studies.each do |study| dataset = datasets[np["bundles"].keys.first] proteomics_features = {} -- cgit v1.2.3 From 4960d36c9b453fa4a5bd6f483f1b8ae9d81e5a55 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 6 Jul 2017 08:44:18 +0000 Subject: cleanup test db --- test/setup.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/setup.rb b/test/setup.rb index c1cddfb..fbeb2d8 100644 --- a/test/setup.rb +++ b/test/setup.rb @@ -3,8 +3,8 @@ require 'minitest/autorun' require_relative '../lib/lazar.rb' #require 'lazar' include OpenTox -#$mongo.database.drop -#$gridfs = $mongo.database.fs # recreate GridFS indexes +$mongo.database.drop +$gridfs = $mongo.database.fs # recreate GridFS indexes TEST_DIR ||= File.expand_path(File.dirname(__FILE__)) DATA_DIR ||= File.join(TEST_DIR,"data") training_dataset = Dataset.where(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first -- cgit v1.2.3 From 9f2468afe7b45cd20472fb41b18ebeff3e4e908d Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 4 Aug 2017 14:02:40 +0000 Subject: script to convert mol to mmol -log10 in training dataset --- scripts/mol2mmol-log10.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 scripts/mol2mmol-log10.rb diff --git a/scripts/mol2mmol-log10.rb b/scripts/mol2mmol-log10.rb new file mode 100755 index 0000000..04f64ad --- /dev/null +++ b/scripts/mol2mmol-log10.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +require_relative '../lib/lazar.rb' +include OpenTox +newfile = ARGV[0].sub(/.csv/,"_mmol_log10.csv") +p newfile +CSV.open(newfile, "wb") do |csv| + CSV.read(ARGV[0]).each do |line| + smi,mol = line + if mol.numeric? + c = Compound.from_smiles smi + #delog = 10**(-1*mol.to_f) #if values already -log10 but mol + mmol = mol.to_f*1000 + log = -Math.log10(mmol) + csv << [smi, log] + else + csv << [smi, mol.gsub(/mol/,'mmol')] + end + end +end -- cgit v1.2.3 From 8e4944ea4d58a4a7ee4fd3b41a53c835cb0b419a Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 8 Aug 2017 14:53:22 +0000 Subject: added model field for qmrf metadata --- lib/model.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/model.rb b/lib/model.rb index 475a346..ba52c84 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -395,6 +395,7 @@ module OpenTox include Mongoid::Timestamps field :endpoint, type: String + field :qmrf, type: Hash field :species, type: String field :source, type: String field :unit, type: String -- cgit v1.2.3 From 6136efbd4066aeeb569424fbba619523ee038f95 Mon Sep 17 00:00:00 2001 From: gebele Date: Mon, 14 Aug 2017 11:19:02 +0000 Subject: bumped version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7dea76e..524cb55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.1 +1.1.1 -- cgit v1.2.3