class MiGA::TaxIndex

Indexing methods based on taxonomy.

Attributes

datasets[R]

Datasets in the index.

root[R]

Taxonomy root.

Public Class Methods

new() click to toggle source

Initialize an empty MiGA::TaxIndex

# File lib/miga/tax_index.rb, line 20
def initialize
  @root = MiGA::TaxIndexTaxon.new :root, "biota"
  @datasets = []
end

Public Instance Methods

<<(dataset) click to toggle source

Index dataset, a MiGA::Dataset object.

# File lib/miga/tax_index.rb, line 27
def <<(dataset)
  return nil if dataset.metadata[:tax].nil?
  taxon = @root
  MiGA::Taxonomy.KNOWN_RANKS.each do |rank|
    next if rank == :ns
    taxon = taxon.add_child(rank, dataset.metadata[:tax][rank])
  end
  taxon.add_dataset dataset
  @datasets << dataset
end
taxa_by_rank(rank) click to toggle source

Finds all the taxa in the collection at the rank taxonomic rank.

# File lib/miga/tax_index.rb, line 40
def taxa_by_rank(rank)
  rank = MiGA::Taxonomy.normalize_rank(rank)
  taxa = [@root]
  select = []
  loop do
    new_taxa = []
    taxa.map{ |tx| tx.children }.flatten.each do |ch|
      if ch.rank == rank
        select << ch
      elsif not ch.children.empty?
        new_taxa << ch
      end
    end
    break if new_taxa.empty?
  end
  select
end
to_json() click to toggle source

Generate JSON String for the index.

# File lib/miga/tax_index.rb, line 60
def to_json
  MiGA::Json.generate(
    { root: root.to_hash, datasets: datasets.map{ |d| d.name } })
end
to_tab(unknown=false) click to toggle source

Generate tabular String for the index.

# File lib/miga/tax_index.rb, line 67
def to_tab(unknown=false) ; root.to_tab(unknown) ; end