class MiGA::Project

MiGA representation of a project

Attributes

do_not_save[RW]

If true, it doesn't save changes

metadata[R]

Information about the project as MiGA::Metadata

path[R]

Absolute path to the project folder

Public Class Methods

DISTANCE_TASKS() click to toggle source
# File lib/miga/project/base.rb, line 28
def DISTANCE_TASKS
  @@DISTANCE_TASKS
end
INCLADE_TASKS() click to toggle source
# File lib/miga/project/base.rb, line 24
def INCLADE_TASKS
  @@INCLADE_TASKS
end
KNOWN_TYPES() click to toggle source
# File lib/miga/project/base.rb, line 32
def KNOWN_TYPES
  @@KNOWN_TYPES
end
OPTIONS() click to toggle source
# File lib/miga/project/base.rb, line 40
def OPTIONS
  @@OPTIONS
end
RESULT_DIRS() click to toggle source
# File lib/miga/project/base.rb, line 36
def RESULT_DIRS
  @@RESULT_DIRS
end
exist?(path) click to toggle source

Does the project at path exist?

# File lib/miga/project/base.rb, line 11
def exist?(path)
  Dir.exist?(path) and File.exist?("#{path}/miga.project.json")
end
load(path) click to toggle source

Load the project at path. Returns MiGA::Project if project exists, nil otherwise.

# File lib/miga/project/base.rb, line 18
def load(path)
  return nil unless exist? path

  new path
end
new(path, update = false) click to toggle source

Create a new MiGA::Project at path, if it doesn't exist and update is false, or load an existing one.

# File lib/miga/project.rb, line 31
def initialize(path, update = false)
  @datasets = {}
  @do_not_save = false
  @path = File.absolute_path(path)
  self.create if !update && !Project.exist?(self.path)
  self.load if self.metadata.nil?
  self.metadata[:type] = :mixed if type.nil?
  raise "Unrecognized project type: #{type}" if @@KNOWN_TYPES[type].nil?
end

Public Instance Methods

active?() click to toggle source

Is this project active? Currently a dummy function, returns always true.

# File lib/miga/project.rb, line 128
def active?
  true
end
clade?() click to toggle source

Is this a clade project?

# File lib/miga/project.rb, line 101
def clade?
  %[clade plasmids].include? type
end
Also aliased as: is_clade?
create() click to toggle source

Create an empty project

# File lib/miga/project.rb, line 43
def create
  unless MiGA::MiGA.initialized?
    warn 'Projects cannot be processed yet, first run: miga init'
  end

  dirs = @@FOLDERS.map { |d| File.join(path, d) }
  dirs += @@DATA_FOLDERS.map { |d| File.join(path, 'data', d) }
  dirs.each { |d| FileUtils.mkdir_p(d) }
  @metadata = MiGA::Metadata.new(
    File.join(path, 'miga.project.json'),
    datasets: [], name: File.basename(path)
  )
  d_path = File.join(path, 'daemon', 'daemon.json')
  File.open(d_path, 'w') { |fh| fh.puts '{}' } unless File.exist?(d_path)
  pull_hook :on_create
  self.load
end
daemon() click to toggle source

Load or recover the project's daemon

# File lib/miga/project.rb, line 134
def daemon
  require 'miga/daemon'
  @daemon ||= MiGA::Daemon.new(self)
end
is_clade?()

Same as active? For backward compatibility

Alias for: clade?
is_multi?()

Same as multi? For backward compatibility

Alias for: multi?
load() click to toggle source

(Re-)load project data and metadata

# File lib/miga/project.rb, line 77
def load
  @datasets = {}
  @dataset_names_hash = nil
  @dataset_names_set = nil
  @metadata = MiGA::Metadata.load "#{path}/miga.project.json"
  raise "Couldn't find project metadata at #{path}" if metadata.nil?

  pull_hook :on_load
end
markers?() click to toggle source

Does the project support the use of universal markers?

# File lib/miga/project.rb, line 121
def markers?
  @@KNOWN_TYPES[type][:markers]
end
multi?() click to toggle source

Is this a project for multi-organism datasets?

# File lib/miga/project.rb, line 111
def multi?
  @@KNOWN_TYPES[type][:multi]
end
Also aliased as: is_multi?
name() click to toggle source

Name of the project

# File lib/miga/project.rb, line 89
def name
  metadata[:name]
end
option_by_metadata(key) click to toggle source

Retrieves the option with name key from the project's metadata, extending support to relative paths in :ref_project and :db_proj_dir

# File lib/miga/project.rb, line 143
def option_by_metadata(key)
  case key.to_sym
  when :ref_project, :db_proj_dir
    y = metadata[key]
    y = File.expand_path(y, path) if y && y =~ /^[^\/]/
    return y
  end

  super
end
save() click to toggle source

Save any changes persistently. Do nothing if do_not_save is true

# File lib/miga/project.rb, line 63
def save
  save! unless do_not_save
end
save!() click to toggle source

Save any changes persistently, regardless of do_not_save

# File lib/miga/project.rb, line 69
def save!
  metadata.save!
  pull_hook :on_save
  self.load
end
type() click to toggle source

Type of project

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