summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-08-14 11:19:37 +0000
committergebele <gebele@in-silico.ch>2017-08-14 11:19:37 +0000
commitb2b9cc5d14d10a62025486c5b3abbbeb06bf0ec6 (patch)
treeb7a53a54fab65652a2b67d2cc6946810238ec6fb
parentd04c3e870daaf6e42d08c8f8d32ab2f430e23b98 (diff)
parent6136efbd4066aeeb569424fbba619523ee038f95 (diff)
bumped version
-rw-r--r--VERSION2
-rw-r--r--lazar.gemspec1
-rw-r--r--lib/import.rb9
-rw-r--r--lib/lazar.rb1
-rw-r--r--lib/model.rb1
-rw-r--r--lib/overwrite.rb2
-rw-r--r--lib/rest-client-wrapper.rb1
-rwxr-xr-xscripts/mol2mmol-log10.rb19
-rw-r--r--test/compound.rb4
-rw-r--r--test/setup.rb4
10 files changed, 34 insertions, 10 deletions
diff --git a/VERSION b/VERSION
index 9084fa2..524cb55 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.0
+1.1.1
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/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 = {}
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/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
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/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
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
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