class MiGA::Project

MiGA representation of a project.

@package MiGA @license Artistic-2.0

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 22
def DISTANCE_TASKS ; @@DISTANCE_TASKS ; end
INCLADE_TASKS() click to toggle source
# File lib/miga/project/base.rb, line 21
def INCLADE_TASKS ; @@INCLADE_TASKS ; end
KNOWN_TYPES() click to toggle source
# File lib/miga/project/base.rb, line 23
def KNOWN_TYPES ; @@KNOWN_TYPES ; end
RESULT_DIRS() click to toggle source
# File lib/miga/project/base.rb, line 24
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 9
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 16
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 32
def initialize(path, update=false)
  @datasets = {}
  @do_not_save = false
  @path = File.absolute_path(path)
  self.create if not update and not Project.exist? self.path
  self.load if self.metadata.nil?
  self.load_plugins
  self.metadata[:type] = :mixed if type.nil?
  raise "Unrecognized project type: #{type}." if @@KNOWN_TYPES[type].nil?
end

Public Instance Methods

create() click to toggle source

Create an empty project.

# File lib/miga/project.rb, line 45
def create
  unless MiGA::MiGA.initialized?
    raise 'Impossible to create project in uninitialized MiGA.'
  end
  dirs = [path] + @@FOLDERS.map{|d| "#{path}/#{d}" } +
    @@DATA_FOLDERS.map{ |d| "#{path}/data/#{d}"}
  dirs.each{ |d| Dir.mkdir(d) unless Dir.exist? d }
  @metadata = MiGA::Metadata.new(self.path + "/miga.project.json",
    {datasets: [], name: File.basename(path)})
  FileUtils.cp("#{ENV["MIGA_HOME"]}/.miga_daemon.json",
    "#{path}/daemon/daemon.json") unless
      File.exist? "#{path}/daemon/daemon.json"
  self.load
end
is_clade?() click to toggle source

Is this a clade project?

# File lib/miga/project.rb, line 92
def is_clade? ; type==:clade ; end
is_multi?() click to toggle source

Is this a project for multi-organism datasets?

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

(Re-)load project data and metadata.

# File lib/miga/project.rb, line 75
def load
  @datasets = {}
  @dataset_names_hash = nil
  @metadata = MiGA::Metadata.load "#{path}/miga.project.json"
  raise "Couldn't find project metadata at #{path}" if metadata.nil?
end
name() click to toggle source

Name of the project.

# File lib/miga/project.rb, line 84
def name ; metadata[:name] ; end
save() click to toggle source

Save any changes persistently. Do nothing if do_not_save is true.

# File lib/miga/project.rb, line 62
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 68
def save!
  metadata.save
  self.load
end
type() click to toggle source

Type of project.

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