Class: MiGA::TaxIndex
Overview
Indexing methods based on taxonomy.
Constant Summary
Constants included from MiGA
CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary collapse
-
#datasets ⇒ Object
readonly
Datasets in the index.
-
#root ⇒ Object
readonly
Taxonomy root.
Instance Method Summary collapse
-
#<<(dataset) ⇒ Object
Index
dataset
, a MiGA::Dataset object. -
#initialize ⇒ TaxIndex
constructor
Initialize an empty MiGA::TaxIndex.
-
#taxa_by_rank(rank) ⇒ Object
Finds all the taxa in the collection at the
rank
taxonomic rank. -
#to_json ⇒ Object
Generate JSON String for the index.
-
#to_tab(unknown = false) ⇒ Object
Generate tabular String for the index.
Methods inherited from MiGA
CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say
Methods included from Common::Path
Methods included from Common::Format
#clean_fasta_file, #seqs_length, #tabulate
Methods included from Common::Net
#download_file_ftp, #known_hosts, #remote_connection
Methods included from Common::SystemCall
Constructor Details
#initialize ⇒ TaxIndex
Initialize an empty MiGA::TaxIndex
19 20 21 22 |
# File 'lib/miga/tax_index.rb', line 19 def initialize @root = MiGA::TaxIndexTaxon.new(:root, 'biota') @datasets = [] end |
Instance Attribute Details
#datasets ⇒ Object (readonly)
Datasets in the index.
13 14 15 |
# File 'lib/miga/tax_index.rb', line 13 def datasets @datasets end |
#root ⇒ Object (readonly)
Taxonomy root.
15 16 17 |
# File 'lib/miga/tax_index.rb', line 15 def root @root end |
Instance Method Details
#<<(dataset) ⇒ Object
Index dataset
, a MiGA::Dataset object.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/miga/tax_index.rb', line 26 def <<(dataset) return nil if dataset.[:tax].nil? taxon = @root MiGA::Taxonomy.KNOWN_RANKS.each do |rank| next if rank == :ns taxon = taxon.add_child(rank, dataset.[:tax][rank]) end taxon.add_dataset dataset @datasets << dataset end |
#taxa_by_rank(rank) ⇒ Object
Finds all the taxa in the collection at the rank
taxonomic rank
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
#to_json ⇒ Object
Generate JSON String for the index.
62 63 64 65 66 67 |
# File 'lib/miga/tax_index.rb', line 62 def to_json MiGA::Json.generate( root: root.to_hash, datasets: datasets.map(&:name) ) end |
#to_tab(unknown = false) ⇒ Object
Generate tabular String for the index.
71 72 73 |
# File 'lib/miga/tax_index.rb', line 71 def to_tab(unknown = false) root.to_tab(unknown) end |