Class: MiGA::Cli::Action::Summary

Inherits:
MiGA::Cli::Action show all
Defined in:
lib/miga/cli/action/summary.rb

Constant Summary

Constants included from MiGA

MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary

Attributes inherited from MiGA::Cli::Action

#cli

Instance Method Summary collapse

Methods inherited from MiGA::Cli::Action

#complete, #empty_action, #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, #known_hosts, #remote_connection

Methods included from MiGA::Common::SystemCall

#run_cmd, #run_cmd_opts

Constructor Details

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

Instance Method Details

#parse_cliObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/miga/cli/action/summary.rb', line 7

def parse_cli
  cli.defaults = { units: false, tabular: false }
  cli.parse do |opt|
    cli.opt_object(opt, [:project, :dataset_opt])
    cli.opt_filter_datasets(opt)
    cli.opt_object(opt, [:result_dataset])
    opt.on(
      '-o', '--output PATH',
      'Create output file instead of returning to STDOUT'
    ) { |v| cli[:output] = v }
    opt.on(
      '--tab',
      'Return a tab-delimited table'
    ) { |v| cli[:tabular] = v }
    opt.on(
      '--key STRING',
      'Return only the value of the requested key'
    ) { |v| cli[:key_md] = v }
    opt.on(
      '--with-units',
      'Include units in each cell'
    ) { |v| cli[:units] = v }
    opt.on(
      '--compute-and-save',
      'Compute and save the statistics if not yet available'
    ) { |v| cli[:compute] = v }
  end
end

#performObject



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
# File 'lib/miga/cli/action/summary.rb', line 36

def perform
  cli.ensure_par(result: '-r')
  ds = cli.load_and_filter_datasets
  cli.say 'Loading results'
  k = 0
  n = ds.size
  stats = ds.map do |d|
    cli.advance('Datasets:', k += 1, n, false)
    r = d.result(cli[:result])
    r.compute_stats if cli[:compute] && !r.nil? && r[:stats].empty?
    s = r.nil? ? {} : r[:stats]
    s.tap { |i| i[:dataset] = d.name }
  end
  cli.say ''
  keys = cli[:key_md].nil? ? stats.map(&:keys).flatten.uniq :
    [:dataset, cli[:key_md].downcase.miga_name.to_sym]
  keys.delete :dataset
  keys.unshift :dataset

  table = cli[:units] ?
    stats.map { |s|
      keys
        .map { |k| s[k].is_a?(Array) ? s[k].map(&:to_s).join('') : s[k] }
    } :
    stats.map { |s| keys.map { |k| s[k].is_a?(Array) ? s[k].first : s[k] } }
  io = cli[:output].nil? ? $stdout : File.open(cli[:output], 'w')
  cli.puts(io, MiGA.tabulate(keys, table, cli[:tabular]))
  io.close unless cli[:output].nil?
end