Module: MiGA::Dataset::Result
Overview
Helper module including specific functions to add dataset results.
Instance Method Summary collapse
-
#add_result(result_type, save = true, opts = {}) ⇒ Object
Look for the result with symbol key
result_type
and register it in the dataset. -
#cleanup_distances! ⇒ Object
Clean-up all the stored distances, removing values for datasets no longer in the project as reference datasets.
-
#done_preprocessing?(save = false) ⇒ Boolean
Are all the dataset-specific tasks done? Passes
save
to #add_result. -
#each_result(&blk) ⇒ Object
For each result executes the 2-ary
blk
block: key symbol and MiGA::Result. -
#first_preprocessing(save = false) ⇒ Object
Returns the key symbol of the first registered result (sorted by the execution order).
-
#get_result(result_type) ⇒ Object
Gets a result as MiGA::Result for the datasets with
result_type
. -
#next_preprocessing(save = false) ⇒ Object
Returns the key symbol of the next task that needs to be executed.
-
#profile_advance(save = false) ⇒ Object
Returns an array indicating the stage of each task (sorted by execution order).
-
#result(k) ⇒ Object
Get the result MiGA::Result in this dataset identified by the symbol
k
. -
#results ⇒ Object
Get all the results (Array of MiGA::Result) in this dataset.
Instance Method Details
#add_result(result_type, save = true, opts = {}) ⇒ Object
Look for the result with symbol key result_type
and register it in the dataset. If save
is false, it doesn’t register the result, but it still returns a result if the expected files are complete. The opts
hash controls result creation (if necessary). Supported values include:
-
is_clean
: A Boolean indicating if the input files are clean. -
force
: A Boolean indicating if the result must be re-indexed. If true, it implies save=true.
Returns MiGA::Result or nil.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/miga/dataset/result.rb', line 41 def add_result(result_type, save=true, opts={}) dir = @@RESULT_DIRS[result_type] return nil if dir.nil? base = File.("data/#{dir}/#{name}", project.path) if opts[:force] FileUtils.rm("#{base}.json") if File.exist?("#{base}.json") else r_pre = MiGA::Result.load("#{base}.json") return r_pre if (r_pre.nil? and not save) or not r_pre.nil? end r = File.exist?("#{base}.done") ? self.send("add_result_#{result_type}", base, opts) : nil r.save unless r.nil? r end |
#cleanup_distances! ⇒ Object
Clean-up all the stored distances, removing values for datasets no longer in the project as reference datasets.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/miga/dataset/result.rb', line 117 def cleanup_distances! r = get_result(:distances) return if r.nil? [:haai_db, :aai_db, :ani_db].each do |db_type| db = r.file_path(db_type) next if db.nil? or not File.size? db sqlite_db = SQLite3::Database.new db table = db_type[-6..-4] val = sqlite_db.execute "select seq2 from #{table}" next if val.empty? (val.map{ |i| i.first } - project.dataset_names).each do |extra| sqlite_db.execute "delete from #{table} where seq2=?", extra end end end |
#done_preprocessing?(save = false) ⇒ Boolean
Are all the dataset-specific tasks done? Passes save
to #add_result.
89 90 91 |
# File 'lib/miga/dataset/result.rb', line 89 def done_preprocessing?(save=false) !first_preprocessing(save).nil? and next_preprocessing(save).nil? end |
#each_result(&blk) ⇒ Object
For each result executes the 2-ary blk
block: key symbol and MiGA::Result.
26 27 28 29 30 |
# File 'lib/miga/dataset/result.rb', line 26 def each_result(&blk) @@RESULT_DIRS.keys.each do |k| blk.call(k, result(k)) unless result(k).nil? end end |
#first_preprocessing(save = false) ⇒ Object
Returns the key symbol of the first registered result (sorted by the execution order). This typically corresponds to the result used as the initial input. Passes save
to #add_result.
66 67 68 69 70 |
# File 'lib/miga/dataset/result.rb', line 66 def first_preprocessing(save=false) @@PREPROCESSING_TASKS.find do |t| not ignore_task?(t) and not add_result(t, save).nil? end end |
#get_result(result_type) ⇒ Object
Gets a result as MiGA::Result for the datasets with result_type
. This is equivalent to add_result(result_type, false).
60 |
# File 'lib/miga/dataset/result.rb', line 60 def get_result(result_type) ; add_result(result_type, false) ; end |
#next_preprocessing(save = false) ⇒ Object
Returns the key symbol of the next task that needs to be executed. Passes save
to #add_result.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/miga/dataset/result.rb', line 75 def next_preprocessing(save=false) after_first = false first = first_preprocessing(save) return nil if first.nil? @@PREPROCESSING_TASKS.each do |t| next if ignore_task? t return t if after_first and add_result(t, save).nil? after_first = (after_first or (t==first)) end nil end |
#profile_advance(save = false) ⇒ Object
Returns an array indicating the stage of each task (sorted by execution order). The values are integers:
-
0 for an undefined result (a task before the initial input).
-
1 for a registered result (a completed task).
-
2 for a queued result (a task yet to be executed).
It passes save
to #add_result
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/miga/dataset/result.rb', line 100 def profile_advance(save=false) first_task = first_preprocessing(save) return Array.new(@@PREPROCESSING_TASKS.size, 0) if first_task.nil? adv = [] state = 0 next_task = next_preprocessing(save) @@PREPROCESSING_TASKS.each do |task| state = 1 if first_task==task state = 2 if !next_task.nil? and next_task==task adv << state end adv end |
#result(k) ⇒ Object
Get the result MiGA::Result in this dataset identified by the symbol k
.
14 15 16 17 18 |
# File 'lib/miga/dataset/result.rb', line 14 def result(k) return nil if @@RESULT_DIRS[k.to_sym].nil? MiGA::Result.load( "#{project.path}/data/#{@@RESULT_DIRS[k.to_sym]}/#{name}.json" ) end |
#results ⇒ Object
Get all the results (Array of MiGA::Result) in this dataset.
22 |
# File 'lib/miga/dataset/result.rb', line 22 def results ; @@RESULT_DIRS.keys.map{ |k| result k }.compact ; end |