From 8c6c59980bc82dc2177147f2fe34adf8bfbc1539 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 24 Aug 2015 12:17:07 +0200 Subject: Model::Prediction with tests, initial indexes --- lib/compound.rb | 2 ++ lib/crossvalidation.rb | 1 + lib/feature.rb | 1 + lib/lazar.rb | 7 +++---- lib/model.rb | 13 +++++++++++-- 5 files changed, 18 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/compound.rb b/lib/compound.rb index c0d6536..fa57aff 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -22,6 +22,8 @@ module OpenTox field :fp4, type: Array field :fp4_size, type: Integer + index({smiles: 1}, {unique: true}) + # Overwrites standard Mongoid method to create fingerprints before database insertion def self.find_or_create_by params compound = self.find_or_initialize_by params diff --git a/lib/crossvalidation.rb b/lib/crossvalidation.rb index d0ad324..5af75bf 100644 --- a/lib/crossvalidation.rb +++ b/lib/crossvalidation.rb @@ -8,6 +8,7 @@ module OpenTox field :nr_unpredicted, type: Integer field :predictions, type: Array field :finished_at, type: Time + #belongs_to :prediction def time finished_at - created_at diff --git a/lib/feature.rb b/lib/feature.rb index b2bc1f5..22b2846 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -29,6 +29,7 @@ module OpenTox # Feature for SMARTS fragments class Smarts < NominalFeature field :smarts, type: String + index "smarts" => 1 def self.from_smarts smarts self.find_or_create_by :smarts => smarts end diff --git a/lib/lazar.rb b/lib/lazar.rb index 174fb2c..d0128b7 100644 --- a/lib/lazar.rb +++ b/lib/lazar.rb @@ -15,20 +15,19 @@ require "base64" ENV["MONGOID_ENV"] ||= "development" # TODO remove config files, change default via ENV or directly in Mongoid class Mongoid.load!("#{File.expand_path(File.join(File.dirname(__FILE__),'..','mongoid.yml'))}") -# TODO get Mongo::Client from Mongoid -$mongo = Mongo::Client.new('mongodb://127.0.0.1:27017/opentox') -# TODO same for GridFS +$mongo = Mongoid.default_client +#$mongo = Mongo::Client.new('mongodb://127.0.0.1:27017/opentox') $gridfs = $mongo.database.fs # R setup R = Rserve::Connection.new # Logger setup +STDOUT.sync = true # for redirection, etc see http://stackoverflow.com/questions/8549443/why-doesnt-logger-output-to-stdout-get-redirected-to-files $logger = Logger.new STDOUT # STDERR did not work on my development machine (CH) $logger.level = Logger::DEBUG Mongo::Logger.logger = $logger Mongo::Logger.level = Logger::WARN -#Mongoid.logger = $logger # Require sub-Repositories require_relative '../libfminer/libbbrc/bbrc' # include before openbabel diff --git a/lib/model.rb b/lib/model.rb index bf8c549..185d70f 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -19,6 +19,8 @@ module OpenTox # prediction feature field :prediction_feature_id, type: BSON::ObjectId + #belongs_to :prediction + attr_accessor :prediction_dataset attr_accessor :training_dataset @@ -156,11 +158,10 @@ module OpenTox end - class PredictionModel + class Prediction include OpenTox include Mongoid::Document include Mongoid::Timestamps - store_in collection: "models" # TODO field Validations field :endpoint, type: String @@ -169,6 +170,14 @@ module OpenTox field :unit, type: String field :model_id, type: BSON::ObjectId field :crossvalidation_id, type: BSON::ObjectId + + def predict object + Model::Lazar.find(model_id).predict object + end + + def crossvalidation + CrossValidation.find crossvalidation_id + end end end -- cgit v1.2.3