miga-base 1.3.9.8 → 1.3.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f778c1cf98987c440f71da2da7cfa760279c90009f58cc9abfbe9bb129fec97
4
- data.tar.gz: bf128ed11141faa28decc79f80d7426a16e113c8d6b381885815ba98a98e5a4f
3
+ metadata.gz: '0239e39a0588b73d042da7d970925d2d93a5334c858453e032d51b0af760fa27'
4
+ data.tar.gz: 81e6903e1feba6571d76fe5d113a60414bd0d3b1b3090d6e26367a93cf8d0da7
5
5
  SHA512:
6
- metadata.gz: ac2ab474cfdb3667d187f71b787d3cd30685198def25beb20cee58f964fbeec3071733637c14a6722c21c74fd3e1bfa4efb8f0920b36f4d6ebb3b2e0b3eef4c9
7
- data.tar.gz: eefb0c999194af805699c7a538d8992c9795447f7a5c81decfc2d85750618e57b116ab56f8c34a2478366ec9efce585649c6f78d1aec44c39c4f8633e3494384
6
+ metadata.gz: d68e55d5335f3da03eb9cea737aad5fa21a7a272e3958db6130e7260387844c1bed92b0b2f655a5a5133772797212b717559da9701723c9885cc9ee7cffc962f
7
+ data.tar.gz: 8d27c2f580106c0d1f74e6daaf1cb81ffd7c6fbabf86e7569342027ff9e09b1810c245ad560eff0179c3d06a88b2d1a087344c56e34a2d54c799004e2f6370c0
@@ -17,10 +17,7 @@ module MiGA::Cli::Action::Download::Ncbi
17
17
  cli.opt_flag(opt, 'chromosome', 'Download complete chromosomes')
18
18
  cli.opt_flag(opt, 'scaffold', 'Download genomes in scaffolds')
19
19
  cli.opt_flag(opt, 'contig', 'Download genomes in contigs')
20
- opt.on(
21
- '--all',
22
- 'Download all genomes (in any status)'
23
- ) do
20
+ opt.on('--all', 'Download all genomes (in any status)') do
24
21
  cli[:complete] = true
25
22
  cli[:chromosome] = true
26
23
  cli[:scaffold] = true
@@ -29,6 +26,10 @@ module MiGA::Cli::Action::Download::Ncbi
29
26
  opt.on('--ncbi-list-json STRING', '::HIDE::') do |v|
30
27
  cli[:ncbi_list_json] = v
31
28
  end
29
+ opt.on(
30
+ '--ncbi-taxonomy-dump STRING',
31
+ 'Path to an NCBI Taxonomy dump directory to query instead of API calls'
32
+ ) { |v| MiGA::RemoteDataset.use_ncbi_taxonomy_dump(v) }
32
33
  end
33
34
 
34
35
  def cli_name_modifiers(opt)
@@ -24,14 +24,13 @@ class MiGA::Cli::Action::NcbiGet < MiGA::Cli::Action
24
24
  cli_name_modifiers(opt)
25
25
  cli_filters(opt)
26
26
  cli_save_actions(opt)
27
- opt.on(
28
- '--api-key STRING',
29
- '::HIDE::' # For backwards compatibility
30
- ) { |v| ENV['NCBI_API_KEY'] = v }
31
- opt.on(
32
- '--ncbi-api-key STRING',
33
- 'NCBI API key'
34
- ) { |v| ENV['NCBI_API_KEY'] = v }
27
+ opt.on('--api-key STRING', '::HIDE::') do |v|
28
+ warn "The use of --api-key is deprecated, please use --ncbi-api-key"
29
+ ENV['NCBI_API_KEY'] = v
30
+ end
31
+ opt.on('--ncbi-api-key STRING', 'NCBI API key') do |v|
32
+ ENV['NCBI_API_KEY'] = v
33
+ end
35
34
  end
36
35
  end
37
36
 
@@ -12,6 +12,55 @@ class MiGA::RemoteDataset < MiGA::MiGA
12
12
  # Class-level
13
13
 
14
14
  class << self
15
+ ##
16
+ # Path to a directory with a recent NCBI Taxonomy dump to use instead of
17
+ # making API calls to NCBI servers, which can be obtained at:
18
+ # https://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
19
+ def use_ncbi_taxonomy_dump(path)
20
+ raise "Directory doesn't exist: #{path}" unless File.directory?(path)
21
+
22
+ # Structure: { TaxID => ["name", "rank", parent TaxID] }
23
+ @ncbi_taxonomy_names = {}
24
+
25
+ # Read names.dmp
26
+ File.open(File.join(path, 'names.dmp')) do |fh|
27
+ fh.each do |ln|
28
+ row = ln.split(/\t\|\t?/)
29
+ next unless row[3] == 'scientific name'
30
+ @ncbi_taxonomy_names[row[0].to_i] = [row[1].strip]
31
+ end
32
+ end
33
+
34
+ # Read nodes.dmp
35
+ File.open(File.join(path, 'nodes.dmp')) do |fh|
36
+ fh.each do |ln|
37
+ row = ln.split(/\t\|\t?/)
38
+ child = row[0].to_i
39
+ parent = row[1].to_i
40
+ @ncbi_taxonomy_names[child][1] = row[2]
41
+ @ncbi_taxonomy_names[child][2] = parent unless parent == child
42
+ end
43
+ end
44
+ end
45
+
46
+ ##
47
+ # Is a local NCBI Taxonomy dump available?
48
+ def ncbi_taxonomy_dump?
49
+ (@ncbi_taxonomy_names ||= nil) ? true : false
50
+ end
51
+
52
+ ##
53
+ # Get the MiGA::Taxonomy object for the lineage of the taxon with TaxID
54
+ # +id+ using the local NCBI Taxonomy dump.
55
+ def taxonomy_from_ncbi_dump(id)
56
+ MiGA::Taxonomy.new(ns: 'ncbi').tap do |tax|
57
+ while @ncbi_taxonomy_names[id]
58
+ tax << { @ncbi_taxonomy_names[id][1] => @ncbi_taxonomy_names[id][0] }
59
+ id = @ncbi_taxonomy_names[id][2]
60
+ end
61
+ end
62
+ end
63
+
15
64
  ##
16
65
  # Translate an NCBI Assembly Accession (+acc+) to corresponding internal
17
66
  # NCBI ID, with up to +retrials+ retrials if the returned JSON document
@@ -173,6 +222,10 @@ class MiGA::RemoteDataset < MiGA::MiGA
173
222
  def get_ncbi_taxonomy
174
223
  tax_id = get_ncbi_taxid or return
175
224
 
225
+ if self.class.ncbi_taxonomy_dump?
226
+ return self.class.taxonomy_from_ncbi_dump(tax_id)
227
+ end
228
+
176
229
  lineage = { ns: 'ncbi' }
177
230
  doc = MiGA::RemoteDataset.download(:ncbi, :taxonomy, tax_id, :xml)
178
231
  doc.scan(%r{<Taxon>(.*?)</Taxon>}m).map(&:first).each do |i|
data/lib/miga/version.rb CHANGED
@@ -12,7 +12,7 @@ module MiGA
12
12
  # - String indicating release status:
13
13
  # - rc* release candidate, not released as gem
14
14
  # - [0-9]+ stable release, released as gem
15
- VERSION = [1.3, 9, 8].freeze
15
+ VERSION = [1.3, 10, 0].freeze
16
16
 
17
17
  ##
18
18
  # Nickname for the current major.minor version.
@@ -20,7 +20,7 @@ module MiGA
20
20
 
21
21
  ##
22
22
  # Date of the current gem relese.
23
- VERSION_DATE = Date.new(2024, 1, 30)
23
+ VERSION_DATE = Date.new(2024, 1, 31)
24
24
 
25
25
  ##
26
26
  # References of MiGA
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9.8
4
+ version: 1.3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-30 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons