From b7cd3ebbb858a8891c35c45896f1bdd525f3534e Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 10 Aug 2015 13:26:06 +0200 Subject: algorithm libraries added, fminer tests pass --- lib/neighbor.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/neighbor.rb (limited to 'lib/neighbor.rb') diff --git a/lib/neighbor.rb b/lib/neighbor.rb new file mode 100644 index 0000000..a2c28d4 --- /dev/null +++ b/lib/neighbor.rb @@ -0,0 +1,25 @@ +module OpenTox + module Algorithm + class Neighbor + + def self.fingerprint_similarity compound, params={} + compound.neighbors params[:min_sim] + end + + def self.fminer_similarity compound, params + feature_dataset = Dataset.find params[:feature_dataset_id] + query_fingerprint = Algorithm::Descriptor.smarts_match(compound, feature_dataset.features.collect{|f| f.smarts} ) + neighbors = [] + + # find neighbors + feature_dataset.data_entries.each_with_index do |fingerprint, i| + sim = Algorithm::Similarity.tanimoto fingerprint, query_fingerprint + if sim > params[:min_sim] + neighbors << [feature_dataset.compound_ids[i],sim] # use compound_ids, instantiation of Compounds is too time consuming + end + end + neighbors + end + end + end +end -- cgit v1.2.3