diff options
author | Christoph Helma <helma@in-silico.ch> | 2011-07-28 12:14:33 +0000 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2011-07-28 12:14:33 +0000 |
commit | 328ca6fbe2ba51ca1d555b56d63ab196a71e40cd (patch) | |
tree | 6d314172e3f828621e7daf7285ad74228c90f829 | |
parent | 9bc59a8715e5b12bb989ba3ed2856630f0436b2b (diff) | |
parent | 1dcc4402c15001a89b10e1e8bbdc4ab6b0a30a4b (diff) |
Merge branch 'development' into feature/sdf-import
-rw-r--r-- | lib/algorithm.rb | 45 | ||||
-rw-r--r-- | lib/dataset.rb | 12 | ||||
-rw-r--r-- | lib/model.rb | 2 |
3 files changed, 18 insertions, 41 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 5093c34..a0ad9a5 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -383,7 +383,7 @@ module OpenTox gram_matrix = [] # square matrix of similarities between neighbors; implements weighted tanimoto kernel prediction = nil - if acts.to_scale.variance_population == 0 + if Algorithm::zero_variance? acts prediction = acts[0] else # gram matrix @@ -467,7 +467,7 @@ module OpenTox q_prop = props[1] # is an Array. prediction = nil - if acts.to_scale.variance_population == 0 + if Algorithm::zero_variance? acts prediction = acts[0] else #LOGGER.debug gram_matrix.to_yaml @@ -517,11 +517,11 @@ module OpenTox # @return[Float] Confidence def self.get_confidence(params) if params[:conf_stdev] - sim_median = Algorithm.median(params[:sims]) + sim_median = params[:sims].to_scale.median if sim_median.nil? confidence = nil else - standard_deviation = params[:acts].std_dev + standard_deviation = params[:acts].to_scale.standard_deviation_sample confidence = (sim_median*Math.exp(-1*standard_deviation)).abs if confidence.nan? confidence = nil @@ -818,23 +818,6 @@ module OpenTox return (array.to_scale.variance_sample == 0.0) end - # Median of an array - # @param [Array] Array with values - # @return [Float] Median - def self.median(array) - return nil if array.empty? - array.sort! - m_pos = array.size / 2 - return array.size % 2 == 1 ? array[m_pos] : (array[m_pos-1] + array[m_pos])/2 - end - - # Sum of an array for Numeric values - # @param [Array] Array with values - # @return [Integer] Sum of values - def self.sum(array) - array.inject{|s,x| s + x } - end - # Sum of an array for Arrays. # @param [Array] Array with values # @return [Integer] Sum of size of values @@ -860,7 +843,7 @@ module OpenTox max=0 max_value=0 nr_o = self.sum_size(occurrences) - nr_db = self.sum(db_instances) + nr_db = db_instances.to_scale.sum occurrences.each_with_index { |o,i| # fminer outputs occurrences sorted reverse by activity. actual = o.size.to_f/nr_o @@ -888,24 +871,6 @@ module OpenTox p_sum end - # Adds variance, mean and standard deviation calculation to Array class - module Variance - def sum(&blk) - map(&blk).inject { |sum, element| sum + element } - end - def mean - (sum.to_f / size.to_f) - end - def variance - m = mean - sum { |i| ( i - m )**2 } / (size-1).to_f - end - def std_dev - Math.sqrt(variance) - end - end - Array.send :include, Variance - end end diff --git a/lib/dataset.rb b/lib/dataset.rb index 5d5d13d..05335dd 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -240,8 +240,18 @@ module OpenTox # Get SDF representation of compounds # @return [String] SDF representation def to_sdf + sum="" + @compounds.each{ |c| + sum << OpenTox::Compound.new(c).to_inchi + sum << OpenTox::Compound.new(c).to_sdf + } + sum + end + + def to_urilist @compounds.inject { |sum, c| - sum + OpenTox::Compound.new(c).to_sdf + sum << OpenTox::Compound.new(c).uri + sum + "\n" } end diff --git a/lib/model.rb b/lib/model.rb index 0f1cc22..1ff9df1 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -239,6 +239,8 @@ module OpenTox @prediction_dataset.add @compound.uri, value_feature_uri, prediction[:prediction] end @prediction_dataset.add @compound.uri, confidence_feature_uri, prediction[:confidence] + @prediction_dataset.features[value_feature_uri][DC.title] = @prediction_dataset.metadata[DC.title] + @prediction_dataset.features[confidence_feature_uri][DC.title] = "Confidence" if verbose if @feature_calculation_algorithm == "Substructure.match" |