miga-base 0.5.5.0 → 0.5.5.1

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: 59649a6c1b7aaa4e3c0db090a828469e9595eba42d311eff114417741a2816bd
4
- data.tar.gz: a765a214e5b64d3f1758ae50942dc7f0649f438e8c2b12312648012d9cceeacc
3
+ metadata.gz: 405d3cf6f84fa7f78f8026d1392be3fd8c32b3caea3d9e2c4c29a511ffeccb6c
4
+ data.tar.gz: 29108306ca8358a1155f791a4a586fce73eb9dccbbf2841869ed450064508774
5
5
  SHA512:
6
- metadata.gz: f76b1691a30d7ce94314a4bd8d22601d86d3101c2db33f262b53548bba817d17bc783f2c93ec0502844adda1f5a17bd0c530e82c82c7fb590f07abf8ffc6788c
7
- data.tar.gz: c27cd47089f65633cefaca74cd217967b583df43d60682dce9f755a6610fdc6e728638d8d7b884f4de627de79b48080c8325f7b4d60794253f69511c15f997a4
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
- ){ |v| cli[:index] = v }
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 = p.is_clade? ? 'ani' : 'aai'
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("Ln: #{mfh.lineno}") if (mfh.lineno % 1_000) == 0
65
+ cli.advance('Lines:', mfh.lineno, nil, false) if (mfh.lineno % 1_000) == 0
61
66
  end
62
- cli.say " Lines: #{mfh.lineno}"
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
- cli.say "o #{rank}: "
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.each { |d| tax_index << d }
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
- ds.select! { |d| d.is_ref? == self[:ref] } unless self[:ref].nil?
44
- ds.select! { |d| d.is_active? == self[:active] } unless self[:active].nil?
43
+ k = 0
44
+ n = ds.size
45
45
  ds.select! do |d|
46
- self[:multi] ? d.is_multi? : d.is_nonmulti?
47
- end unless self[:multi].nil?
48
- ds.select! do |d|
49
- (not d.metadata[:tax].nil?) && d.metadata[:tax].in?(self[:taxonomy])
50
- end unless self[:taxonomy].nil?
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
- @metadata = MiGA::Metadata.new(
59
- File.expand_path("metadata/#{name}.json", project.path), metadata )
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(self.path + "/miga.project.json",
52
+ @metadata = MiGA::Metadata.new(
53
+ File.expand_path('miga.project.json', path),
53
54
  {datasets: [], name: File.basename(path)})
54
- FileUtils.cp("#{ENV["MIGA_HOME"]}/.miga_daemon.json",
55
- "#{path}/daemon/daemon.json") unless
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
 
@@ -1,7 +1,7 @@
1
1
  # @package MiGA
2
2
  # @license Artistic-2.0
3
3
 
4
- require "miga/taxonomy"
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, "biota"
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) ; root.to_tab(unknown) ; end
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? ? "?" : name}" ; end
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
- o = "#{" " * indent}#{tax_str}: #{datasets_count}\n" if
147
- unknown or not datasets.empty? or not name.nil?
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 << "#{" " * indent}# #{ds.name}\n" }
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, 0]
13
+ VERSION = [0.5, 5, 1]
14
14
 
15
15
  ##
16
16
  # Nickname for the current major.minor version.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5.0
4
+ version: 0.5.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R