Indexing methods based on taxonomy.
Datasets in the index.
Taxonomy root.
Initialize an empty MiGA::TaxIndex
# File lib/miga/tax_index.rb, line 19 def initialize @root = MiGA::TaxIndexTaxon.new(:root, 'biota') @datasets = [] end
Index dataset
, a MiGA::Dataset
object.
# File lib/miga/tax_index.rb, line 26 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
Finds all the taxa in the collection at the rank
taxonomic
rank
# File lib/miga/tax_index.rb, line 41 def taxa_by_rank(rank) rank = MiGA::Taxonomy.normalize_rank(rank) taxa = [@root] select = [] loop do new_taxa = [] taxa.map(&:children).flatten.each do |ch| if ch.rank == rank select << ch elsif !ch.children.empty? new_taxa << ch end end taxa = new_taxa break if taxa.empty? end select end
Generate JSON String for the index.
# File lib/miga/tax_index.rb, line 62 def to_json MiGA::Json.generate( root: root.to_hash, datasets: datasets.map(&:name) ) end
Generate tabular String for the index.
# File lib/miga/tax_index.rb, line 71 def to_tab(unknown = false) root.to_tab(unknown) end