miga-base 0.5.5.0 → 0.5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/miga/cli/action/tax_dist.rb +13 -8
- data/lib/miga/cli/action/tax_index.rb +5 -2
- data/lib/miga/cli/objects_helper.rb +13 -7
- data/lib/miga/cli.rb +1 -1
- data/lib/miga/dataset.rb +11 -7
- data/lib/miga/project.rb +4 -4
- data/lib/miga/tax_index.rb +11 -8
- data/lib/miga/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 405d3cf6f84fa7f78f8026d1392be3fd8c32b3caea3d9e2c4c29a511ffeccb6c
|
4
|
+
data.tar.gz: 29108306ca8358a1155f791a4a586fce73eb9dccbbf2841869ed450064508774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e3264d6d55ff810b6ba0ae415abac248b65ec411fde5780107c1974923c2ef7da2cd1ae86c74f36aad94af03534b1f326327f797eaf6aec1c2a20c444dfa8d
|
7
|
+
data.tar.gz: cff5d84655677d1eabe298478d099074c1769cb4c74a753b10e3cbd62fb9fb0ed3b4df2ccc8924799c04d8a2e6be6ac7b3720f8ccbf7d83885cf17c5537fcd97
|
@@ -16,7 +16,12 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
|
|
16
16
|
'-i', '--index FILE',
|
17
17
|
'Pre-calculated tax-index (in tabular format) to be used',
|
18
18
|
'If passed, dataset filtering arguments are ignored'
|
19
|
-
|
19
|
+
) { |v| cli[:index] = v }
|
20
|
+
opt.on(
|
21
|
+
'-m', '--metric STR',
|
22
|
+
'Distance metric used to evaluate the distribution',
|
23
|
+
'By default: AAI for genomes projects, ANI for clade projects'
|
24
|
+
) { |v| cli[:metric] = v.downcase }
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
@@ -43,9 +48,9 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
|
|
43
48
|
|
44
49
|
def read_distances
|
45
50
|
p = cli.load_project
|
46
|
-
metric
|
47
|
-
res_n = "#{metric}_distances"
|
48
|
-
cli.say "Reading distances: 1-#{metric.upcase}"
|
51
|
+
cli[:metric] ||= p.is_clade? ? 'ani' : 'aai'
|
52
|
+
res_n = "#{cli[:metric]}_distances"
|
53
|
+
cli.say "Reading distances: 1-#{cli[:metric].upcase}"
|
49
54
|
res = p.result(res_n)
|
50
55
|
raise "#{res_n} not yet calculated" if res.nil?
|
51
56
|
matrix = res.file_path(:matrix)
|
@@ -57,9 +62,9 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
|
|
57
62
|
next if mfh.lineno == 1
|
58
63
|
row = ln.chomp.split("\t")
|
59
64
|
dist[cannid(row[1], row[2])] = [row[3], row[5], row[6], 0, ['root:biota']]
|
60
|
-
cli.advance(
|
65
|
+
cli.advance('Lines:', mfh.lineno, nil, false) if (mfh.lineno % 1_000) == 0
|
61
66
|
end
|
62
|
-
cli.say
|
67
|
+
cli.say ''
|
63
68
|
mfh.close
|
64
69
|
dist
|
65
70
|
end
|
@@ -84,7 +89,7 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
|
|
84
89
|
cli.say 'Traversing taxonomy'
|
85
90
|
rank_i = 0
|
86
91
|
Taxonomy.KNOWN_RANKS.each do |rank|
|
87
|
-
|
92
|
+
next if rank == :ns
|
88
93
|
rank_n = 0
|
89
94
|
rank_i += 1
|
90
95
|
in_rank = nil
|
@@ -110,7 +115,7 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
|
|
110
115
|
end
|
111
116
|
end
|
112
117
|
end
|
113
|
-
cli.say "#{rank_n} pairs of datasets"
|
118
|
+
cli.say "o #{rank}: #{rank_n} pairs of datasets"
|
114
119
|
end
|
115
120
|
dist
|
116
121
|
end
|
@@ -26,11 +26,14 @@ class MiGA::Cli::Action::TaxIndex < MiGA::Cli::Action
|
|
26
26
|
def perform
|
27
27
|
cli.ensure_par(index: '-i')
|
28
28
|
ds = cli.load_and_filter_datasets
|
29
|
-
ds.keep_if {|d| !d.metadata[:tax].nil? }
|
30
29
|
|
31
30
|
cli.say 'Indexing taxonomy'
|
32
31
|
tax_index = MiGA::TaxIndex.new
|
33
|
-
ds.
|
32
|
+
ds.each_with_index do |d, i|
|
33
|
+
cli.advance('Datasets:', i, ds.size, false)
|
34
|
+
tax_index << d unless d.metadata[:tax].nil?
|
35
|
+
end
|
36
|
+
cli.say ''
|
34
37
|
|
35
38
|
cli.say 'Saving index'
|
36
39
|
File.open(cli[:index], 'w') do |fh|
|
@@ -40,14 +40,20 @@ module MiGA::Cli::ObjectsHelper
|
|
40
40
|
say 'Listing datasets'
|
41
41
|
ds = self[:dataset].nil? ?
|
42
42
|
load_project.datasets : [load_dataset(silent)].compact
|
43
|
-
|
44
|
-
|
43
|
+
k = 0
|
44
|
+
n = ds.size
|
45
45
|
ds.select! do |d|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
(
|
50
|
-
|
46
|
+
advance('Datasets:', k += 1, n, false)
|
47
|
+
o = true
|
48
|
+
o &&= (d.is_ref? == self[:ref]) unless self[:ref].nil?
|
49
|
+
o &&= (d.is_active? == self[:active]) unless self[:active].nil?
|
50
|
+
o &&= (self[:multi] ? d.is_multi? :
|
51
|
+
d.is_nonmulti?) unless self[:multi].nil?
|
52
|
+
o &&= (not d.metadata[:tax].nil?) &&
|
53
|
+
d.metadata[:tax].in?(self[:taxonomy]) unless self[:taxonomy].nil?
|
54
|
+
o
|
55
|
+
end
|
56
|
+
say ''
|
51
57
|
ds = ds.values_at(self[:dataset_k]-1) unless self[:dataset_k].nil?
|
52
58
|
@objects[:filtered_datasets] = ds
|
53
59
|
end
|
data/lib/miga/cli.rb
CHANGED
@@ -118,7 +118,7 @@ class MiGA::Cli < MiGA::MiGA
|
|
118
118
|
# The report goes to $stderr iff --verborse
|
119
119
|
def advance(step, n = 0, total = nil, bin = true)
|
120
120
|
return unless self[:verbose]
|
121
|
-
adv = total.nil? ? '' :
|
121
|
+
adv = total.nil? ? (n == 0 ? '' : num_suffix(n, bin)) :
|
122
122
|
('%.1f%% (%s/%s)' % [100 * n / total,
|
123
123
|
num_suffix(n, bin), num_suffix(total, bin)])
|
124
124
|
$stderr.print("[%s] %s %s \r" % [Time.now, step, adv])
|
data/lib/miga/dataset.rb
CHANGED
@@ -38,16 +38,12 @@ class MiGA::Dataset < MiGA::MiGA
|
|
38
38
|
# Datasets are uniquely identified by +name+ in a project.
|
39
39
|
attr_reader :name
|
40
40
|
|
41
|
-
##
|
42
|
-
# MiGA::Metadata with information about the dataset.
|
43
|
-
attr_reader :metadata
|
44
|
-
|
45
41
|
##
|
46
42
|
# Create a MiGA::Dataset object in a +project+ MiGA::Project with a
|
47
43
|
# uniquely identifying +name+. +is_ref+ indicates if the dataset is to
|
48
44
|
# be treated as reference (true, default) or query (false). Pass any
|
49
45
|
# additional +metadata+ as a Hash.
|
50
|
-
def initialize(project, name, is_ref=true, metadata={})
|
46
|
+
def initialize(project, name, is_ref = true, metadata = {})
|
51
47
|
unless name.miga_name?
|
52
48
|
raise 'Invalid name, please use only alphanumerics and underscores: ' +
|
53
49
|
name.to_s
|
@@ -55,8 +51,16 @@ class MiGA::Dataset < MiGA::MiGA
|
|
55
51
|
@project = project
|
56
52
|
@name = name
|
57
53
|
metadata[:ref] = is_ref
|
58
|
-
@
|
59
|
-
File.expand_path("metadata/#{name}.json", project.path),
|
54
|
+
@metadata_future = [
|
55
|
+
File.expand_path("metadata/#{name}.json", project.path),
|
56
|
+
metadata
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# MiGA::Metadata with information about the dataset.
|
62
|
+
def metadata
|
63
|
+
@metadata ||= MiGA::Metadata.new(*@metadata_future)
|
60
64
|
end
|
61
65
|
|
62
66
|
##
|
data/lib/miga/project.rb
CHANGED
@@ -49,11 +49,11 @@ class MiGA::Project < MiGA::MiGA
|
|
49
49
|
dirs = [path] + @@FOLDERS.map{|d| "#{path}/#{d}" } +
|
50
50
|
@@DATA_FOLDERS.map{ |d| "#{path}/data/#{d}"}
|
51
51
|
dirs.each{ |d| Dir.mkdir(d) unless Dir.exist? d }
|
52
|
-
@metadata = MiGA::Metadata.new(
|
52
|
+
@metadata = MiGA::Metadata.new(
|
53
|
+
File.expand_path('miga.project.json', path),
|
53
54
|
{datasets: [], name: File.basename(path)})
|
54
|
-
|
55
|
-
|
56
|
-
File.exist? "#{path}/daemon/daemon.json"
|
55
|
+
d_path = File.expand_path('daemon/daemon.json', path)
|
56
|
+
File.open(d_path, 'w') { |fh| fh.puts '{}' } unless File.exist? d_path
|
57
57
|
self.load
|
58
58
|
end
|
59
59
|
|
data/lib/miga/tax_index.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# @package MiGA
|
2
2
|
# @license Artistic-2.0
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'miga/taxonomy'
|
5
5
|
|
6
6
|
##
|
7
7
|
# Indexing methods based on taxonomy.
|
@@ -18,7 +18,7 @@ class MiGA::TaxIndex < MiGA::MiGA
|
|
18
18
|
##
|
19
19
|
# Initialize an empty MiGA::TaxIndex
|
20
20
|
def initialize
|
21
|
-
@root = MiGA::TaxIndexTaxon.new :root,
|
21
|
+
@root = MiGA::TaxIndexTaxon.new :root, 'biota'
|
22
22
|
@datasets = []
|
23
23
|
end
|
24
24
|
|
@@ -64,7 +64,9 @@ class MiGA::TaxIndex < MiGA::MiGA
|
|
64
64
|
|
65
65
|
##
|
66
66
|
# Generate tabular String for the index.
|
67
|
-
def to_tab(unknown=false)
|
67
|
+
def to_tab(unknown = false)
|
68
|
+
root.to_tab(unknown)
|
69
|
+
end
|
68
70
|
end
|
69
71
|
|
70
72
|
##
|
@@ -94,7 +96,7 @@ class MiGA::TaxIndexTaxon < MiGA::MiGA
|
|
94
96
|
|
95
97
|
##
|
96
98
|
# String representation of the taxon.
|
97
|
-
def tax_str ; "#{rank}:#{name.nil? ?
|
99
|
+
def tax_str ; "#{rank}:#{name.nil? ? '?' : name}" ; end
|
98
100
|
|
99
101
|
##
|
100
102
|
# Add child at +rank+ with +name+.
|
@@ -142,11 +144,12 @@ class MiGA::TaxIndexTaxon < MiGA::MiGA
|
|
142
144
|
##
|
143
145
|
# Tabular String of the taxon.
|
144
146
|
def to_tab(unknown, indent=0)
|
145
|
-
o =
|
146
|
-
|
147
|
-
|
147
|
+
o = ''
|
148
|
+
if unknown or not datasets.empty? or not name.nil?
|
149
|
+
o = "#{' ' * indent}#{tax_str}: #{datasets_count}\n"
|
150
|
+
end
|
148
151
|
indent += 2
|
149
|
-
datasets.each{ |ds| o << "#{
|
152
|
+
datasets.each{ |ds| o << "#{' ' * indent}# #{ds.name}\n" }
|
150
153
|
children.each{ |it| o << it.to_tab(unknown, indent) }
|
151
154
|
o
|
152
155
|
end
|
data/lib/miga/version.rb
CHANGED
@@ -10,7 +10,7 @@ module MiGA
|
|
10
10
|
# - Float representing the major.minor version.
|
11
11
|
# - Integer representing gem releases of the current version.
|
12
12
|
# - Integer representing minor changes that require new version number.
|
13
|
-
VERSION = [0.5, 5,
|
13
|
+
VERSION = [0.5, 5, 1]
|
14
14
|
|
15
15
|
##
|
16
16
|
# Nickname for the current major.minor version.
|