class MiGA::Dataset

Dataset representation in MiGA

@package MiGA @license Artistic-2.0

Attributes

name[R]

Datasets are uniquely identified by name in a project

project[R]

MiGA::Project that contains the dataset

Public Class Methods

INFO_FIELDS() click to toggle source

Standard fields of metadata for datasets

# File lib/miga/dataset.rb, line 29
def INFO_FIELDS
  %w[name created updated type ref user description comments]
end
KNOWN_TYPES() click to toggle source
# File lib/miga/dataset/base.rb, line 11
def KNOWN_TYPES
  @@KNOWN_TYPES
end
PREPROCESSING_TASKS() click to toggle source
# File lib/miga/dataset/base.rb, line 15
def PREPROCESSING_TASKS
  @@PREPROCESSING_TASKS
end
RESULT_DIRS() click to toggle source
# File lib/miga/dataset/base.rb, line 7
def RESULT_DIRS
  @@RESULT_DIRS
end
exist?(project, name) click to toggle source

Does the project already have a dataset with that name?

# File lib/miga/dataset.rb, line 23
def exist?(project, name)
  !project.dataset_names_hash[name].nil?
end
new(project, name, is_ref = true, metadata = {}) click to toggle source

Create a MiGA::Dataset object in a project MiGA::Project with a uniquely identifying name. is_ref indicates if the dataset is to be treated as reference (true, default) or query (false). Pass any additional metadata as a Hash.

# File lib/miga/dataset.rb, line 49
def initialize(project, name, is_ref = true, metadata = {})
  name.miga_name? or
    raise 'Invalid name, please use only alphanumerics and underscores: ' +
          name.to_s
  @project, @name, @metadata = project, name, nil
  metadata[:ref] = is_ref
  @metadata_future = [
    File.join(project.path, 'metadata', "#{name}.json"),
    metadata
  ]
  return if File.exist? @metadata_future[0]

  save
  pull_hook :on_create
end

Public Instance Methods

activate!() click to toggle source

Activate a dataset. This removes the :inactive flag

# File lib/miga/dataset.rb, line 111
def activate!
  metadata[:inactive] = nil
  metadata[:warn] = nil if metadata[:warn] && metadata[:warn] =~ /^Inactive: /
  metadata.save
  pull_hook :on_activate
end
active?() click to toggle source

Is this dataset active?

# File lib/miga/dataset.rb, line 156
def active?
  metadata[:inactive].nil? or !metadata[:inactive]
end
Also aliased as: is_active?
closest_relatives(how_many = 1, ref_project = false) click to toggle source

Returns an Array of how_many duples (Arrays) sorted by AAI:

  • 0: A String with the name(s) of the reference dataset.

  • 1: A Float with the AAI.

This function is currently only supported for query datasets when ref_project is false (default), and only for reference dataset when ref_project is true. It returns nil if this analysis is not supported.

# File lib/miga/dataset.rb, line 187
def closest_relatives(how_many = 1, ref_project = false)
  return nil if (ref? != ref_project) || multi?

  r = result(ref_project ? :taxonomy : :distances)
  return nil if r.nil?

  db = SQLite3::Database.new(r.file_path(:aai_db))
  db.execute(
    'SELECT seq2, aai FROM aai WHERE seq2 != ? '        'GROUP BY seq2 ORDER BY aai DESC LIMIT ?', [name, how_many]
  )
end
inactivate!(reason = nil) click to toggle source

Inactivate a dataset. This halts automated processing by the daemon

If given, the reason string is saved as a metadata :warn entry

# File lib/miga/dataset.rb, line 102
def inactivate!(reason = nil)
  metadata[:warn] = "Inactive: #{reason}" unless reason.nil?
  metadata[:inactive] = true
  metadata.save
  pull_hook :on_inactivate
end
info() click to toggle source

Get standard metadata values for the dataset as Array

# File lib/miga/dataset.rb, line 120
def info
  MiGA::Dataset.INFO_FIELDS.map do |k|
    k == 'name' ? name : metadata[k]
  end
end
is_active?()

Same as active? for backwards-compatibility

Alias for: active?
is_multi?()

Same as multi? for backwards-compatibility

Alias for: multi?
is_nonmulti?()

Same as is_nonmulti? for backwards-compatibility

Alias for: nonmulti?
is_query?()

Same as query? for backwards-compatibility

Alias for: query?
is_ref?()

Same as ref? for backwards-compatibility

Alias for: ref?
metadata() click to toggle source

MiGA::Metadata with information about the dataset

# File lib/miga/dataset.rb, line 67
def metadata
  if @metadata.nil?
    @metadata = MiGA::Metadata.new(*@metadata_future)
    pull_hook :on_load
  end
  @metadata
end
multi?() click to toggle source

Is this dataset known to be multi-organism?

# File lib/miga/dataset.rb, line 140
def multi?
  return false if metadata[:type].nil? || @@KNOWN_TYPES[type].nil?

  @@KNOWN_TYPES[type][:multi]
end
Also aliased as: is_multi?
nonmulti?() click to toggle source

Is this dataset known to be single-organism?

# File lib/miga/dataset.rb, line 148
def nonmulti?
  return false if metadata[:type].nil? || @@KNOWN_TYPES[type].nil?

  !@@KNOWN_TYPES[type][:multi]
end
Also aliased as: is_nonmulti?
query?() click to toggle source

Is this dataset a query (non-reference)?

# File lib/miga/dataset.rb, line 134
def query?
  !metadata[:ref]
end
Also aliased as: is_query?
ref?() click to toggle source

Is this dataset a reference?

# File lib/miga/dataset.rb, line 128
def ref?
  !query?
end
Also aliased as: is_ref?
remove!() click to toggle source

Delete the dataset with all it's contents (including results) and returns nil

# File lib/miga/dataset.rb, line 92
def remove!
  results.each(&:remove!)
  metadata.remove!
  pull_hook :on_remove
end
save() click to toggle source

Save any changes you've made in the dataset

# File lib/miga/dataset.rb, line 77
def save
  MiGA.DEBUG "Dataset.metadata: #{metadata.data}"
  metadata.save
  pull_hook :on_save
end
type() click to toggle source

Get the type of dataset as Symbol

# File lib/miga/dataset.rb, line 85
def type
  metadata[:type]
end