summaryrefslogtreecommitdiff
path: root/lib/compound.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compound.rb')
-rw-r--r--lib/compound.rb20
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 2a79fd6..049d77b 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -2,10 +2,8 @@ CACTUS_URI="http://cactus.nci.nih.gov/chemical/structure/"
module OpenTox
- class Compound
+ class Compound < Substance
require_relative "unique_descriptors.rb"
- include OpenTox
-
DEFAULT_FINGERPRINT = "MP2D"
field :inchi, type: String
@@ -19,9 +17,6 @@ module OpenTox
field :sdf_id, type: BSON::ObjectId
field :fingerprints, type: Hash, default: {}
field :default_fingerprint_size, type: Integer
- field :physchem_descriptors, type: Hash, default: {}
- field :dataset_ids, type: Array, default: []
- field :features, type: Hash, default: {}
index({smiles: 1}, {unique: true})
@@ -293,8 +288,7 @@ module OpenTox
training_dataset.compounds.each do |compound|
candidate_fingerprint = compound.fingerprint params[:type]
sim = (query_fingerprint & candidate_fingerprint).size/(query_fingerprint | candidate_fingerprint).size.to_f
- feature_values = training_dataset.values(compound,prediction_feature)
- neighbors << {"_id" => compound.id, "features" => {prediction_feature.id.to_s => feature_values}, "tanimoto" => sim} if sim >= params[:min_sim]
+ neighbors << {"_id" => compound.id, "toxicities" => {prediction_feature.id.to_s => compound.toxicities[prediction_feature.id.to_s]}, "tanimoto" => sim} if sim >= params[:min_sim]
end
neighbors.sort!{|a,b| b["tanimoto"] <=> a["tanimoto"]}
end
@@ -335,25 +329,25 @@ module OpenTox
'in' => {'$divide' => ['$$common', {'$subtract' => [{'$add' => [default_fingerprint_size, '$default_fingerprint_size']}, '$$common']}]}
}},
'_id' => 1,
- 'features' => 1,
+ 'toxicities' => 1,
'dataset_ids' => 1
}},
{'$match' => {'tanimoto' => {'$gte' => params[:min_sim]}}},
{'$sort' => {'tanimoto' => -1}}
]
- $mongo["compounds"].aggregate(aggregate).select{|r| r["dataset_ids"].include? params[:training_dataset_id]}
+ $mongo["substances"].aggregate(aggregate).select{|r| r["dataset_ids"].include? params[:training_dataset_id]}
end
- # Convert mg to mmol
+ # Convert mmol to mg
# @return [Float] value in mg
def mmol_to_mg mmol
mmol.to_f*molecular_weight
end
- # Convert mmol to mg
- # @return [Float] value in mg
+ # Convert mg to mmol
+ # @return [Float] value in mmol
def mg_to_mmol mg
mg.to_f/molecular_weight
end