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

#uri_escape

Constructor Details

#initialize(params) ⇒ Dataset

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



87
88
89
90
91
92
93
# File 'lib/opentox-ruby-api-wrapper.rb', line 87

def initialize(params)
	if params[:uri]
		@uri = params[:uri].to_s
	elsif params[:name] 
		@uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name]
	end
end

Instance Method Details

#add(compound, feature) ⇒ Object

Add a compound and a feature to a dataset



121
122
123
# File 'lib/opentox-ruby-api-wrapper.rb', line 121

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

#all_compounds_and_featuresObject

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



106
107
108
# File 'lib/opentox-ruby-api-wrapper.rb', line 106

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

#all_featuresObject

Get all features from a dataset



111
112
113
# File 'lib/opentox-ruby-api-wrapper.rb', line 111

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

#compoundsObject

Get all compounds from a dataset



101
102
103
# File 'lib/opentox-ruby-api-wrapper.rb', line 101

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

#features(compound) ⇒ Object

Get all features for a compound



116
117
118
# File 'lib/opentox-ruby-api-wrapper.rb', line 116

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

#nameObject

Get the dataset name



96
97
98
# File 'lib/opentox-ruby-api-wrapper.rb', line 96

def name
	RestClient.get @uri + '/name'
end