Class: MiGA::TaxIndexTaxon
Overview
Helper class for MiGA::TaxIndex.
Constant Summary
Constants included from MiGA
CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Children of the taxon.
-
#datasets ⇒ Object
readonly
Datasets directly classified at the taxon (not at children).
-
#name ⇒ Object
readonly
Name of the taxon.
-
#rank ⇒ Object
readonly
Rank of the taxon.
Instance Method Summary collapse
-
#add_child(rank, name) ⇒ Object
Add child at
rank
withname
. -
#add_dataset(dataset) ⇒ Object
Add dataset at the current taxon (not children).
-
#all_datasets ⇒ Object
Get all the datasets in the taxon (including children).
-
#datasets_count ⇒ Object
Get the number of datasets in the taxon (including children).
-
#initialize(rank, name) ⇒ TaxIndexTaxon
constructor
Initalize taxon at
rank
withname
. -
#tax_str ⇒ Object
String representation of the taxon.
-
#to_hash ⇒ Object
Hash representation of the taxon.
-
#to_json(*a) ⇒ Object
JSON String of the taxon.
-
#to_tab(unknown, indent = 0) ⇒ Object
Tabular String of the taxon.
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(rank, name) ⇒ TaxIndexTaxon
Initalize taxon at rank
with name
.
93 94 95 96 97 98 |
# File 'lib/miga/tax_index.rb', line 93 def initialize(rank, name) @rank = rank.to_sym @name = (name.nil? ? nil : name.miga_name) @children = [] @datasets = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Children of the taxon.
87 88 89 |
# File 'lib/miga/tax_index.rb', line 87 def children @children end |
#datasets ⇒ Object (readonly)
Datasets directly classified at the taxon (not at children).
89 90 91 |
# File 'lib/miga/tax_index.rb', line 89 def datasets @datasets end |
#name ⇒ Object (readonly)
Name of the taxon.
85 86 87 |
# File 'lib/miga/tax_index.rb', line 85 def name @name end |
#rank ⇒ Object (readonly)
Rank of the taxon.
83 84 85 |
# File 'lib/miga/tax_index.rb', line 83 def rank @rank end |
Instance Method Details
#add_child(rank, name) ⇒ Object
Add child at rank
with name
.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/miga/tax_index.rb', line 106 def add_child(rank, name) rank = rank.to_sym name = name.miga_name unless name.nil? child = children.find { |it| it.rank == rank and it.name == name } if child.nil? child = MiGA::TaxIndexTaxon.new(rank, name) @children << child end child end |
#add_dataset(dataset) ⇒ Object
Add dataset at the current taxon (not children).
119 |
# File 'lib/miga/tax_index.rb', line 119 def add_dataset(dataset) @datasets << dataset; end |
#all_datasets ⇒ Object
Get all the datasets in the taxon (including children).
129 130 131 |
# File 'lib/miga/tax_index.rb', line 129 def all_datasets children.map(&:datasets).reduce(datasets, :+) end |
#datasets_count ⇒ Object
Get the number of datasets in the taxon (including children).
123 124 125 |
# File 'lib/miga/tax_index.rb', line 123 def datasets_count children.map(&:datasets_count).reduce(datasets.size, :+) end |
#tax_str ⇒ Object
String representation of the taxon.
102 |
# File 'lib/miga/tax_index.rb', line 102 def tax_str; "#{rank}:#{name.nil? ? '?' : name}"; end |
#to_hash ⇒ Object
Hash representation of the taxon.
145 146 147 148 149 150 151 |
# File 'lib/miga/tax_index.rb', line 145 def to_hash { str: tax_str, datasets: datasets.map(&:name), children: children.map(&:to_hash) } end |
#to_json(*a) ⇒ Object
JSON String of the taxon.
135 136 137 138 139 140 141 |
# File 'lib/miga/tax_index.rb', line 135 def to_json(*a) { str: tax_str, datasets: datasets.map(&:name), children: children }.to_json(a) end |
#to_tab(unknown, indent = 0) ⇒ Object
Tabular String of the taxon.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/miga/tax_index.rb', line 155 def to_tab(unknown, indent = 0) o = '' if unknown or not datasets.empty? or not name.nil? o = "#{' ' * indent}#{tax_str}: #{datasets_count}\n" end indent += 2 datasets.each { |ds| o << "#{' ' * indent}# #{ds.name}\n" } children.each { |it| o << it.to_tab(unknown, indent) } o end |