Class: MiGA::Cli::Action::TaxSet

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

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 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, #http_request, #known_hosts, #main_server, #net_method, #normalize_encoding, #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
# File 'lib/miga/cli/action/tax_set.rb', line 7

def parse_cli
  cli.parse do |opt|
    cli.opt_object(opt, [:project, :dataset_opt])
    opt.on(
      '-s', '--tax-string STRING',
      'String corresponding to the taxonomy of the dataset',
      'A space-delimited set of \'rank:name\' pairs'
    ) { |v| cli[:taxstring] = v }
    opt.on(
      '-t', '--tax-file PATH',
      '(Mandatory unless -D and -s are provided)',
      'Tab-delimited file containing datasets taxonomy',
      'Each row corresponds to a datasets and each column to a rank',
      'The first row must be a header with the rank names,',
      'and the first column must contain dataset names'
    ) { |v| cli[:taxfile] = v }
  end
end

#performObject



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

def perform
  p = cli.load_project
  if !cli[:taxfile].nil?
    cli.say 'Reading tax-file and registering taxonomy'
    tfh = File.open(cli[:taxfile], 'r')
    header = nil
    tfh.each_line do |ln|
      next if ln =~ /^\s*?$/

      r = ln.chomp.split(/\t/, -1)
      dn = r.shift
      if header.nil?
        header = r
        next
      end
      d = p.dataset(dn)
      if d.nil?
        warn "Impossible to find dataset at line #{$.}: #{dn}. Ignoring..."
        next
      end
      d.[:tax] = Taxonomy.new(r, header)
      d.save
      cli.say "o #{d.name} registered"
    end
    tfh.close
  else
    cli.ensure_par({ dataset: '-D', taxstring: '-s' },
                   '%<flag>s is mandatory unless -t is provided')
    cli.say 'Registering taxonomy'
    d = cli.load_dataset
    d.[:tax] = Taxonomy.new(cli[:taxstring])
    d.save
  end
end