Class: OpenTox::Dataset

Inherits:
OpenTox show all
Defined in:
lib/opentox-ruby-api-wrapper.rb

Instance Attribute Summary

Attributes inherited from OpenTox

#uri

Instance Method Summary collapse

Methods inherited from OpenTox

#destroy, #finished?, #name, #uri_escape

Constructor Details

#initialize(params) ⇒ Dataset

Initialize with :uri => uri or :name => name (creates a new dataset)



97
98
99
100
101
102
103
104
105
# File 'lib/opentox-ruby-api-wrapper.rb', line 97

def initialize(params)
  if params[:uri]
    @uri = params[:uri].to_s
  elsif params[:name] and params[:filename]
    @uri = `curl -X POST -F file=@#{params[:filename]} -F name="#{params[:name]}" #{ENV['OPENTOX_DATASET']}`
  elsif params[:name] 
    @uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name], :data => params[:data].to_yaml
  end
end

Instance Method Details

#add(compound, feature) ⇒ Object

Add a compound and a feature to a dataset



128
129
130
# File 'lib/opentox-ruby-api-wrapper.rb', line 128

def add(compound,feature)
  RestClient.put @uri, :compound_uri => compound.uri, :feature_uri => feature.uri
end

#all_compounds_and_features_urisObject

Get all compounds and features from a dataset, returns a hash with compound_uris as keys and arrays of feature_uris as values



113
114
115
# File 'lib/opentox-ruby-api-wrapper.rb', line 113

def all_compounds_and_features_uris
  YAML.load(RestClient.get(@uri + '/compounds/features'))
end

#all_featuresObject

Get all features from a dataset



118
119
120
# File 'lib/opentox-ruby-api-wrapper.rb', line 118

def all_features
  RestClient.get(@uri + '/features').split("\n").collect{|f| Feature.new(:uri => f)}
end

#closeObject

Tell the dataset that it is complete



133
134
135
136
# File 'lib/opentox-ruby-api-wrapper.rb', line 133

def close
  puts @uri + '/finished'
  RestClient.put @uri + '/finished', nil
end

#compoundsObject

Get all compounds from a dataset



108
109
110
# File 'lib/opentox-ruby-api-wrapper.rb', line 108

def compounds
  RestClient.get(@uri + '/compounds').split("\n").collect{ |c| Compound.new(:uri => c) }
end

#features(compound) ⇒ Object

Get all features for a compound



123
124
125
# File 'lib/opentox-ruby-api-wrapper.rb', line 123

def features(compound)
  RestClient.get(@uri + '/compound/' + uri_escape(compound.uri) + '/features').split("\n").collect{|f| Feature.new(:uri => f) }
end