Class: TreeClusters::Attrs
- Inherits:
-
Hash
- Object
- Hash
- TreeClusters::Attrs
- Defined in:
- lib/tree_clusters.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
251 252 253 254 255 256 257 |
# File 'lib/tree_clusters.rb', line 251 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.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/tree_clusters.rb', line 235 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 |