From d6eced29e104b9bc1923b2ac89b2700a48adf07a Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 8 Jan 2016 11:00:20 +0100 Subject: mg-mmol conversion fixed --- lib/compound.rb | 20 ++------------------ lib/crossvalidation.rb | 2 -- lib/dataset.rb | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/compound.rb b/lib/compound.rb index d5a4cbb..040fd6f 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -337,30 +337,15 @@ module OpenTox end - # Get mg from logmmol (for nch LOAEL/pTD50 data) - # @return [Float] value in mg - def logmmol_to_mg(value, mw) - mg = (10**(-1.0*value.to_f)*(mw.to_f*1000)) - return mg - end - # Get mg from mmol # @return [Float] value in mg - def mmol_to_mg(value, mw) - mg = (value.to_f)*(mw.to_f) - return mg + def mmol_to_mg mmol + mmol.to_f*molecular_weight end def mg_to_mmol mg mg.to_f/molecular_weight end - - # Get mg from logmg - # @return [Float] value in mg - def logmg_to_mg(value) - mg = 10**value.to_f - return mg - end # Calculate molecular weight of Compound with OB and store it in object # @return [Float] molecular weight @@ -371,7 +356,6 @@ module OpenTox self["molecular_weight"].to_f end - private def self.obconversion(identifier,input_format,output_format,option=nil) diff --git a/lib/crossvalidation.rb b/lib/crossvalidation.rb index 3127351..9b5c4e2 100644 --- a/lib/crossvalidation.rb +++ b/lib/crossvalidation.rb @@ -175,8 +175,6 @@ module OpenTox weighted_rse = 0 mae = 0 weighted_mae = 0 - rae = 0 - weighted_rae = 0 confidence_sum = 0 predictions.each do |pred| compound_id,activity,prediction,confidence = pred diff --git a/lib/dataset.rb b/lib/dataset.rb index 366c79f..55cde63 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -126,6 +126,17 @@ module OpenTox end # Diagnostics + + def duplicates feature=self.features.first + col = feature_ids.index feature.id + dups = {} + compound_ids.each_with_index do |cid,i| + rows = compound_ids.each_index.select{|r| compound_ids[r] == cid } + values = rows.collect{|row| data_entries[row][col]} + dups[cid] = values if values.size > 1 + end + dups + end def correlation_plot training_dataset # TODO: create/store svg @@ -162,10 +173,10 @@ module OpenTox # TODO #def self.from_sdf_file #end - + # Create a dataset from CSV file # TODO: document structure - def self.from_csv_file file, source=nil, bioassay=true + def self.from_csv_file file, source=nil, bioassay=true#, layout={} source ||= file name = File.basename(file,".*") dataset = self.find_by(:source => source, :name => name) @@ -175,7 +186,7 @@ module OpenTox $logger.debug "Parsing #{file}." table = CSV.read file, :skip_blanks => true, :encoding => 'windows-1251:utf-8' dataset = self.new(:source => source, :name => name) - dataset.parse_table table, bioassay + dataset.parse_table table, bioassay#, layout end dataset end -- cgit v1.2.3