From adfcc9d572a2122b1b030dc04b3abf46007fb3f7 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 23 Nov 2009 18:17:37 +0100 Subject: RDF support added --- Rakefile | 11 +++--- lib/compound.rb | 6 ++-- lib/dataset.rb | 78 ++++++---------------------------------- lib/environment.rb | 2 ++ lib/feature.rb | 48 ------------------------- lib/opentox-ruby-api-wrapper.rb | 6 ++-- opentox-ruby-api-wrapper.gemspec | 15 +------- 7 files changed, 27 insertions(+), 139 deletions(-) delete mode 100644 lib/feature.rb diff --git a/Rakefile b/Rakefile index 9d042a5..1c79e15 100644 --- a/Rakefile +++ b/Rakefile @@ -15,15 +15,16 @@ begin gem.add_dependency "rack" gem.add_dependency "rack-contrib" gem.add_dependency "thin" - gem.add_dependency "ezmobius-redis-rb" + #gem.add_dependency "ezmobius-redis-rb" gem.add_dependency "emk-sinatra-url-for" gem.add_dependency "cehoffman-sinatra-respond_to" - gem.add_dependency "dm-core" - gem.add_dependency "datamapper" - gem.add_dependency "do_sqlite3" + #gem.add_dependency "dm-core" + #gem.add_dependency "datamapper" + #gem.add_dependency "do_sqlite3" gem.add_development_dependency "cucumber" gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] - gem.files.include %w(lib/tasks/opentox.rb, lib/tasks/redis.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/feature.rb, lib/model.rb, lib/utils.rb, lib/templates/*) + #gem.files.include %w(lib/tasks/opentox.rb, lib/tasks/redis.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/feature.rb, lib/model.rb, lib/utils.rb, lib/templates/*) + gem.files.include %w(lib/tasks/opentox.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/model.rb, lib/utils.rb, lib/templates/*) # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings end Jeweler::GemcutterTasks.new diff --git a/lib/compound.rb b/lib/compound.rb index c4ba8d9..416acab 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -15,7 +15,7 @@ module OpenTox @inchi = params[:inchi] @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi)) elsif params[:name] - @inchi = RestClient.get "#{@@cactus_uri}#{params[:name]}/stdinchi" + @inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi)) elsif params[:uri] @inchi = params[:uri].sub(/^.*InChI/, 'InChI') @@ -44,8 +44,8 @@ module OpenTox end # Match an array of smarts features, returns matching features - def match(smarts_dataset) - smarts_dataset.all_features.collect{ |uri| uri if self.match?(Feature.new(:uri => uri).name) }.compact + def match(smarts_array) + smarts_array.collect{|s| s if match?(s)}.compact end def smiles2inchi(smiles) diff --git a/lib/dataset.rb b/lib/dataset.rb index 754e7f4..fe49622 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -1,11 +1,5 @@ module OpenTox - # key: /datasets - # set: dataset uris - # key: /dataset/:dataset/compounds - # set: compound uris - # key: /dataset/:dataset/compound/:inchi - # set: feature uris class Dataset < OpenTox # Initialize with :uri => uri or :name => name (creates a new dataset) @@ -13,81 +7,31 @@ module OpenTox super(uri) end - def self.create(params) - uri = RestClient.post @@config[:services]["opentox-dataset"], :name => params[:name] + def self.create(data) + uri = RestClient.post @@config[:services]["opentox-dataset"], data, :content_type => 'application/rdf+xml' Dataset.new(uri.to_s) end - def self.find(params) - begin - if params[:name] - uri = File.join(@@config[:services]["opentox-dataset"], URI.encode(params[:name])) - elsif params[:uri] - uri = params[:uri] - end - RestClient.get uri # check if the resource is available - Dataset.new(uri) if uri - rescue - nil - end - end - - def self.find_or_create(params) - self.create(params) unless self.find(params) + def self.find(uri) + RestClient.get uri # check if the resource is available end def self.base_uri @@config[:services]["opentox-dataset"] end - def import(params) - if params[:csv] - # RestClient seems not to work for file uploads - #RestClient.post @uri + '/import', :compound_format => params[:compound_format], :content_type => "text/csv", :file => File.new(params[:csv]) - `curl -X POST -F "file=@#{params[:csv]};type=text/csv" -F compound_format=#{params[:compound_format]} #{@uri + '/import'}` - end - end - - def add(features) - RestClient.put @uri, :features => features - end - - # Get all compounds from a dataset - def compound_uris - RestClient.get(File.join(@uri, 'compounds')).split("\n") - end - - def compounds - compound_uris.collect{|uri| Compound.new(:uri => uri)} - end - - # Get all features for a compound - def feature_uris(compound) - uri = File.join(@uri, 'compound', CGI.escape(compound.inchi)) # URI.encode does not work here - RestClient.get(uri).split("\n") - end - - # Get all features for a compound - def features(compound) - feature_uris(compound).collect{|uri| Feature.new(:uri => uri)} - end - - def all_features - RestClient.get(File.join(@uri, 'features')).split("\n") - end - # Delete a dataset def delete RestClient.delete @uri end - def tanimoto(dataset) - RestClient.get(File.join(@uri,'tanimoto',dataset.path)) - end - - def weighted_tanimoto(dataset) - RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path)) - end +# def tanimoto(dataset) +# RestClient.get(File.join(@uri,'tanimoto',dataset.path)) +# end +# +# def weighted_tanimoto(dataset) +# RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path)) +# end end diff --git a/lib/environment.rb b/lib/environment.rb index 3a9319d..7ce6c7e 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -18,6 +18,7 @@ else end # configure redis database +=begin begin case ENV['RACK_ENV'] when 'production' @@ -31,3 +32,4 @@ begin rescue puts "Redis database not running, please start it with 'rake redis:start'." end +=end diff --git a/lib/feature.rb b/lib/feature.rb deleted file mode 100644 index a3ba333..0000000 --- a/lib/feature.rb +++ /dev/null @@ -1,48 +0,0 @@ -module OpenTox - - # uri: /feature/:name/:property_name/:property_value/... - class Feature < OpenTox - - attr_accessor :name, :values - - def initialize(params) - if params[:uri] - @uri = params[:uri] - items = URI.split(@uri)[5].split(/\//) - @name = items[1] - @values = {} - i = 2 - while i < items.size - @values[items[i]] = items[i+1] - i += 2 - end - else - @name = params[:name] - @values = {} - params.each do |k,v| - @values[k] = v unless k.to_s == 'name' - end - @uri = File.join(@@config[:services]["opentox-feature"],path) - end - end - - def values_path - path = '' - @values.each do |k,v| - path = File.join path, URI.encode(k.to_s), URI.encode(v.to_s) - end - path - end - - def path - File.join(URI.encode(@name),values_path) - end - - def value(property) - items = @uri.split(/\//) - i = items.index(property) - items[i+1] - end - - end -end diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb index c4d9d4e..a55b59e 100644 --- a/lib/opentox-ruby-api-wrapper.rb +++ b/lib/opentox-ruby-api-wrapper.rb @@ -1,4 +1,5 @@ -['rubygems', 'sinatra', 'sinatra/url_for', 'redis','builder', 'rest_client', 'yaml', 'cgi', 'spork', 'environment'].each do |lib| +#['rubygems', 'sinatra', 'sinatra/url_for', 'redis','builder', 'rest_client', 'yaml', 'cgi', 'spork', 'environment'].each do |lib| +['rubygems', 'sinatra', 'sinatra/url_for', 'builder', 'rest_client', 'yaml', 'cgi', 'spork', 'environment'].each do |lib| require lib end @@ -8,6 +9,7 @@ rescue LoadError puts "Please install Openbabel with 'rake openbabel:install' in the compound component" end -['opentox', 'compound','feature','dataset','algorithm','model','task','utils'].each do |lib| +#['opentox', 'compound','feature','dataset','algorithm','model','task','utils'].each do |lib| +['opentox', 'compound','dataset','algorithm','model','task','utils'].each do |lib| require lib end diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec index bb54a0c..db31db0 100644 --- a/opentox-ruby-api-wrapper.gemspec +++ b/opentox-ruby-api-wrapper.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Christoph Helma"] - s.date = %q{2009-11-17} + s.date = %q{2009-11-20} s.default_executable = %q{opentox-install-debian.sh} s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)} s.email = %q{helma@in-silico.ch} @@ -28,7 +28,6 @@ Gem::Specification.new do |s| "lib/compound.rb", "lib/dataset.rb", "lib/environment.rb", - "lib/feature.rb", "lib/helper.rb", "lib/model.rb", "lib/opentox-ruby-api-wrapper.rb", @@ -59,12 +58,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) @@ -72,12 +67,8 @@ Gem::Specification.new do |s| s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end else @@ -86,12 +77,8 @@ Gem::Specification.new do |s| s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end end -- cgit v1.2.3