summaryrefslogtreecommitdiff
path: root/lib/compound.rb
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2012-09-06 16:59:57 +0200
committerAndreas Maunz <andreas@maunz.de>2012-09-06 16:59:57 +0200
commit781e7f714130dcd054d5d437f9c9f95c02cf9f7f (patch)
tree4dccd1c7d3501702bf47b58d9126e1ebfbec4eb9 /lib/compound.rb
parent607be1ffb0a001e4a2bf9cae2babd44b4d898d25 (diff)
Added match routines
Diffstat (limited to 'lib/compound.rb')
-rw-r--r--lib/compound.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 127a6ee..19d00fb 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -186,5 +186,44 @@ module OpenTox
end
end
=end
+
+ # Match an array of smarts strings, returns array with matching smarts
+ # @example
+ # compound = Compound.from_name("Benzene")
+ # compound.match(['cc','cN']) # returns ['cc']
+ # @param [Array] smarts_array Array with Smarts strings
+ # @return [Array] Array with matching Smarts strings
+ def match(smarts_array)
+ obconversion = OpenBabel::OBConversion.new
+ obmol = OpenBabel::OBMol.new
+ obconversion.set_in_format('inchi')
+ obconversion.read_string(obmol,inchi)
+ smarts_pattern = OpenBabel::OBSmartsPattern.new
+ smarts_array.collect { |smarts|
+ smarts_pattern.init(smarts)
+ smarts if smarts_pattern.match(obmol)
+ }.compact
+ end
+
+ # Match an array of smarts strings, returns hash with matching smarts as key and number of non-unique hits as value
+ # @param [Array] smarts_array Array with Smarts strings
+ # @return [Hash] Hash with matching smarts as key and number of non-unique hits as value
+ def match_hits(smarts_array)
+ obconversion = OpenBabel::OBConversion.new
+ obmol = OpenBabel::OBMol.new
+ obconversion.set_in_format('inchi')
+ obconversion.read_string(obmol,inchi)
+ smarts_pattern = OpenBabel::OBSmartsPattern.new
+ smarts_hits = {}
+ smarts_array.collect do |smarts|
+ smarts_pattern.init(smarts)
+ if smarts_pattern.match(obmol)
+ hits = smarts_pattern.get_map_list
+ smarts_hits[smarts] = hits.to_a.size
+ end
+ end
+ return smarts_hits
+ end
+
end
end