Skip to content

Commit

Permalink
Better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amaunz committed May 7, 2012
1 parent dcd8379 commit 615b105
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions fminer.rb
Expand Up @@ -307,7 +307,7 @@
# 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
Expand All @@ -324,7 +324,7 @@

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 => [
Expand All @@ -335,13 +335,12 @@
})
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

Expand All @@ -362,24 +361,28 @@
@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 = {
Expand Down

0 comments on commit 615b105

Please sign in to comment.