Skip to content

Commit

Permalink
Allow for empty --ncbi-taxonomy-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
lmrodriguezr committed Mar 8, 2024
1 parent 7f3c122 commit 615b602
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
24 changes: 19 additions & 5 deletions lib/miga/cli/action/download/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def cli_save_actions(opt)
'Path to an output file with the list of all datasets listed remotely'
) { |v| cli[:remote_list] = v }
opt.on(
'--ncbi-taxonomy-dump STRING',
'Path to an NCBI Taxonomy dump directory to query instead of API calls'
) { |v| cli[:ncbi_taxonomy_dump] = v }
'--ncbi-taxonomy-dump [path]',
'Path to an NCBI Taxonomy dump directory to query instead of API calls',
'If the path is not passed, the dump is automatically downloaded'
) { |v| cli[:ncbi_taxonomy_dump] = v || true }
end

def generic_perform
Expand All @@ -97,8 +98,21 @@ def load_tasks
def load_ncbi_taxonomy_dump
return unless cli[:ncbi_taxonomy_dump]

cli.say "Reading NCBI Taxonomy dump: #{cli[:ncbi_taxonomy_dump]}"
MiGA::RemoteDataset.use_ncbi_taxonomy_dump(cli[:ncbi_taxonomy_dump], cli)
if cli[:ncbi_taxonomy_dump] == true
cli.say 'Downloading and reading NCBI Taxonomy dump'
Dir.mktmpdir do |dir|
file = 'taxdump.tar.gz'
path = File.join(dir, file)
url = 'https://ftp.ncbi.nih.gov/pub/taxonomy/%s' % file

File.open(path, 'wb') { |fh| fh.print MiGA::MiGA.net_method(:get, url) }
MiGA::MiGA.run_cmd('cd "%s" && tar -zxf "%s"' % [dir, file])
MiGA::RemoteDataset.use_ncbi_taxonomy_dump(dir, cli)
end
else
cli.say "Reading NCBI Taxonomy dump: #{cli[:ncbi_taxonomy_dump]}"
MiGA::RemoteDataset.use_ncbi_taxonomy_dump(cli[:ncbi_taxonomy_dump], cli)
end
end


Expand Down
3 changes: 2 additions & 1 deletion lib/miga/common/net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ def http_request(method, url, *opts)

def net_method(method, uri, *opts)
attempts ||= 0
uri = URI.parse(uri) if uri.is_a? String
DEBUG "#{method.to_s.upcase}: #{uri} #{opts}"
case method.to_sym
when :ftp
download_file_ftp(uri)
download_file_ftp(uri, *opts)
else
http_request(method, uri, *opts)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/miga/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module MiGA
# - String indicating release status:
# - rc* release candidate, not released as gem
# - [0-9]+ stable release, released as gem
VERSION = [1.3, 12, 0].freeze
VERSION = [1.3, 12, 1].freeze

##
# Nickname for the current major.minor version.
Expand Down
16 changes: 7 additions & 9 deletions test/net_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ def test_download_file_ftp
f = tmpfile('t/test.txt')
d = File.dirname(f)
assert(!Dir.exist?(d))
# TODO
# Bring back when I can connect to the Gatech's FTP
### m = MiGA::MiGA
### m.download_file_ftp(:miga_online_ftp, 'api_test.txt', f)
### assert(Dir.exist?(d))
### assert_equal('miga', File.read(f).chomp)
### File.unlink(f)
### m.download_file_ftp(:miga_db, '../api_test.txt', f)
### assert_equal('miga', File.read(f).chomp)
m = MiGA::MiGA
m.download_file_ftp(:miga_online_ftp, 'api_test.txt', f)
assert(Dir.exist?(d))
assert_equal('miga', File.read(f).chomp)
File.unlink(f)
m.download_file_ftp(:miga_db, '../api_test.txt', f)
assert_equal('miga', File.read(f).chomp)
end

def test_encoding
Expand Down

0 comments on commit 615b602

Please sign in to comment.