summaryrefslogtreecommitdiff
path: root/lib/algorithm.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-06-19 16:29:43 +0200
committerChristoph Helma <helma@in-silico.ch>2013-06-19 16:29:43 +0200
commitbc9d5b9266e18d39ab5fd83db272bffde98c4161 (patch)
treee30a2a96d77b2f010c8b10316b2163d112613355 /lib/algorithm.rb
parent4dba36635f5d214c4453d2d0d67426d6f14f5b6b (diff)
openbabel requirement removed. initial descriptor classes.
Diffstat (limited to 'lib/algorithm.rb')
-rw-r--r--lib/algorithm.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 8576681..1ffc883 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -5,11 +5,38 @@ module OpenTox
# Execute algorithm with parameters, please consult the OpenTox API and the webservice documentation for acceptable parameters
# @param [optional,Hash] params Algorithm parameters
- # @param [optional,Boolean] wait set to true if method should wait for task result
+ # @param [optional,Boolean] wait set to false if method should return a task uri instead of the algorithm result
# @return [String] URI of new resource (dataset, model, ...)
def run params=nil, wait=true
uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid}
wait_for_task uri if wait
end
end
+
+ module Descriptor
+
+ class Smarts
+
+ 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
+
+
+ end
end