class MiGA::Cli::Action::ClassifyWf

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/classify_wf.rb, line 10
def parse_cli
  default_opts_for_wf
  cli.defaults = {
    download: false, summaries: true, pvalue: 0.05,
    local: File.expand_path('.miga_db', ENV['MIGA_HOME'])
  }
  cli.parse do |opt|
    opt.on(
      '--download-db',
      'Attempt to download the reference database (all default options)',
      'It is recommended to use "miga get_db" separately instead'
    ) { |v| cli[:download] = v }
    opt.on(
      '-n', '--database STRING',
      'Name of the reference database to use',
      'By default, the first locally listed database is used'
    ) { |v| cli[:database] = v.to_sym }
    opt.on(
      '-p', '--p-value FLOAT', Float,
      'Maximum p-value to transfer taxonomy',
      "By default: #{cli[:pvalue]}"
    ) { |v| cli[:pvalue] = v }
    opt.on(
      '-l', '--local-dir PATH',
      "Local directory to store the database. By default: #{cli[:local]}"
    ) { |v| cli[:local] = v }
    opt.on(
      '--db-path STRING',
      'Path to the reference database to use, a fully indexed MiGA project',
      'If defined, --local-dir and --database are ignored'
    ) { |v| cli[:db_path] = v }
    opt.on(
      '--no-summaries',
      'Do not generate intermediate step summaries'
    ) { |v| cli[:summaries] = v }
    opts_for_wf(
      opt, 'Input genome assemblies (nucleotides, FastA)', qual: false
    )
  end
end
perform() click to toggle source
# File lib/miga/cli/action/classify_wf.rb, line 51
def perform
  # Input data
  ref_db = reference_db
  p_metadata = Hash[
    %w[project_stats haai_distances aai_distances ani_distances clade_finding]
               .map { |i| ["run_#{i}", false] }
  ]
  p_metadata[:ref_project] = ref_db.path
  p_metadata[:tax_pvalue] = cli[:pvalue]
  p = create_project(:assembly, p_metadata,
                     run_ssu: false, run_mytaxa_scan: false, run_distances: false)
  # Run
  run_daemon
  summarize(%w[cds assembly essential_genes]) if cli[:summaries]
  summarize(['taxonomy'])
  cli.say "Summary: classification"
  call_cli([
             'ls', '-P', cli[:outdir], '-m', 'tax', '--tab',
             '-o', File.expand_path('classification.tsv', cli[:outdir])
           ])
  cleanup
end