module MiGA::Dataset::Result

Helper module including specific functions to add dataset results.

Public Instance Methods

add_result(result_type, save = true, opts = {}) click to toggle source

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.

# 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.expand_path("data/#{dir}/#{name}", project.path)
  if opts[:force]
    FileUtils.rm("#{base}.json") if File.exist?("#{base}.json")
    r_pre = MiGA::Result.load("#{base}.json")
    return r_pre if (r_pre.nil? and not save) or not r_pre.nil?
  r = File.exist?("#{base}.done") ?
      self.send("add_result_#{result_type}", base, opts) : nil unless r.nil?
cleanup_distances!() click to toggle source

Clean-up all the stored distances, removing values for datasets no longer in the project as reference datasets.

# File lib/miga/dataset/result.rb, line 123
def cleanup_distances!
  r = get_result(:distances)
  ref =
  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 = db
    table = db_type[-6..-4]
    val = sqlite_db.execute "select seq2 from #{table}"
    next if val.empty?
    ( - ref).each do |extra|
      sqlite_db.execute "delete from #{table} where seq2=?", extra
done_preprocessing?(save = false) click to toggle source

Are all the dataset-specific tasks done? Passes save to add_result.

# File lib/miga/dataset/result.rb, line 95
def done_preprocessing?(save = false)
  !first_preprocessing(save).nil? and next_preprocessing(save).nil?
each_result(&blk) click to toggle source

For each result executes the 2-ary blk block: key symbol and MiGA::Result.

# File lib/miga/dataset/result.rb, line 26
def each_result(&blk)
  @@RESULT_DIRS.keys.each do |k|, result(k)) unless result(k).nil?
first_preprocessing(save = false) click to toggle source

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.

# File lib/miga/dataset/result.rb, line 66
def first_preprocessing(save = false)
    not ignore_task?(t) and not add_result(t, save).nil?
get_result(result_type) click to toggle source

Gets a result as MiGA::Result for the datasets with result_type. This is equivalent to +add_result(result_type, false)+.

# File lib/miga/dataset/result.rb, line 60
def get_result(result_type) ; add_result(result_type, false) ; end
next_preprocessing(save = false) click to toggle source

Returns the key symbol of the next task that needs to be executed. Passes save to add_result.

# 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?
    next if ignore_task? t
    if after_first and add_result(t, save).nil?
      if (metadata["_try_#{t}"] || 0) > (project.metadata[:max_try] || 10)
        return nil
      return t
    after_first = (after_first or (t==first))
profile_advance(save = false) click to toggle source

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

# File lib/miga/dataset/result.rb, line 106
def profile_advance(save = false)
  first_task = first_preprocessing(save)
  return, 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
result(k) click to toggle source

Get the result MiGA::Result in this dataset identified by the symbol k.

# File lib/miga/dataset/result.rb, line 14
def result(k)
  return nil if @@RESULT_DIRS[k.to_sym].nil?
    "#{project.path}/data/#{@@RESULT_DIRS[k.to_sym]}/#{name}.json" )
results() click to toggle source

Get all the results (Array of MiGA::Result) in this dataset.

# File lib/miga/dataset/result.rb, line 22
def results ;{ |k| result k }.compact ; end