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 --- lib/compound.rb | 6 ++-- lib/dataset.rb | 78 ++++++----------------------------------- lib/environment.rb | 2 ++ lib/feature.rb | 48 ------------------------- lib/opentox-ruby-api-wrapper.rb | 6 ++-- 5 files changed, 20 insertions(+), 120 deletions(-) delete mode 100644 lib/feature.rb (limited to 'lib') 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 -- cgit v1.2.3