From 615b105230453e04bf6ec0354f2c391170e76974 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 7 May 2012 15:31:22 +0200 Subject: Better comments --- fminer.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fminer.rb b/fminer.rb index cec902e..ee7f8e9 100644 --- a/fminer.rb +++ b/fminer.rb @@ -307,7 +307,7 @@ post '/fminer/bbrc/sample/?' do # min_sampling_support unless params[:min_sampling_support] min_sampling_support = (num_boots * 0.3).ceil - LOGGER.debug "Set num_boots to default value #{min_sampling_support}" + LOGGER.debug "Set min_sampling_support to default value #{min_sampling_support}" else raise OpenTox::BadRequestError.new "min_sampling_support is not numeric" unless OpenTox::Algorithm.numeric? params[:min_sampling_support] min_sampling_support= params[:min_sampling_support].to_i.ceil @@ -324,7 +324,7 @@ post '/fminer/bbrc/sample/?' do feature_dataset = OpenTox::Dataset.new(nil, @subjectid) feature_dataset.add_metadata({ - DC.title => "BBRC sampled representatives for " + fminer.training_dataset.metadata[DC.title].to_s, + DC.title => "BBRC representatives for " + fminer.training_dataset.metadata[DC.title].to_s + "(bootstrapped)", DC.creator => url_for('/fminer/bbrc/sample',:full), OT.hasSource => url_for('/fminer/bbrc/sample', :full), OT.parameters => [ @@ -335,13 +335,12 @@ post '/fminer/bbrc/sample/?' do }) feature_dataset.save(@subjectid) - fminer.compounds = [] - fminer.db_class_sizes = Array.new # AM: effect - fminer.all_activities = Hash.new # DV: for effect calculation (class and regr) - fminer.smi = [] # AM LAST: needed for matching the patterns back - - # Add data to fminer - fminer.add_fminer_data(nil, @value_map) # AM: 'nil' as instance to only fill in administrative data + # filled by add_fminer_data: + fminer.compounds = [] # indexed by id, starting from 1 (not 0) + fminer.db_class_sizes = Array.new # for effect calculation + fminer.all_activities = Hash.new # for effect calculation, indexed by id, starting from 1 (not 0) + fminer.smi = [] # needed for matching the patterns back, indexed by id, starting from 1 (not 0) + fminer.add_fminer_data(nil, @value_map) # To only fill in administrative data (no fminer priming) pass 'nil' as instance raise "No compounds in dataset #{fminer.training_dataset.uri}" if fminer.compounds.size==0 @@ -362,24 +361,28 @@ post '/fminer/bbrc/sample/?' do @r.eval "source(\"bbrc-sample/bbrc-sample.R\")" @r.eval "bootBbrc(dataset.uri, prediction.feature.uri, num.boots, min.frequency.per.sample, min.sampling.support, NULL, bbrc.service, dataset.service, F)" - smarts = (@r.pull "ans.patterns").collect! { |id| id.gsub(/\'/,"") } # remove extra quotes + smarts = (@r.pull "ans.patterns").collect! { |id| id.gsub(/\'/,"") } # remove extra quotes around smarts r_p_values = @r.pull "ans.p.values" # matching task.progress 90 lu = LU.new # AM LAST: uses last-utils here params[:nr_hits] == "true" ? hit_count=true: hit_count=false + + + LOGGER.debug fminer.smi.to_yaml + LOGGER.debug smarts.to_yaml matches, counts = lu.match_rb(fminer.smi,smarts,hit_count) # AM LAST: creates instantiations matches.each do |smarts, ids| feat_hash = Hash[*(fminer.all_activities.select { |k,v| ids.include?(k) }.flatten)] # AM LAST: get activities of feature occurrences; see http://www.softiesonrails.com/2007/9/18/ruby-201-weird-hash-syntax p_value = @@last.ChisqTest(fminer.all_activities.values, feat_hash.values).to_f - g=Array.new + g = Array.new @value_map.each { |y,act| g[y-1]=Array.new } feat_hash.each { |x,y| g[y-1].push(x) } max = OpenTox::Algorithm.effect(g, fminer.db_class_sizes) effect = g.size-max - feature_uri = File.join feature_dataset.uri,"feature","last", features.size.to_s + feature_uri = File.join feature_dataset.uri,"feature","bbrc", features.size.to_s unless features.include? smarts features << smarts metadata = { -- cgit v1.2.3 From b0f3f05d6a8df53956547d04a6a82316ee78b102 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Tue, 8 May 2012 08:18:04 +0200 Subject: Removed debug --- bbrc-sample | 2 +- fminer.rb | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bbrc-sample b/bbrc-sample index fc4ae7d..813595b 160000 --- a/bbrc-sample +++ b/bbrc-sample @@ -1 +1 @@ -Subproject commit fc4ae7d22a60838a62747069660542c304ce2f12 +Subproject commit 813595bc811e1fdb71dee0ea9e2f0dc9b6a44cdc diff --git a/fminer.rb b/fminer.rb index ee7f8e9..abedc36 100644 --- a/fminer.rb +++ b/fminer.rb @@ -359,7 +359,7 @@ post '/fminer/bbrc/sample/?' do @r.assign "dataset.service", CONFIG[:services]["opentox-dataset"] @r.eval "source(\"bbrc-sample/bbrc-sample.R\")" - @r.eval "bootBbrc(dataset.uri, prediction.feature.uri, num.boots, min.frequency.per.sample, min.sampling.support, NULL, bbrc.service, dataset.service, F)" + @r.eval "bootBbrc(dataset.uri, prediction.feature.uri, num.boots, min.frequency.per.sample, min.sampling.support, NULL, bbrc.service, dataset.service, T)" smarts = (@r.pull "ans.patterns").collect! { |id| id.gsub(/\'/,"") } # remove extra quotes around smarts r_p_values = @r.pull "ans.p.values" @@ -369,9 +369,6 @@ post '/fminer/bbrc/sample/?' do lu = LU.new # AM LAST: uses last-utils here params[:nr_hits] == "true" ? hit_count=true: hit_count=false - - LOGGER.debug fminer.smi.to_yaml - LOGGER.debug smarts.to_yaml matches, counts = lu.match_rb(fminer.smi,smarts,hit_count) # AM LAST: creates instantiations matches.each do |smarts, ids| -- cgit v1.2.3 From a00bf34d6dbd079f2437bac19299def05dc6321c Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Tue, 8 May 2012 08:28:28 +0200 Subject: Fixed r quit --- fminer.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fminer.rb b/fminer.rb index abedc36..d38703a 100644 --- a/fminer.rb +++ b/fminer.rb @@ -348,7 +348,6 @@ post '/fminer/bbrc/sample/?' do # run bbrc-sample, obtain smarts and p-values features = Set.new task.progress 10 - @r = RinRuby.new(true,false) # global R instance leads to Socket errors after a large number of requests @r.assign "dataset.uri", params[:dataset_uri] @r.assign "prediction.feature.uri", fminer.prediction_feature.uri @@ -357,20 +356,22 @@ post '/fminer/bbrc/sample/?' do @r.assign "min.sampling.support", min_sampling_support @r.assign "bbrc.service", File.join(CONFIG[:services]["opentox-algorithm"], "fminer/bbrc") @r.assign "dataset.service", CONFIG[:services]["opentox-dataset"] - @r.eval "source(\"bbrc-sample/bbrc-sample.R\")" - @r.eval "bootBbrc(dataset.uri, prediction.feature.uri, num.boots, min.frequency.per.sample, min.sampling.support, NULL, bbrc.service, dataset.service, T)" - - smarts = (@r.pull "ans.patterns").collect! { |id| id.gsub(/\'/,"") } # remove extra quotes around smarts - r_p_values = @r.pull "ans.p.values" + begin + @r.eval "bootBbrc(dataset.uri, prediction.feature.uri, num.boots, min.frequency.per.sample, min.sampling.support, NULL, bbrc.service, dataset.service, T)" + smarts = (@r.pull "ans.patterns").collect! { |id| id.gsub(/\'/,"") } # remove extra quotes around smarts + r_p_values = @r.pull "ans.p.values" + rescue Exception => e + LOGGER.debug "#{e.class}: #{e.message}" + LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" + end + @r.quit # free R # matching task.progress 90 lu = LU.new # AM LAST: uses last-utils here params[:nr_hits] == "true" ? hit_count=true: hit_count=false - matches, counts = lu.match_rb(fminer.smi,smarts,hit_count) # AM LAST: creates instantiations - matches.each do |smarts, ids| feat_hash = Hash[*(fminer.all_activities.select { |k,v| ids.include?(k) }.flatten)] # AM LAST: get activities of feature occurrences; see http://www.softiesonrails.com/2007/9/18/ruby-201-weird-hash-syntax p_value = @@last.ChisqTest(fminer.all_activities.values, feat_hash.values).to_f -- cgit v1.2.3