Class: MiGA::Project

Inherits:
MiGA
  • Object
show all
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

Attributes included from Common::Net

#remote_connection_uri

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, #dataset_names_set, #dataset_ref_active, #dataset_ref_active!, #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_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

#root_path, #script_path

Methods included from Common::Format

#clean_fasta_file, #seqs_length, #tabulate

Methods included from Common::Net

#download_file_ftp, #http_request, #known_hosts, #main_server, #net_method, #normalize_encoding, #remote_connection

Methods included from Common::SystemCall

#run_cmd, #run_cmd_opts

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 !update && !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



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

def do_not_save
  @do_not_save
end

#metadataObject (readonly)

Information about the project as MiGA::Metadata



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

def 
  @metadata
end

#pathObject (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_TASKSObject



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?

Returns:

  • (Boolean)


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_TASKSObject



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

def INCLADE_TASKS
  @@INCLADE_TASKS
end

.KNOWN_TYPESObject



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

.OPTIONSObject



40
41
42
# File 'lib/miga/project/base.rb', line 40

def OPTIONS
  @@OPTIONS
end

.RESULT_DIRSObject



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.

Returns:

  • (Boolean)


128
129
130
# File 'lib/miga/project.rb', line 128

def active?
  true
end

#clade?Boolean Also known as: is_clade?

Is this a clade project?

Returns:

  • (Boolean)


101
102
103
# File 'lib/miga/project.rb', line 101

def clade?
  %i[clade plasmids].include? type
end

#createObject

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

#daemonObject

Load or recover the project’s daemon



134
135
136
137
# File 'lib/miga/project.rb', line 134

def daemon
  require 'miga/daemon'
  @daemon ||= MiGA::Daemon.new(self)
end

#loadObject

(Re-)load project data and metadata



77
78
79
80
81
82
83
84
85
# 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 .nil?

  pull_hook :on_load
end

#markers?Boolean

Does the project support the use of universal markers?

Returns:

  • (Boolean)


121
122
123
# File 'lib/miga/project.rb', line 121

def markers?
  @@KNOWN_TYPES[type][:markers]
end

#multi?Boolean Also known as: is_multi?

Is this a project for multi-organism datasets?

Returns:

  • (Boolean)


111
112
113
# File 'lib/miga/project.rb', line 111

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

#nameObject

Name of the project



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

def name
  [:name]
end

#option_by_metadata(key) ⇒ Object

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



143
144
145
146
147
148
149
150
151
152
# File 'lib/miga/project.rb', line 143

def (key)
  case key.to_sym
  when :ref_project, :db_proj_dir
    y = [key]
    y = File.expand_path(y, path) if y && y =~ /^[^\/]/
    return y
  end

  super
end

#saveObject

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

#typeObject

Type of project



95
96
97
# File 'lib/miga/project.rb', line 95

def type
  [:type]
end