module MiGA::Dataset::Result

Helper module including specific functions to add dataset results

Public Instance Methods

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 140
def cleanup_distances!
  r = get_result(:distances)
  ref = project.datasets.select(&:is_ref?).select(&:is_active?).map(&:name)
  return if r.nil?
  %[haai_db aai_db ani_db].each do |db_type|
    db = r.file_path(db_type)
    next if db.nil? || !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(&:first) - ref).each do |extra|
      sqlite_db.execute "delete from #{table} where seq2=?", extra
    end
  end
end
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 84
def done_preprocessing?(save = false)
  !first_preprocessing(save).nil? && next_preprocessing(save).nil?
end
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 57
def first_preprocessing(save = false)
  @first_processing ||= @@PREPROCESSING_TASKS.find do |t|
    !ignore_task?(t) && !add_result(t, save).nil?
  end
end
ignore_task?(task) click to toggle source

Should I ignore task for this dataset?

# File lib/miga/dataset/result.rb, line 20
def ignore_task?(task)
  why_ignore(task) != :execute
end
next_preprocessing(save = false) click to toggle source

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

# File lib/miga/dataset/result.rb, line 66
def next_preprocessing(save = false)
  first = first_preprocessing(save) or return nil
  @@PREPROCESSING_TASKS[@@PREPROCESSING_TASKS.index(first) .. -1].find do |t|
    if ignore_task? t
      false
    elsif add_result(t, save).nil?
      if (metadata["_try_#{t}"] || 0) > (project.metadata[:max_try] || 10)
        inactivate!
        false
      else
        true
      end
    end
  end
end
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 95
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? && next_task == task
    adv << state
  end
  adv
end
result_base() click to toggle source

Return the basename for results

# File lib/miga/dataset/result.rb, line 14
def result_base
  name
end
result_status(task) click to toggle source

Returns the status of task. The status values are symbols:

  • -: the task is upstream from the initial input

  • ignore_*: the task is to be ignored, see codes in why_ignore

  • complete: a task with registered results

  • pending: a task queued to be performed

# File lib/miga/dataset/result.rb, line 122
def result_status(task)
  if first_preprocessing.nil?
    :ignore_empty
  elsif !get_result(task).nil?
    :complete
  elsif @@PREPROCESSING_TASKS.index(task) <
        @@PREPROCESSING_TASKS.index(first_preprocessing)
    :-
  elsif ignore_task?(task)
    :"ignore_#{why_ignore task}"
  else
    :pending
  end
end
results_status() click to toggle source

Returns a Hash with tasks as key and status as value. See result_status for possible values

# File lib/miga/dataset/result.rb, line 112
def results_status
  Hash[@@PREPROCESSING_TASKS.map { |task| [task, result_status(task)] }]
end
why_ignore(task) click to toggle source

Return a code explaining why a task is ignored. The values are symbols:

  • empty: the dataset has no data

  • inactive: the dataset is inactive

  • force: forced to ignore by metadata

  • project: incompatible project

  • noref: incompatible dataset, only for reference

  • multi: incompatible dataset, only for multi

  • nonmulti: incompatible dataset, only for nonmulti

  • execute: do not ignore, execute the task

# File lib/miga/dataset/result.rb, line 35
def why_ignore(task)
  if !is_active?
    :inactive
  elsif !metadata["run_#{task}"].nil?
    metadata["run_#{task}"] ? :execute : :force
  elsif task == :taxonomy && project.metadata[:ref_project].nil?
    :project
  elsif @@_EXCLUDE_NOREF_TASKS_H[task] && !is_ref?
    :noref
  elsif @@_ONLY_MULTI_TASKS_H[task] && !is_multi?
    :multi
  elsif @@_ONLY_NONMULTI_TASKS_H[task] && !is_nonmulti?
    :nonmulti
  else
    :execute
  end
end