Class: MiGA::Project
- Includes:
- Common::WithOption, Dataset, Hooks, Result
- Defined in:
- lib/miga/project.rb,
lib/miga/project/base.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
-
#do_not_save ⇒ Object
If true, it doesn’t save changes.
-
#metadata ⇒ Object
readonly
Information about the project as MiGA::Metadata.
-
#path ⇒ Object
readonly
Absolute path to the project folder.
Class Method Summary collapse
- .DISTANCE_TASKS ⇒ Object
-
.exist?(path) ⇒ Boolean
Does the project at
path
exist?. - .INCLADE_TASKS ⇒ Object
- .KNOWN_TYPES ⇒ Object
-
.load(path) ⇒ Object
Load the project at
path
. - .OPTIONS ⇒ Object
- .RESULT_DIRS ⇒ Object
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is this project active? Currently a dummy function, returns always true.
-
#clade? ⇒ Boolean
(also: #is_clade?)
Is this a clade project?.
-
#create ⇒ Object
Create an empty project.
-
#daemon ⇒ Object
Load or recover the project’s daemon.
-
#initialize(path, update = false) ⇒ Project
constructor
Create a new MiGA::Project at
path
, if it doesn’t exist andupdate
is false, or load an existing one. -
#load ⇒ Object
(Re-)load project data and metadata.
-
#multi? ⇒ Boolean
(also: #is_multi?)
Is this a project for multi-organism datasets?.
-
#name ⇒ Object
Name of the project.
-
#save ⇒ Object
Save any changes persistently.
-
#save! ⇒ Object
Save any changes persistently, regardless of
do_not_save
. -
#type ⇒ Object
Type of project.
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?, #inactivate!, #next_distances, #next_inclade, #project, #result_base
Methods included from Common::WithResult
#add_result, #each_result, #get_result, #next_task, #recalculate_tasks, #result, #result_dirs, #results
Methods included from Common::WithOption
#all_options, #assert_has_option, #assert_valid_option_value, #option, #option?, #option_by_default, #option_by_metadata, #option_from_string, #set_option
Methods inherited from MiGA
CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say
Methods included from Common::Path
Methods included from Common::Format
#clean_fasta_file, #seqs_length, #tabulate
Methods included from Common::Net
#download_file_ftp, #known_hosts, #remote_connection
Methods included from Common::SystemCall
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.
31 32 33 34 35 36 37 38 39 |
# 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 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_save ⇒ Object
If true, it doesn’t save changes
26 27 28 |
# File 'lib/miga/project.rb', line 26 def do_not_save @do_not_save end |
#metadata ⇒ Object (readonly)
Information about the project as MiGA::Metadata
22 23 24 |
# File 'lib/miga/project.rb', line 22 def @metadata end |
#path ⇒ Object (readonly)
Absolute path to the project folder
18 19 20 |
# File 'lib/miga/project.rb', line 18 def path @path end |
Class Method Details
.DISTANCE_TASKS ⇒ Object
28 29 30 |
# File 'lib/miga/project/base.rb', line 28 def DISTANCE_TASKS @@DISTANCE_TASKS end |
.exist?(path) ⇒ Boolean
Does the project at path
exist?
11 12 13 |
# File 'lib/miga/project/base.rb', line 11 def exist?(path) Dir.exist?(path) and File.exist?("#{path}/miga.project.json") end |
.INCLADE_TASKS ⇒ Object
24 25 26 |
# File 'lib/miga/project/base.rb', line 24 def INCLADE_TASKS @@INCLADE_TASKS end |
.KNOWN_TYPES ⇒ Object
32 33 34 |
# File 'lib/miga/project/base.rb', line 32 def KNOWN_TYPES @@KNOWN_TYPES end |
.load(path) ⇒ Object
Load the project at path
. Returns MiGA::Project if project exists, nil otherwise.
18 19 20 21 22 |
# File 'lib/miga/project/base.rb', line 18 def load(path) return nil unless exist? path new path end |
.OPTIONS ⇒ Object
40 41 42 |
# File 'lib/miga/project/base.rb', line 40 def OPTIONS @@OPTIONS end |
.RESULT_DIRS ⇒ Object
36 37 38 |
# File 'lib/miga/project/base.rb', line 36 def RESULT_DIRS @@RESULT_DIRS end |
Instance Method Details
#active? ⇒ Boolean
Is this project active? Currently a dummy function, returns always true.
121 122 123 |
# File 'lib/miga/project.rb', line 121 def active? true end |
#clade? ⇒ Boolean Also known as: is_clade?
Is this a clade project?
100 101 102 |
# File 'lib/miga/project.rb', line 100 def clade? type == :clade end |
#create ⇒ Object
Create an empty project
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Object
Load or recover the project’s daemon
127 128 129 130 |
# File 'lib/miga/project.rb', line 127 def daemon require 'miga/daemon' @daemon ||= MiGA::Daemon.new(self) end |
#load ⇒ Object
(Re-)load project data and metadata
77 78 79 80 81 82 83 84 |
# File 'lib/miga/project.rb', line 77 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 |
#multi? ⇒ Boolean Also known as: is_multi?
Is this a project for multi-organism datasets?
110 111 112 |
# File 'lib/miga/project.rb', line 110 def multi? @@KNOWN_TYPES[type][:multi] end |
#name ⇒ Object
Name of the project
88 89 90 |
# File 'lib/miga/project.rb', line 88 def name [:name] end |
#save ⇒ Object
Save any changes persistently. Do nothing if do_not_save
is true
63 64 65 |
# File 'lib/miga/project.rb', line 63 def save save! unless do_not_save end |
#save! ⇒ Object
Save any changes persistently, regardless of do_not_save
69 70 71 72 73 |
# File 'lib/miga/project.rb', line 69 def save! .save pull_hook :on_save self.load end |
#type ⇒ Object
Type of project
94 95 96 |
# File 'lib/miga/project.rb', line 94 def type [:type] end |