diff options
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r-- | lib/dataset.rb | 78 |
1 files changed, 11 insertions, 67 deletions
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 <tt>:uri => uri</tt> or <tt>:name => name</tt> (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 |