Class: MiGA::Project

Inherits:
MiGA
  • Object
show all
Includes:
Dataset, Hooks, Result
Defined in:
lib/miga/project/base.rb,
lib/miga/project.rb

Overview

MiGA representation of a project.

Defined Under Namespace

Modules: Base, Dataset, Hooks, Result

Constant Summary

Constants included from MiGA

CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#default_hooks, #hook__pull_result_hooks, #hook_run_cmd

Methods included from Common::Hooks

#add_hook, #default_hooks, #hook_run_lambda, #hooks, #pull_hook

Methods included from Dataset

#add_dataset, #dataset, #dataset_names, #dataset_names_hash, #datasets, #done_preprocessing?, #each_dataset, #each_dataset_profile_advance, #import_dataset, #profile_datasets_advance, #unlink_dataset, #unregistered_datasets

Methods included from Result

#ignore_task?, #next_distances, #next_inclade, #next_task, #project, #result_base

Methods included from Common::WithResult

#add_result, #each_result, #get_result, #result, #result_dirs, #results

Methods inherited from MiGA

CITATION, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, initialized?, #result_files_exist?

Methods included from Common::Path

#root_path, #script_path

Methods included from Common::Format

#clean_fasta_file, #seqs_length, #tabulate

Constructor Details

#initialize(path, update = false) ⇒ Project

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



32
33
34
35
36
37
38
39
40
# 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..nil?
  self.[:type] = :mixed if type.nil?
  raise "Unrecognized project type: #{type}." if @@KNOWN_TYPES[type].nil?
end

Instance Attribute Details

#do_not_saveObject

If true, it doesn’t save changes



27
28
29
# File 'lib/miga/project.rb', line 27

def do_not_save
  @do_not_save
end

#metadataObject (readonly)

Information about the project as MiGA::Metadata.



23
24
25
# File 'lib/miga/project.rb', line 23

def 
  @metadata
end

#pathObject (readonly)

Absolute path to the project folder.



19
20
21
# File 'lib/miga/project.rb', line 19

def path
  @path
end

Class Method Details

.DISTANCE_TASKSObject



22
# File 'lib/miga/project/base.rb', line 22

def DISTANCE_TASKS ; @@DISTANCE_TASKS ; end

.exist?(path) ⇒ Boolean

Does the project at path exist?



9
10
11
# File 'lib/miga/project/base.rb', line 9

def exist?(path)
  Dir.exist?(path) and File.exist?("#{path}/miga.project.json")
end

.INCLADE_TASKSObject



21
# File 'lib/miga/project/base.rb', line 21

def INCLADE_TASKS ; @@INCLADE_TASKS ; end

.KNOWN_TYPESObject



23
# File 'lib/miga/project/base.rb', line 23

def KNOWN_TYPES ; @@KNOWN_TYPES ; end

.load(path) ⇒ Object

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



16
17
18
19
# File 'lib/miga/project/base.rb', line 16

def load(path)
  return nil unless exist? path
  new path
end

.RESULT_DIRSObject



24
# File 'lib/miga/project/base.rb', line 24

def RESULT_DIRS ; @@RESULT_DIRS ; end

Instance Method Details

#createObject

Create an empty project.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/miga/project.rb', line 44

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(
    File.expand_path('miga.project.json', path),
    {datasets: [], name: File.basename(path)})
  d_path = File.expand_path('daemon/daemon.json', path)
  File.open(d_path, 'w') { |fh| fh.puts '{}' } unless File.exist? d_path
  pull_hook :on_create
  self.load
end

#is_clade?Boolean

Is this a clade project?



94
# File 'lib/miga/project.rb', line 94

def is_clade? ; type==:clade ; end

#is_multi?Boolean

Is this a project for multi-organism datasets?



98
# File 'lib/miga/project.rb', line 98

def is_multi? ; @@KNOWN_TYPES[type][:multi] ; end

#loadObject

(Re-)load project data and metadata.



76
77
78
79
80
81
82
# File 'lib/miga/project.rb', line 76

def load
  @datasets = {}
  @dataset_names_hash = nil
  @metadata = MiGA::Metadata.load "#{path}/miga.project.json"
  raise "Couldn't find project metadata at #{path}" if .nil?
  pull_hook :on_load
end

#nameObject

Name of the project.



86
# File 'lib/miga/project.rb', line 86

def name ; [:name] ; end

#saveObject

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



62
63
64
# File 'lib/miga/project.rb', line 62

def save
  save! unless do_not_save
end

#save!Object

Save any changes persistently, regardless of do_not_save.



68
69
70
71
72
# File 'lib/miga/project.rb', line 68

def save!
  .save
  pull_hook :on_save
  self.load
end

#typeObject

Type of project.



90
# File 'lib/miga/project.rb', line 90

def type ; [:type] ; end