Class: MiGA::Cli::Action::Init

Inherits:
MiGA::Cli::Action show all
Includes:
DaemonHelper, FilesHelper
Defined in:
lib/miga/cli/action/init.rb

Defined Under Namespace

Modules: DaemonHelper, FilesHelper

Constant Summary

Constants included from MiGA

MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary

Attributes inherited from MiGA::Cli::Action

#cli

Attributes included from MiGA::Common::Net

#remote_connection_uri

Instance Method Summary collapse

Methods included from FilesHelper

#check_additional_files, #check_configuration_script, #check_mytaxa_database, #check_mytaxa_scores, #check_phyla_lite, #check_rdp_classifier, #close_rc_file, #open_rc_file

Methods included from DaemonHelper

#configure_bash_daemon, #configure_daemon, #configure_qsub_msub_daemon, #configure_slurm_daemon, #configure_ssh_daemon

Methods inherited from MiGA::Cli::Action

#complete, #initialize, #launch, load, #name

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 MiGA::Common::Path

#root_path, #script_path

Methods included from MiGA::Common::Format

#clean_fasta_file, #seqs_length, #tabulate

Methods included from MiGA::Common::Net

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

Methods included from MiGA::Common::SystemCall

#run_cmd_opts

Constructor Details

This class inherits a constructor from MiGA::Cli::Action

Instance Method Details

#empty_actionObject



89
90
# File 'lib/miga/cli/action/init.rb', line 89

def empty_action
end

#list_requirementsObject



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/miga/cli/action/init.rb', line 105

def list_requirements
  if cli.ask_user(
    'Would you like to see all the requirements before starting?',
    'no', %w(yes no)
  ) == 'yes'
    cli.puts ''
    req_path = File.join(MiGA.root_path, 'utils', 'requirements.txt')
    File.open(req_path, 'r') do |fh|
      fh.each_line { |ln| cli.puts ln }
    end
    cli.puts ''
  end
end

#parse_cliObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/miga/cli/action/init.rb', line 12

def parse_cli
  cli.interactive = true
  cli.defaults = {
    mytaxa: nil,
    rdp: nil,
    reads: nil,
    optional: nil,
    config: File.join(ENV['MIGA_HOME'], '.miga_modules'),
    ask: false,
    auto: false,
    dtype: :bash
  }
  cli.parse do |opt|
    opt.on(
      '-c', '--config PATH',
      'Path to the Bash configuration file',
      "By default: #{cli[:config]}"
    ) { |v| cli[:config] = v }
    opt.on(
      '--[no-]mytaxa',
      'Should I try setting up MyTaxa and its dependencies?',
      'By default: interactive (true if --auto)'
    ) { |v| cli[:mytaxa] = v }
    opt.on(
      '--[no-]rdp',
      'Should I try setting up the RDP classifier?',
      'By default: interactive (true if --auto)'
    ) { |v| cli[:rdp] = v }
    opt.on(
      '--[no-]read-processing',
      'Should I try setting up read processing software?',
      'By default: interactive (true if --auto)'
    ) { |v| cli[:reads] = v }
    opt.on(
      '--[no-]optional',
      'Should I try setting up the optional software?',
      'Automatically sets answers for mytaxa, rdp, and reads'
    ) { |v| cli[:optional] = v }
    opt.on(
      '--daemon-type STRING',
      'Type of daemon launcher, one of: bash, ssh, qsub, msub, slurm',
      "By default: interactive (#{cli[:dtype]} if --auto)"
    ) { |v| cli[:dtype] = v.to_sym }
    %w[R ruby python].each do |bin|
      opt.on(
        "--path-to-#{bin} STRING",
        "Use this path to #{bin} instead of testing for executables"
      ) { |v| cli[:"path_to_#{bin}"] = v }
    end
    opt.on(
      '--ask-all',
      'Ask for the location of all software',
      'By default, only the locations missing in PATH are requested'
    ) { |v| cli[:ask] = v }
  end
end

#performObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/miga/cli/action/init.rb', line 69

def perform
  cli.puts <<~BANNER
    ===[ Welcome to MiGA, the Microbial Genome Atlas ]===

    I'm the initialization script, and I'll sniff around your computer to
    make sure you have all the requirements for MiGA data processing.

  BANNER
  list_requirements
  rc_fh = open_rc_file
  check_configuration_script(rc_fh)
  paths = check_software_requirements(rc_fh)
  check_additional_files(paths)
  check_libraries(paths)
  configure_daemon
  close_rc_file(rc_fh)
  cli.puts 'Configuration complete. MiGA is ready to work!'
  cli.puts ''
end

#run_cmd(cli, cmd, opts = {}) ⇒ Object



92
93
94
95
# File 'lib/miga/cli/action/init.rb', line 92

def run_cmd(cli, cmd, opts = {})
  opts = { return: :output, source: cli[:config] }.merge(opts)
  MiGA::MiGA.run_cmd(cmd, opts)
end

#run_r_cmd(cli, paths, cmd, opts = {}) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/miga/cli/action/init.rb', line 97

def run_r_cmd(cli, paths, cmd, opts = {})
  run_cmd(
    cli,
    "echo #{cmd.shellescape} | #{paths['R'].shellescape} --vanilla -q",
    { err2out: true, stdout: '/dev/null' }.merge(opts)
  )
end