Class: TreeClusters::Attrs
- Inherits:
-
Hash
- Object
- Hash
- TreeClusters::Attrs
- Defined in:
- lib/tree_clusters/attrs.rb
Overview
A Hash table for genome/leaf/taxa attributes
Instance Method Summary collapse
- #add(leaf, attr, val) ⇒ Object
-
#attrs(leaves, attr) ⇒ AttrArray<Set>
Returns the an AttrArray of Sets for the given genomes and attribute.
Instance Method Details
#add(leaf, attr, val) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/tree_clusters/attrs.rb', line 39 def add leaf, attr, val if self.has_key? leaf self[leaf][attr] = val else self[leaf] = { attr => val } end end |
#attrs(leaves, attr) ⇒ AttrArray<Set>
Note:
If a genome is in the leaves array, but is not in the hash table, NO error will be raised. Rather that genome will be skipped. This is for cases in which not all genomes have attributes.
Returns the an AttrArray of Sets for the given genomes and attribute.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tree_clusters/attrs.rb', line 23 def attrs leaves, attr ary = leaves.map do |leaf| if self.has_key? leaf abort_unless self[leaf].has_key?(attr), "Missing attr #{attr.inspect} for leaf '#{leaf}'" self[leaf][attr] else nil end end.compact TreeClusters::AttrArray.new ary end |