class MiGA::Cli::Action::NcbiGet

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/ncbi_get.rb, line 9
def parse_cli
  cli.defaults = {
    query: false, unlink: false,
    reference: false, legacy_name: false,
    complete: false, chromosome: false,
    scaffold: false, contig: false, add_version: true, dry: false,
    get_md: false, only_md: false, save_every: 1
  }
  cli.parse do |opt|
    cli.opt_object(opt, [:project])
    opt.on(
      '-T', '--taxon STRING',
      '(Mandatory unless --reference) Taxon name (e.g., a species binomial)'
    ) { |v| cli[:taxon] = v }
    cli_task_flags(opt)
    cli_name_modifiers(opt)
    cli_filters(opt)
    cli_save_actions(opt)
    opt.on(
      '--api-key STRING',
      'NCBI API key'
    ) { |v| ENV['NCBI_API_KEY'] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/ncbi_get.rb, line 34
def perform
  sanitize_cli
  p = cli.load_project
  ds = remote_list
  ds = discard_blacklisted(ds)
  d, downloaded = download_entries(ds, p)

  # Finalize
  cli.say "Datasets listed: #{d.size}"
  act = cli[:dry] ? 'to download' : 'downloaded'
  cli.say "Datasets #{act}: #{downloaded}"
  unless cli[:remote_list].nil?
    File.open(cli[:remote_list], 'w') do |fh|
      d.each { |i| fh.puts i }
    end
  end
  return unless cli[:unlink]
  unlink = p.dataset_names - d
  unlink.each { |i| p.unlink_dataset(i).remove! }
  cli.say "Datasets unlinked: #{unlink.size}"
end