Module: MiGA::Cli::Action::Download::Gtdb

Includes:
Base
Included in:
GtdbGet
Defined in:
lib/miga/cli/action/download/gtdb.rb

Overview

Helper module including download functions for the gtdb_get action

Instance Method Summary collapse

Methods included from Base

#cli_base_flags, #cli_filters, #cli_save_actions, #discard_excluded, #download_entries, #exclude_newer, #finalize_tasks, #generic_perform, #impose_limit, #load_ncbi_taxonomy_dump, #load_tasks, #save_entry, #unlink_entries

Instance Method Details

#cli_name_modifiers(opt) ⇒ Object



17
18
19
20
21
22
# File 'lib/miga/cli/action/download/gtdb.rb', line 17

def cli_name_modifiers(opt)
  opt.on(
    '--no-version-name',
    'Do not add sequence version to the dataset name'
  ) { |v| cli[:add_version] = v }
end

#cli_task_flags(opt) ⇒ Object



10
11
12
13
14
15
# File 'lib/miga/cli/action/download/gtdb.rb', line 10

def cli_task_flags(opt)
  cli.opt_flag(
    opt, 'reference',
    'Download only reference genomes. By default: download all'
  )
end

#remote_listObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/miga/cli/action/download/gtdb.rb', line 32

def remote_list
  cli.say 'Downloading genome list'
  extra = { sp_reps_only: cli[:reference].to_s }
  json = MiGA::RemoteDataset.download(
    :gtdb, :taxon, cli[:taxon], :genomes, nil, extra
  )
  doc = MiGA::Json.parse(json, contents: true)

  Hash[
    doc.map do |acc|
      [
        remote_row_name(acc),
        {
          ids: [acc], db: :assembly, universe: :gtdb,
          md: {
            type: :genome, gtdb_assembly: acc,
            get_ncbi_taxonomy: cli[:get_ncbi_taxonomy]
          }
        }
      ]
    end
  ]
end

#remote_row_name(asm) ⇒ Object



56
57
58
59
60
# File 'lib/miga/cli/action/download/gtdb.rb', line 56

def remote_row_name(asm)
  acc = asm.to_s
  acc.gsub!(/\.\d+\Z/, '') unless cli[:add_version]
  acc.miga_name
end

#sanitize_cliObject



24
25
26
27
28
29
30
# File 'lib/miga/cli/action/download/gtdb.rb', line 24

def sanitize_cli
  cli.ensure_par(taxon: '-T')
  unless cli[:taxon] =~ /^[a-z]__\S+$/
    raise 'Taxon (-T) must be in GTDB format: s__Macondimonas_diazotrophica'
  end
  cli[:save_every] = 1 if cli[:dry]
end