summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-07-04 18:17:56 +0200
committerChristoph Helma <helma@in-silico.ch>2013-07-04 18:17:56 +0200
commit3262e3cf2ed1ce896dcd11d9c1bde5222ea720ce (patch)
tree1a38a08f585885d33c4540b525e7daf7247a302a
parent14f55a3bfc2b980115c2f3fadd703fd3de4c3445 (diff)
Algorithm::Generic and Model::Generic classes.
-rw-r--r--lib/compound.rb139
-rw-r--r--lib/model.rb2
2 files changed, 2 insertions, 139 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 9bd2066..82f0d73 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -112,144 +112,5 @@ module OpenTox
uri = "http://www.ebi.ac.uk/chemblws/compounds/smiles/#{smiles}.json"
@chemblid = JSON.parse(RestClientWrapper.get(uri))["compounds"].first["chemblId"]
end
-
-=begin
- # Match a smarts string
- # @example
- # compound = OpenTox::Compound.from_name("Benzene")
- # compound.match?("cN") # returns false
- # @param [String] smarts Smarts string
- def match?(smarts)
- matcher = Algorithm.new File.join($algorithm[:uri],"descriptor","smarts")
- matcher.run :compound_uri => @uri, :smarts => smarts, :count => false
- end
-
- # Match an array of smarts strings, returns array with matching smarts
- # @example
- # compound = OpenTox::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)
- matcher = Algorithm.new File.join($algorithm[:uri],"descriptor","smarts")
- matcher.run :compound_uri => @uri, :smarts => smarts_array, :count => false
- end
-
- # Match a smarts string
- # @example
- # compound = OpenTox::Compound.from_name("Benzene")
- # compound.match?("cN") # returns false
- # @param [String] smarts Smarts string
- def match?(smarts)
- obconversion = OpenBabel::OBConversion.new
- obmol = OpenBabel::OBMol.new
- obconversion.set_in_format('inchi')
- obconversion.read_string(obmol,@inchi)
- smarts_pattern = OpenBabel::OBSmartsPattern.new
- smarts_pattern.init(smarts)
- smarts_pattern.match(obmol)
- end
-
- # Match an array of smarts strings, returns array with matching smarts
- # @example
- # compound = OpenTox::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)
- # avoid recreation of OpenBabel objects
- 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 do |smarts|
- smarts_pattern.init(smarts)
- smarts if smarts_pattern.match(obmol)
- end.compact
- #smarts_array.collect { |s| s if match?(s)}.compact
- end
-
- # Get URI of compound image with highlighted fragments
- #
- # @param [Array] activating Array with activating Smarts strings
- # @param [Array] deactivating Array with deactivating Smarts strings
- # @return [String] URI for compound image with highlighted fragments
- def matching_smarts_image_uri(activating, deactivating)
- activating_smarts = URI.encode "\"#{activating.join("\"/\"")}\""
- deactivating_smarts = URI.encode "\"#{deactivating.join("\"/\"")}\""
- File.join @uri, "smarts/activating", URI.encode(activating_smarts),"deactivating", URI.encode(deactivating_smarts)
- end
-
-
- private
-
- # Convert sdf to inchi
- def self.sdf2inchi(sdf)
- Compound.obconversion(sdf,'sdf','inchi')
- end
-
- # Convert smiles to inchi
- def self.smiles2inchi(smiles)
- Compound.obconversion(smiles,'smi','inchi')
- end
-
- # Convert smiles to canonical smiles
- def self.smiles2cansmi(smiles)
- Compound.obconversion(smiles,'smi','can')
- end
-
- # Convert identifier from OpenBabel input_format to OpenBabel output_format
- def self.obconversion(identifier,input_format,output_format)
- obconversion = OpenBabel::OBConversion.new
- obmol = OpenBabel::OBMol.new
- obconversion.set_in_and_out_formats input_format, output_format
- obconversion.read_string obmol, identifier
- case output_format
- when /smi|can|inchi/
- obconversion.write_string(obmol).gsub(/\s/,'').chomp
- else
- obconversion.write_string(obmol)
- end
- end
-
-
-
- # Match an array of smarts strings, returns hash
- # Keys: matching smarts, values: number of non-unique hits, or 1
- # @param [Array] smarts_array Array with Smarts strings
- # @param use_hits [Boolean] Whether non-unique hits or 1 should be produced
- # @return [Hash] Hash with matching Smarts as keys, nr-of-hits/1 as values
- # @example
- # compound = Compound.from_name("Benzene")
- # compound.match(['cc','cN'],true) # returns { 'cc' => 12 }, 'cN' is not included because it does not match
- # compound.match(['cc','cN'],false) # returns { 'cc' => 1 }
- def match_hits(smarts_array, use_hits=true)
- 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)
- if use_hits
- hits = smarts_pattern.get_map_list
- smarts_hits[smarts] = hits.to_a.size
- else
- smarts_hits[smarts] = 1
- end
- end
- end
- smarts_hits
- end
-
- # Provided for backward compatibility
- def match(smarts_array)
- match_hits(smarts_array,false)
- end
-=end
-
end
end
diff --git a/lib/model.rb b/lib/model.rb
index 1dbac6d..c2914eb 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -45,11 +45,13 @@ module OpenTox
class Generic
include OpenTox
include OpenTox::Algorithm
+ include Model
end
class Lazar
include OpenTox
include OpenTox::Algorithm
+ include Model
def self.create params
Lazar.new(File.join($algorithm[:uri], "lazar")).run params
end