Module: MiGA::TaxDist
- Defined in:
- lib/miga/tax_dist.rb
Overview
Methods for taxonomy identification based on AAI/ANI values.
Class Method Summary collapse
-
.aai_path(test) ⇒ Object
Absolute path to the :intax or :novel data file (determined by
test
) for AAI. -
.aai_pvalues(aai, test) ⇒ Object
Returns a Hash, where the keys correspond to the taxonomic level (see MiGA::Taxonomy.LONG_RANKS for the meanings), and the values correspond to the p-values of being :intax or :novel, as determined by
test
. -
.aai_taxtest(aai, test) ⇒ Object
Determines the degree to which a Float
aai
value indicates similar taxonomy (withtest
:intax) or a novel taxon (withtest
:novel).
Class Method Details
.aai_path(test) ⇒ Object
Absolute path to the :intax or :novel data file (determined by test
) for AAI.
15 16 17 18 19 |
# File 'lib/miga/tax_dist.rb', line 15 def self.aai_path(test) test = test.downcase.to_sym return nil unless [:intax, :novel].include? test File.("../_data/aai-#{test}.tsv.gz", __FILE__) end |
.aai_pvalues(aai, test) ⇒ Object
Returns a Hash, where the keys correspond to the taxonomic level (see MiGA::Taxonomy.LONG_RANKS for the meanings), and the values correspond to the p-values of being :intax or :novel, as determined by test
.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/miga/tax_dist.rb', line 24 def self.aai_pvalues(aai, test) Zlib::GzipReader.open(aai_path(test)) do |fh| keys = nil fh.each_line do |ln| row = ln.chomp.split(/\t/) if fh.lineno==1 keys = row[1, row.size-1].map{ |i| i.to_i } elsif row.shift.to_f >= aai vals = {} keys.each do |i| v = row.shift next if v=="NA" rank = i==0 ? :root : MiGA::Taxonomy.KNOWN_RANKS[i-1] vals[rank] = v.to_f end return vals end end # each_line ln end # open fh {} end |
.aai_taxtest(aai, test) ⇒ Object
Determines the degree to which a Float aai
value indicates similar taxonomy (with test
:intax) or a novel taxon (with test
:novel). Returns a Hash with “likelihood” phrases as keys and values as an array with cannonical rank (as in MiGA::Taxonomy) and estimated p-value.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/miga/tax_dist.rb', line 50 def self.aai_taxtest(aai, test) meaning = {most_likely:[0,0.01],probably:[0.01,0.1],possibly_even:[0.1,0.5]} pv = aai_pvalues(aai, test) out = {} meaning.each do |phrase, thresholds| lwr, upr = thresholds min = pv.values.select{ |v| v < upr }.max return out if min.nil? if min >= lwr v = pv.select{ |_,vj| vj==min } out[phrase] = (test==:intax ? v.reverse_each : v).first end end out end |