From 6c35e3f8369ba96cb251eac487424bd949fdcf6c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 2 Jul 2013 19:23:01 +0200 Subject: Algorithms and Models are modules instead of classes. --- lib/algorithm.rb | 57 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'lib/algorithm.rb') diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 1ffc883..7d9a5a2 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -1,7 +1,8 @@ module OpenTox # Wrapper for OpenTox Algorithms - class Algorithm + module Algorithm + include OpenTox # Execute algorithm with parameters, please consult the OpenTox API and the webservice documentation for acceptable parameters # @param [optional,Hash] params Algorithm parameters @@ -11,32 +12,50 @@ module OpenTox uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid} wait_for_task uri if wait end - end - module Descriptor + class Generic + include OpenTox + include Algorithm + end - class Smarts + class Descriptor + include OpenTox + include Algorithm + + [:smarts_match,:smarts_count,:openbabel,:cdk,:joelib,:physchem,:lookup].each do |descriptor| + Descriptor.define_singleton_method(descriptor) do |compounds,descriptors| + descriptors = [descriptors] unless descriptors.is_a? Array + case compounds.class.to_s + when "Array" + klasses = compounds.collect{|c| c.class}.uniq + bad_request_error "First argument contains objects with a different class than OpenTox::Compound or OpenTox::Dataset #{klasses.inspect}" unless klasses.size == 1 and klasses.first == Compound + JSON.parse(Descriptor.new(File.join(self.service_uri, "descriptor", descriptor.to_s), SUBJECTID).run(:compound_uri => compounds.collect{|c| c.uri}, :descriptors => descriptors)) + when "OpenTox::Compound" + JSON.parse(Descriptor.new(File.join(self.service_uri, "descriptor", descriptor.to_s), SUBJECTID).run(:compound_uri => compounds.uri, :descriptors => descriptors)) + when "OpenTox::Dataset" + task_uri = Descriptor.new(File.join(self.service_uri, "descriptor", descriptor.to_s), SUBJECTID).run(:dataset_uri => compounds.uri, :descriptors => descriptors) + puts task_uri + #task_uri + Dataset.new(Task.new(task_uri).wait_for_task) + else + bad_request_error "First argument contains objects with a different class than OpenTox::Compound or OpenTox::Dataset" + end - def self.fingerprint compounds, smarts, count=false - matcher = Algorithm.new File.join($algorithm[:uri],"descriptor","smarts","fingerprint") - smarts = [smarts] unless smarts.is_a? Array - if compounds.is_a? OpenTox::Compound - json = matcher.run :compound_uri => compounds.uri, :smarts => smarts, :count => count - elsif compounds.is_a? OpenTox::Dataset - # TODO: add task and return dataset instead of result - json = matcher.run :dataset_uri => compounds.uri, :smarts => smarts, :count => count - else - bad_request_error "Cannot match smarts on #{compounds.class} objects." end - - JSON.parse json end - def self.count compounds, smarts - fingerprint compounds,smarts,true - end end + class Fminer + include OpenTox + include Algorithm + def self.bbrc params + Fminer.new(File.join(service_uri, "fminer", "bbrc")).run params + end + def self.last params + Fminer.new(File.join(service_uri, "fminer", "last")).run params + end + end end end -- cgit v1.2.3