diff options
author | Christoph Helma <helma@in-silico.ch> | 2016-05-09 16:20:33 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2016-05-09 16:20:33 +0200 |
commit | 4818850830a5b00e01ce5251d7a36f63f18b2b86 (patch) | |
tree | 0e7f14180d3a5929af10d9e27301e098ebbaf3f8 /test/data/enm/enm-import.rb | |
parent | c1be8fe66f640d44dbbc9bfe5212733994bfb9c5 (diff) |
enm test data added
Diffstat (limited to 'test/data/enm/enm-import.rb')
-rw-r--r-- | test/data/enm/enm-import.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/data/enm/enm-import.rb b/test/data/enm/enm-import.rb new file mode 100644 index 0000000..37bc22b --- /dev/null +++ b/test/data/enm/enm-import.rb @@ -0,0 +1,47 @@ +require_relative '../lib/lazar.rb' +include OpenTox +$mongo.database.drop +$gridfs = $mongo.database.fs + +#get list of bundle URIs +bundles = JSON.parse(RestClientWrapper.get('https://data.enanomapper.net/bundle?media=application%2Fjson'))["dataset"] +bundles.each do |bundle| + uri = bundle["URI"] + nanoparticles = JSON.parse(RestClientWrapper.get(bundle["dataset"]+"?media=application%2Fjson"))["dataEntry"] + features = JSON.parse(RestClientWrapper.get(bundle["property"]+"?media=application%2Fjson"))["feature"] + nanoparticles.each do |np| + nanoparticle = Nanoparticle.find_or_create_by( + :name => np["values"]["https://data.enanomapper.net/identifier/name"], + :source => np["compound"]["URI"], + ) + nanoparticle.bundles << uri + nanoparticle.bundles.uniq! + np["composition"].each do |comp| + case comp["relation"] + when "HAS_CORE" + nanoparticle.core = comp["component"]["compound"]["URI"] + when "HAS_COATING" + nanoparticle.coating << comp["component"]["compound"]["URI"] + end + end if np["composition"] + np["values"].each do |u,v| + if u.match(/property/) + name, unit, source = nil + features.each do |uri,feat| + if u.match(/#{uri}/) + name = feat["title"] + unit = feat["units"] + source = uri + end + end + feature = Feature.find_or_create_by( + :name => name, + :unit => unit, + :source => source + ) + end + v.each{|value| nanoparticle.parse_ambit_value feature, value} if v.is_a? Array + end + nanoparticle.save! + end +end |