miga-base 0.4.1.0 → 0.4.2.0

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/bin/miga +2 -244
  3. data/lib/miga/cli/action/about.rb +44 -0
  4. data/lib/miga/cli/action/add.rb +139 -0
  5. data/lib/miga/cli/action/add_result.rb +26 -0
  6. data/lib/miga/cli/action/console.rb +19 -0
  7. data/lib/miga/cli/action/daemon.rb +74 -0
  8. data/lib/miga/cli/action/date.rb +18 -0
  9. data/lib/miga/cli/action/doctor.rb +210 -0
  10. data/lib/miga/cli/action/edit.rb +24 -0
  11. data/lib/miga/cli/action/files.rb +31 -0
  12. data/lib/miga/cli/action/find.rb +48 -0
  13. data/lib/miga/cli/action/generic.rb +44 -0
  14. data/lib/miga/cli/action/get.rb +132 -0
  15. data/lib/miga/cli/action/init.rb +343 -0
  16. data/lib/miga/cli/action/ln.rb +42 -0
  17. data/lib/miga/cli/action/ls.rb +55 -0
  18. data/lib/miga/cli/action/ncbi_get.rb +218 -0
  19. data/lib/miga/cli/action/new.rb +45 -0
  20. data/lib/miga/cli/action/next_step.rb +27 -0
  21. data/lib/miga/cli/action/plugins.rb +28 -0
  22. data/lib/miga/cli/action/rm.rb +25 -0
  23. data/lib/miga/cli/action/run.rb +39 -0
  24. data/lib/miga/cli/action/stats.rb +140 -0
  25. data/lib/miga/cli/action/summary.rb +49 -0
  26. data/lib/miga/cli/action/tax_dist.rb +102 -0
  27. data/lib/miga/cli/action/tax_index.rb +47 -0
  28. data/lib/miga/cli/action/tax_set.rb +59 -0
  29. data/lib/miga/cli/action/tax_test.rb +77 -0
  30. data/lib/miga/cli/action.rb +66 -0
  31. data/lib/miga/cli/base.rb +90 -0
  32. data/lib/miga/cli.rb +426 -0
  33. data/lib/miga/project/result.rb +14 -6
  34. data/lib/miga/remote_dataset.rb +1 -1
  35. data/lib/miga/tax_index.rb +5 -4
  36. data/lib/miga/taxonomy/base.rb +63 -0
  37. data/lib/miga/taxonomy.rb +87 -92
  38. data/lib/miga/version.rb +6 -6
  39. data/test/taxonomy_test.rb +49 -9
  40. data/utils/distance/commands.rb +11 -11
  41. data/utils/distance/pipeline.rb +5 -5
  42. metadata +43 -49
  43. data/actions/about.rb +0 -43
  44. data/actions/add.rb +0 -129
  45. data/actions/add_result.rb +0 -30
  46. data/actions/daemon.rb +0 -55
  47. data/actions/date.rb +0 -14
  48. data/actions/doctor.rb +0 -201
  49. data/actions/edit.rb +0 -33
  50. data/actions/files.rb +0 -43
  51. data/actions/find.rb +0 -41
  52. data/actions/get.rb +0 -105
  53. data/actions/init.rb +0 -301
  54. data/actions/ln.rb +0 -47
  55. data/actions/ls.rb +0 -61
  56. data/actions/ncbi_get.rb +0 -192
  57. data/actions/new.rb +0 -44
  58. data/actions/next_step.rb +0 -33
  59. data/actions/plugins.rb +0 -25
  60. data/actions/rm.rb +0 -29
  61. data/actions/run.rb +0 -45
  62. data/actions/stats.rb +0 -149
  63. data/actions/summary.rb +0 -57
  64. data/actions/tax_dist.rb +0 -106
  65. data/actions/tax_index.rb +0 -46
  66. data/actions/tax_set.rb +0 -63
  67. data/actions/tax_test.rb +0 -80
@@ -0,0 +1,63 @@
1
+ # @package MiGA
2
+ # @license Artistic-2.0
3
+
4
+ class MiGA::Taxonomy < MiGA::MiGA
5
+
6
+ class << self
7
+
8
+ ##
9
+ # Returns cannonical rank (Symbol) for the +rank+ String.
10
+ def normalize_rank(rank)
11
+ return rank.to_sym if @@_KNOWN_RANKS_H[rank.to_sym]
12
+ rank = rank.to_s.downcase
13
+ return nil if rank == 'no rank'
14
+ rank = @@RANK_SYNONYMS[rank] unless @@RANK_SYNONYMS[rank].nil?
15
+ rank = rank.to_sym
16
+ return nil unless @@_KNOWN_RANKS_H[rank]
17
+ rank
18
+ end
19
+
20
+ ##
21
+ # Initialize from JSON-derived Hash +o+.
22
+ def json_create(o)
23
+ new(o['str'], nil, o['alt'])
24
+ end
25
+
26
+ def KNOWN_RANKS() @@KNOWN_RANKS; end
27
+ def LONG_RANKS() @@LONG_RANKS; end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ module MiGA::Taxonomy::Base
34
+
35
+ ##
36
+ # Cannonical ranks.
37
+ @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map { |r| r.to_sym }
38
+ @@_KNOWN_RANKS_H = Hash[ @@KNOWN_RANKS.map { |i| [i, true] } ]
39
+
40
+ ##
41
+ # Long names of the cannonical ranks.
42
+ @@LONG_RANKS = { root: 'root', ns: 'namespace', d: 'domain', k: 'kingdom',
43
+ p: 'phylum', c: 'class', o: 'order', f: 'family', g: 'genus', s: 'species',
44
+ ssp: 'subspecies', str: 'strain', ds: 'dataset' }
45
+
46
+ ##
47
+ # Synonms for cannonical ranks.
48
+ @@RANK_SYNONYMS = {
49
+ 'namespace' => 'ns',
50
+ 'domain' => 'd', 'superkingdom' => 'd',
51
+ 'kingdom' => 'k',
52
+ 'phylum' => 'p',
53
+ 'class' => 'c',
54
+ 'order' => 'o',
55
+ 'family' => 'f',
56
+ 'genus' => 'g',
57
+ 'species' => 's', 'sp' => 's',
58
+ 'subspecies' => 'ssp',
59
+ 'strain' => 'str', 'isolate' => 'str', 'culture' => 'str',
60
+ 'dataset' => 'ds', 'organism' => 'ds', 'genome' => 'ds', 'specimen' => 'ds'
61
+ }
62
+
63
+ end
data/lib/miga/taxonomy.rb CHANGED
@@ -1,60 +1,12 @@
1
1
  # @package MiGA
2
2
  # @license Artistic-2.0
3
3
 
4
+ require 'miga/taxonomy/base'
5
+
4
6
  ##
5
7
  # Taxonomic classifications in MiGA.
6
8
  class MiGA::Taxonomy < MiGA::MiGA
7
- # Class-level
8
-
9
- ##
10
- # Cannonical ranks.
11
- def self.KNOWN_RANKS() @@KNOWN_RANKS ; end
12
- @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map{|r| r.to_sym}
13
- @@_KNOWN_RANKS_H = Hash[ @@KNOWN_RANKS.map{ |i| [i,true] } ]
14
-
15
- ##
16
- # Long names of the cannonical ranks.
17
- def self.LONG_RANKS() @@LONG_RANKS ; end
18
- @@LONG_RANKS = {root: 'root', ns: 'namespace', d: 'domain', k: 'kingdom',
19
- p: 'phylum', c: 'class', o: 'order', f: 'family', g: 'genus', s: 'species',
20
- ssp: 'subspecies', str: 'strain', ds: 'dataset'}
21
-
22
- ##
23
- # Synonms for cannonical ranks.
24
- @@RANK_SYNONYMS = {
25
- 'namespace' => 'ns',
26
- 'domain' => 'd', 'superkingdom' => 'd',
27
- 'kingdom' => 'k',
28
- 'phylum' => 'p',
29
- 'class' => 'c',
30
- 'order' => 'o',
31
- 'family' => 'f',
32
- 'genus' => 'g',
33
- 'species' => 's', 'sp' => 's',
34
- 'subspecies' => 'ssp',
35
- 'strain' => 'str', 'isolate' => 'str', 'culture' => 'str',
36
- 'dataset' => 'ds', 'organism' => 'ds', 'genome' => 'ds', 'specimen' => 'ds'
37
- }
38
-
39
- ##
40
- # Initialize from JSON-derived Hash +o+.
41
- def self.json_create(o)
42
- new(o['str'], nil, o['alt'])
43
- end
44
-
45
- ##
46
- # Returns cannonical rank (Symbol) for the +rank+ String.
47
- def self.normalize_rank(rank)
48
- return rank.to_sym if @@_KNOWN_RANKS_H[rank.to_sym]
49
- rank = rank.to_s.downcase
50
- return nil if rank == 'no rank'
51
- rank = @@RANK_SYNONYMS[rank] unless @@RANK_SYNONYMS[rank].nil?
52
- rank = rank.to_sym
53
- return nil unless @@_KNOWN_RANKS_H[rank]
54
- rank
55
- end
56
-
57
- # Instance-level
9
+ include MiGA::Taxonomy::Base
58
10
 
59
11
  ##
60
12
  # Taxonomic hierarchy Hash.
@@ -69,46 +21,47 @@ class MiGA::Taxonomy < MiGA::MiGA
69
21
  # String, Array, or Hash entries as defined above (except +ranks+ are not
70
22
  # allowed).
71
23
  def initialize(str, ranks = nil, alt = [])
24
+ reset(str, ranks)
25
+ @alt = (alt || []).map { |i| Taxonomy.new(i) }
26
+ end
27
+
28
+ ##
29
+ # Reset ranks (including namespace) while leaving alternatives untouched.
30
+ # See #initialize for +str+ and +ranks+.
31
+ def reset(str, ranks = nil)
72
32
  @ranks = {}
73
33
  if ranks.nil?
74
- case str when Array, Hash
75
- self << str
76
- else
77
- "#{str} ".scan(/([A-Za-z]+):([^:]*)( )/){ |r,n,_| self << {r=>n} }
78
- end
34
+ initialize_by_str(str)
79
35
  else
80
- ranks = ranks.split(/\s+/) unless ranks.is_a? Array
81
- str = str.split(/\s+/) unless str.is_a? Array
82
- raise "Unequal number of ranks (#{ranks.size}) " +
83
- "and names (#{str.size}):#{ranks} => #{str}" unless
84
- ranks.size==str.size
85
- (0 .. str.size).each{ |i| self << "#{ranks[i]}:#{str[i]}" }
36
+ initialize_by_ranks(str, ranks)
86
37
  end
87
- @alt = (alt || []).map { |i| Taxonomy.new(i) }
38
+ initialize_by_str(str)
88
39
  end
89
-
40
+
90
41
  ##
91
42
  # Add +value+ to the hierarchy, that can be an Array, a String, or a Hash, as
92
43
  # described in #initialize.
93
44
  def <<(value)
94
- if value.is_a? Hash
95
- value.each_pair do |rank_i, name_i|
96
- next if name_i.nil? or name_i == ""
97
- @ranks[ Taxonomy.normalize_rank rank_i ] = name_i.tr('_',' ')
45
+ case value
46
+ when Hash
47
+ value.each do |r, n|
48
+ next if n.nil? || n == ''
49
+ @ranks[self.class.normalize_rank(r)] = n.tr('_', ' ')
98
50
  end
99
- elsif value.is_a? Array
100
- value.each{ |v| self << v }
101
- elsif value.is_a? String
102
- (rank, name) = value.split(/:/)
103
- self << { rank => name }
51
+ when Array
52
+ value.each { |v| self << v }
53
+ when String
54
+ self << Hash[*value.split(':', 2)]
104
55
  else
105
- raise "Unsupported class: #{value.class.name}."
56
+ raise 'Unsupported class: ' + value.class.name
106
57
  end
107
58
  end
108
-
59
+
109
60
  ##
110
61
  # Get +rank+ value.
111
- def [](rank) @ranks[ rank.to_sym ] ; end
62
+ def [](rank)
63
+ @ranks[rank.to_sym]
64
+ end
112
65
 
113
66
  ##
114
67
  # Get the alternative taxonomies.
@@ -126,17 +79,38 @@ class MiGA::Taxonomy < MiGA::MiGA
126
79
  when Integer
127
80
  ([self] + @alt)[which]
128
81
  else
129
- ([self] + @alt).find{ |i| i.namespace.to_s == which.to_s }
82
+ ([self] + @alt).find { |i| i.namespace.to_s == which.to_s }
130
83
  end
131
84
  end
132
-
85
+
86
+ ##
87
+ # Add an alternative taxonomy. If the namespace matches an existing namespace,
88
+ # the alternative (or master) is replaced instead if +replace+ is true.
89
+ def add_alternative(tax, replace = true)
90
+ raise 'Unsupported taxonomy class.' unless tax.is_a? MiGA::Taxonomy
91
+ alt_ns = alternative(tax.namespace)
92
+ if !replace || tax.namespace.nil? || alt_ns.nil?
93
+ @alt << tax
94
+ else
95
+ alt_ns.reset(tax.to_s)
96
+ end
97
+ end
98
+
99
+ ##
100
+ # Removes (and returns) all alternative taxonomies.
101
+ def delete_alternative
102
+ alt = @alt.dup
103
+ @alt = []
104
+ alt
105
+ end
106
+
133
107
  ##
134
108
  # Evaluates if the loaded taxonomy includes +taxon+. It assumes that +taxon+
135
109
  # only has one informative rank. The evaluation is case-insensitive.
136
- def is_in? taxon
110
+ def in?(taxon)
137
111
  r = taxon.ranks.keys.first
138
- return false if self[ r ].nil?
139
- self[ r ].downcase == taxon[ r ].downcase
112
+ return false if self[r].nil?
113
+ self[r].casecmp(taxon[r]).zero?
140
114
  end
141
115
 
142
116
  ##
@@ -145,22 +119,24 @@ class MiGA::Taxonomy < MiGA::MiGA
145
119
  # If +with_namespace+ is true, it includes also the namespace.
146
120
  def sorted_ranks(force_ranks = false, with_namespace = false)
147
121
  @@KNOWN_RANKS.map do |r|
148
- next if r == :ns and not with_namespace
149
- next if ranks[r].nil? and not force_ranks
122
+ next if
123
+ (r == :ns && !with_namespace) || (ranks[r].nil? && !force_ranks)
150
124
  [r, ranks[r]]
151
125
  end.compact
152
126
  end
153
127
 
154
128
  ##
155
129
  # Namespace of the taxonomy (a String) or +nil+.
156
- def namespace; self[ :ns ] ; end
157
-
130
+ def namespace
131
+ self[:ns]
132
+ end
133
+
158
134
  ##
159
135
  # Get the most general rank as a two-entry Array (rank and value).
160
136
  # If +force_ranks+ is true, it always returns the value for domain (d)
161
137
  # even if undefined.
162
138
  def highest(force_ranks = false)
163
- sorted_ranks.first
139
+ sorted_ranks(force_ranks).first
164
140
  end
165
141
 
166
142
  ##
@@ -170,21 +146,40 @@ class MiGA::Taxonomy < MiGA::MiGA
170
146
  def lowest(force_ranks = false)
171
147
  sorted_ranks(force_ranks).last
172
148
  end
173
-
149
+
174
150
  ##
175
151
  # Generate cannonical String for the taxonomy. If +force_ranks+ is true,
176
152
  # it returns all the standard ranks even if undefined.
177
153
  def to_s(force_ranks = false)
178
- sorted_ranks(force_ranks, true).
179
- map{ |r| "#{r[0]}:#{(r[1] || '').gsub(/[\s:]/, '_')}" }.join(' ')
154
+ sorted_ranks(force_ranks, true)
155
+ .map { |r| "#{r[0]}:#{(r[1] || '').gsub(/[\s:]/, '_')}" }.join(' ')
180
156
  end
181
-
157
+
182
158
  ##
183
159
  # Generate JSON-formated String representing the taxonomy.
184
160
  def to_json(*a)
185
- hsh = { JSON.create_id => self.class.name, 'str' => self.to_s }
161
+ hsh = { JSON.create_id => self.class.name, 'str' => to_s }
186
162
  hsh['alt'] = alternative.map(&:to_s) unless alternative.empty?
187
163
  hsh.to_json(*a)
188
164
  end
189
-
165
+
166
+ private
167
+
168
+ def initialize_by_str(str)
169
+ case str
170
+ when Array, Hash
171
+ self << str
172
+ else
173
+ "#{str} ".scan(/([A-Za-z]+):([^:]*)( )/) { |r, n, _| self << { r => n } }
174
+ end
175
+ end
176
+
177
+ def initialize_by_ranks(str, ranks)
178
+ ranks = ranks.split(/\s+/) unless ranks.is_a? Array
179
+ str = str.split(/\s+/) unless str.is_a? Array
180
+ unless ranks.size == str.size
181
+ raise "Unequal number of ranks and names: #{ranks} => #{str}"
182
+ end
183
+ str.each_with_index { |i, k| self << "#{ranks[k]}:#{i}" }
184
+ end
190
185
  end
data/lib/miga/version.rb CHANGED
@@ -4,22 +4,22 @@ require 'date'
4
4
  ##
5
5
  # High-level minimal requirements for the MiGA::MiGA class.
6
6
  module MiGA
7
-
7
+
8
8
  ##
9
9
  # Current version of MiGA. An Array with three values:
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.4, 1, 0]
14
-
13
+ VERSION = [0.4, 2, 0]
14
+
15
15
  ##
16
16
  # Nickname for the current major.minor version.
17
17
  VERSION_NAME = 'aquatint'
18
-
18
+
19
19
  ##
20
20
  # Date of the current gem release.
21
- VERSION_DATE = Date.new(2019, 8, 17)
22
-
21
+ VERSION_DATE = Date.new(2019, 9, 8)
22
+
23
23
  ##
24
24
  # Reference of MiGA.
25
25
  CITATION = 'Rodriguez-R et al (2018). ' \
@@ -1,5 +1,5 @@
1
- require "test_helper"
2
- require "miga/taxonomy"
1
+ require 'test_helper'
2
+ require 'miga/taxonomy'
3
3
 
4
4
  class TaxonomyTest < Test::Unit::TestCase
5
5
 
@@ -40,23 +40,32 @@ class TaxonomyTest < Test::Unit::TestCase
40
40
  tx << { :genus => "v3" }
41
41
  assert_equal("v3", tx[:g])
42
42
  tx << "s:v3_0"
43
- assert(tx.is_in? MiGA::Taxonomy.new("species:v3_0"))
43
+ assert(tx.in? MiGA::Taxonomy.new("species:v3_0"))
44
44
  assert_raise(RuntimeError) { tx << 123 }
45
45
  end
46
46
 
47
47
  def test_init_methods
48
- tx = MiGA::Taxonomy.new({:k=>"Mascot", :c=>"Cereal", :s=>"Melvin"})
49
- assert_equal("k:Mascot c:Cereal s:Melvin", tx.to_s)
50
- tx = MiGA::Taxonomy.new("Mascot College Buzz", "k c s")
51
- assert_equal("k:Mascot c:College s:Buzz", tx.to_s)
48
+ tx = MiGA::Taxonomy.new({k: 'Mascot', c: 'Cereal', s: 'Melvin'})
49
+ assert_equal('k:Mascot c:Cereal s:Melvin', tx.to_s)
50
+ tx = MiGA::Taxonomy.new('Mascot College Buzz', 'k c s')
51
+ assert_equal('k:Mascot c:College s:Buzz', tx.to_s)
52
52
  assert_raise do
53
- tx = MiGA::Taxonomy.new("Mascot State Georgia Peach", "k c s")
53
+ tx = MiGA::Taxonomy.new('Mascot State Georgia Peach', 'k c s')
54
54
  end
55
55
  end
56
56
 
57
- def test_alt
57
+ def test_rank_order
58
+ tx = MiGA::Taxonomy.new({k: 'Mascot', s: 'Melvin', c: 'Cereal'})
59
+ assert_equal([:d, nil], tx.highest(true))
60
+ assert_equal([:k, 'Mascot'], tx.highest)
61
+ assert_equal([:ds, nil], tx.lowest(true))
62
+ assert_equal([:s, 'Melvin'], tx.lowest)
63
+ end
64
+
65
+ def test_alternative
58
66
  tx = MiGA::Taxonomy.new('ns:a s:Arnie', nil,
59
67
  ['ns:b s:Bernie','ns:c s:Cornie','s:Darnie'])
68
+ # Fields
60
69
  assert_equal('ns:a s:Arnie', tx.to_s)
61
70
  assert_equal([[:s, 'Arnie']], tx.sorted_ranks)
62
71
  assert_equal('ns:a s:Arnie', tx.alternative(0).to_s)
@@ -65,11 +74,42 @@ class TaxonomyTest < Test::Unit::TestCase
65
74
  assert_equal('s:Darnie', tx.alternative('').to_s)
66
75
  assert_nil(tx.alternative(:x))
67
76
  assert_equal(3, tx.alternative.size)
77
+ # JSON
68
78
  js = tx.to_json
69
79
  tx_js = JSON.parse(js, {symbolize_names: false, create_additions: true})
70
80
  assert_equal(tx.to_s, tx_js.to_s)
71
81
  assert_equal(tx.alternative(2).to_s, tx_js.alternative(2).to_s)
72
82
  assert_equal(tx.alternative.size, tx_js.alternative.size)
83
+ # Add
84
+ tx.add_alternative(tx.alternative(3))
85
+ assert_equal(4, tx.alternative.size)
86
+ tx.add_alternative(tx.alternative(2))
87
+ assert_equal(4, tx.alternative.size)
88
+ # Delete
89
+ alt = tx.delete_alternative
90
+ assert_equal(4, alt.size)
91
+ assert(tx.alternative.empty?)
92
+ end
93
+
94
+ def test_reset
95
+ tx = MiGA::Taxonomy.new('ns:Letters d:Latin s:A', nil,
96
+ ['ns:Words d:English s:A', 'ns:Music d:Tone s:A'])
97
+ # Reset
98
+ assert_equal(2, tx.alternative.size)
99
+ assert_equal('Letters', tx.namespace)
100
+ tx.reset('g:A')
101
+ assert_equal(2, tx.alternative.size)
102
+ assert_nil(tx.namespace)
103
+ tx.reset('ns:Letters d:Latin s:A')
104
+ assert_equal('Letters', tx.namespace)
105
+ # Change of alternative
106
+ assert_equal('ns:Words d:English s:A', tx.alternative('Words').to_s)
107
+ tx.add_alternative(MiGA::Taxonomy.new('ns:Words d:Spanish s:A'))
108
+ assert_equal('ns:Words d:Spanish s:A', tx.alternative('Words').to_s)
109
+ # Change of master
110
+ assert_equal('ns:Letters d:Latin s:A', tx.to_s)
111
+ tx.add_alternative(MiGA::Taxonomy.new('ns:Letters d:Unicode s:A'))
112
+ assert_equal('ns:Letters d:Unicode s:A', tx.to_s)
73
113
  end
74
114
 
75
115
  end
@@ -3,14 +3,14 @@ module MiGA::DistanceRunner::Commands
3
3
  # Estimates or calculates AAI against +target+
4
4
  def aai(target)
5
5
  # Check if the request makes sense
6
- return nil if target.nil? or target.result(:essential_genes).nil?
6
+ return nil if target.nil? || target.result(:essential_genes).nil?
7
7
  # Check if it's been calculated
8
8
  y = stored_value(target, :aai)
9
- return y unless y.nil? or y.zero?
9
+ return y unless y.nil? || y.zero?
10
10
  # Try hAAI (except in clade projects)
11
11
  unless @ref_project.is_clade?
12
12
  y = haai(target)
13
- return y unless y.nil? or y.zero?
13
+ return y unless y.nil? || y.zero?
14
14
  end
15
15
  # Full AAI
16
16
  aai_cmd(
@@ -27,10 +27,10 @@ module MiGA::DistanceRunner::Commands
27
27
  dataset.name, target.name, tmp_dbs[:haai],
28
28
  aai_save_rbm: 'no-save-rbm', aai_p: opts[:haai_p])
29
29
  checkpoint :haai
30
- return nil if haai.nil? or haai.zero? or haai > 90.0
30
+ return nil if haai.nil? || haai.zero? || haai > 90.0
31
31
  aai = 100.0 - Math.exp(2.435076 + 0.4275193*Math.log(100.0-haai))
32
32
  SQLite3::Database.new(tmp_dbs[:aai]) do |conn|
33
- conn.execute "insert into aai values(?, ?, ?, 0, 0, 0)",
33
+ conn.execute 'insert into aai values(?, ?, ?, 0, 0, 0)',
34
34
  [dataset.name, target.name, aai]
35
35
  end
36
36
  checkpoint :aai
@@ -43,10 +43,10 @@ module MiGA::DistanceRunner::Commands
43
43
  # Check if the request makes sense
44
44
  t = tmp_file('largecontigs.fa')
45
45
  r = target.result(:assembly)
46
- return nil if r.nil? or !File.size?(t)
46
+ return nil if r.nil? || !File.size?(t)
47
47
  # Check if it's been calculated
48
48
  y = stored_value(target, :ani)
49
- return y unless y.nil? or y.zero?
49
+ return y unless y.nil? || y.zero?
50
50
  # Run it
51
51
  ani_cmd(
52
52
  t, r.file_path(:largecontigs),
@@ -58,7 +58,7 @@ module MiGA::DistanceRunner::Commands
58
58
  # Returns +nil+ otherwise
59
59
  def ani_after_aai(target, aai_limit = 85.0)
60
60
  aai = aai(target)
61
- (aai.nil? or aai < aai_limit) ? nil : ani(target)
61
+ (aai.nil? || aai < aai_limit) ? nil : ani(target)
62
62
  end
63
63
 
64
64
  ##
@@ -69,7 +69,7 @@ module MiGA::DistanceRunner::Commands
69
69
  --name1 "#{n1}" --name2 "#{n2}" \
70
70
  -t "#{o[:thr]}" -a --lookup-first "--#{o[:aai_save_rbm]}" \
71
71
  -p "#{o[:aai_p] || "blast+"}"`.chomp
72
- (v.nil? or v.empty?) ? 0 : v.to_f
72
+ (v.nil? || v.empty?) ? 0 : v.to_f
73
73
  end
74
74
 
75
75
  ##
@@ -82,7 +82,7 @@ module MiGA::DistanceRunner::Commands
82
82
  -o /dev/stdout 2>/dev/null`.chomp.split(/\s+/)
83
83
  unless out.empty?
84
84
  SQLite3::Database.new(db) do |conn|
85
- conn.execute "insert into ani values(?, ?, ?, 0, ?, ?)",
85
+ conn.execute 'insert into ani values(?, ?, ?, 0, ?, ?)',
86
86
  [n1, n2, out[2], out[3], out[4]]
87
87
  end
88
88
  end
@@ -93,6 +93,6 @@ module MiGA::DistanceRunner::Commands
93
93
  -t "#{opts[:thr]}" -a --no-save-regions --no-save-rbm \
94
94
  --lookup-first -p "#{o[:ani_p] || "blast+"}"`.chomp
95
95
  end
96
- v.nil? or v.empty? ? 0 : v.to_f
96
+ v.nil? || v.empty? ? 0 : v.to_f
97
97
  end
98
98
  end
@@ -6,13 +6,13 @@ module MiGA::DistanceRunner::Pipeline
6
6
  # classification and cluster number
7
7
  def classify(clades, classif, metric, result_fh, val_cls=nil)
8
8
  dir = File.expand_path(classif, clades)
9
- med = File.expand_path("miga-project.medoids", dir)
9
+ med = File.expand_path('miga-project.medoids', dir)
10
10
  return [classif,val_cls] unless File.size? med
11
11
  max_val = 0
12
- val_med = ""
12
+ val_med = ''
13
13
  val_cls = nil
14
14
  i_n = 0
15
- File.open(med, "r") do |med_fh|
15
+ File.open(med, 'r') do |med_fh|
16
16
  med_fh.each_line do |med_ln|
17
17
  i_n += 1
18
18
  med_ln.chomp!
@@ -36,7 +36,7 @@ module MiGA::DistanceRunner::Pipeline
36
36
  return unless File.size? db
37
37
  out_base = File.expand_path(dataset.name, home)
38
38
  ds_matrix = "#{out_base}.txt"
39
- ds_matrix_fh = File.open(ds_matrix, "w")
39
+ ds_matrix_fh = File.open(ds_matrix, 'w')
40
40
  ds_matrix_fh.puts %w[a b value].join("\t")
41
41
  # Find all values in the database
42
42
  seq2 = []
@@ -54,7 +54,7 @@ module MiGA::DistanceRunner::Pipeline
54
54
  end
55
55
  end
56
56
  ds_matrix_fh.close
57
- ref_tree = File.expand_path("utils/ref-tree.R", MiGA::MiGA.root_path)
57
+ ref_tree = File.expand_path('utils/ref-tree.R', MiGA::MiGA.root_path)
58
58
  `"#{ref_tree}" "#{ds_matrix}" "#{out_base}" "#{dataset.name}"`
59
59
  File.unlink ds_matrix
60
60
  end