Skip to content

Commit

Permalink
Extend cases for WGS fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
lmrodriguezr committed Apr 1, 2024
1 parent be0a10e commit e18c651
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/miga/remote_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ def ncbi_asm_json_doc
metadata[:web_assembly_gz] ||=
'%s/%s_genomic.fna.gz' % [url_dir, File.basename(url_dir)]
end

# If all conditions are right, try getting the WGS range
if @_ncbi_asm_json_doc['wgs'] && !@_ncbi_asm_json_doc['wgs'].empty? &&
metadata[:ncbi_nuccore] && !metadata[:ncbi_wgs]
doc = self.class.download(:ncbi_fetch, :nuccore, metadata[:ncbi_nuccore], :gb).split(/\n/)
ln = doc.grep(/^WGS\s+\S+-\S+/).first
wgs = ln&.gsub(/^WGS\s+(\S+-\S+).*/, '\1')
metadata[:ncbi_wgs] = wgs if wgs
end

@_ncbi_asm_json_doc
end

Expand Down
9 changes: 9 additions & 0 deletions lib/miga/remote_dataset/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ module MiGA::RemoteDataset::Base
end,
method: :get
},
ncbi_fetch: {
dbs: { nuccore: { stage: :metadata, format: :gb } },
uri: lambda do |opts|
@@_EUTILS_BUILD[:efetch,
db: opts[:db], id: opts[:ids], rettype: opts[:format], retmode: :text
]
end,
method: :get
},
ncbi_search: {
dbs: {
assembly: { stage: :metadata, format: :json },
Expand Down
9 changes: 6 additions & 3 deletions lib/miga/remote_dataset/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ def ncbi_gb_get(opts)

MiGA::MiGA.DEBUG 'Empty sequence, attempting download as WGS records'
a, b = opts[:obj].metadata[:ncbi_wgs].split('-', 2)
pref = longest_common_prefix([a, b])
rang = a[pref.size .. -1].to_i .. b[pref.size .. -1].to_i
ids = rang.map { |k| "%s%0#{a.size - pref.size}i" % [pref, k] }
ids = [a]
unless b.nil?
pref = longest_common_prefix([a, b])
rang = a[pref.size .. -1].to_i .. b[pref.size .. -1].to_i
ids = rang.map { |k| "%s%0#{a.size - pref.size}i" % [pref, k] }
end
download_rest(opts.merge(universe: :ncbi, db: :nuccore, ids: ids))
end

Expand Down
4 changes: 2 additions & 2 deletions lib/miga/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module MiGA
# - String indicating release status:
# - rc* release candidate, not released as gem
# - [0-9]+ stable release, released as gem
VERSION = [1.3, 13, 9].freeze
VERSION = [1.3, 13, 10].freeze

##
# Nickname for the current major.minor version.
VERSION_NAME = 'mezzotint'

##
# Date of the current gem relese.
VERSION_DATE = Date.new(2024, 3, 31)
VERSION_DATE = Date.new(2024, 4, 1)

##
# References of MiGA
Expand Down

0 comments on commit e18c651

Please sign in to comment.