Class: TreeClusters::Clade
- Inherits:
-
Object
- Object
- TreeClusters::Clade
- Defined in:
- lib/tree_clusters.rb
Overview
Represents a clade in a NewickTree
Instance Attribute Summary collapse
-
#all_leaves ⇒ Object
Returns the value of attribute all_leaves.
-
#all_sibling_leaves ⇒ Object
Returns the value of attribute all_sibling_leaves.
-
#all_tags ⇒ Object
Returns the value of attribute all_tags.
-
#each_sibling_leaf_set ⇒ Object
Returns the value of attribute each_sibling_leaf_set.
-
#left_leaves ⇒ Object
Returns the value of attribute left_leaves.
-
#name ⇒ Object
Returns the value of attribute name.
-
#non_parent_leaves ⇒ Object
Returns the value of attribute non_parent_leaves.
-
#other_leaves ⇒ Object
Returns the value of attribute other_leaves.
-
#parent_leaves ⇒ Object
Returns the value of attribute parent_leaves.
-
#right_leaves ⇒ Object
Returns the value of attribute right_leaves.
-
#single_tag_info ⇒ Object
Returns the value of attribute single_tag_info.
Instance Method Summary collapse
-
#==(clade) ⇒ Object
Compares two Clades field by field.
-
#eql?(clade) ⇒ Boolean
Alias for ==.
-
#initialize(node, tree, metadata = nil) ⇒ Clade
constructor
A new instance of Clade.
Constructor Details
#initialize(node, tree, metadata = nil) ⇒ Clade
Returns a new instance of Clade.
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/tree_clusters.rb', line 293 def initialize node, tree, =nil @name = node.name @all_leaves = descendant_leaves node if (children = node.children).count == 2 lchild, rchild = node.children @left_leaves = descendant_leaves lchild @right_leaves = descendant_leaves rchild end siblings = node.siblings # assert siblings.count == 1, # "Node #{node.name} has more than one sibling." @each_sibling_leaf_set = siblings. map { |node| descendant_leaves node } @all_sibling_leaves = @each_sibling_leaf_set.flatten.uniq parent = node.parent assert parent, "Noge #{node.name} has no parent. Is it the root?" @parent_leaves = descendant_leaves parent @other_leaves = Object::Set.new(tree.taxa) - Object::Set.new(all_leaves) @non_parent_leaves = Object::Set.new(tree.taxa) - Object::Set.new(parent_leaves) if @metadata = @all_tags ||= @single_tag_info ||= get_single_tag_info else @single_tag_info = nil end end |
Instance Attribute Details
#all_leaves ⇒ Object
Returns the value of attribute all_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def all_leaves @all_leaves end |
#all_sibling_leaves ⇒ Object
Returns the value of attribute all_sibling_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def all_sibling_leaves @all_sibling_leaves end |
#all_tags ⇒ Object
Returns the value of attribute all_tags.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def @all_tags end |
#each_sibling_leaf_set ⇒ Object
Returns the value of attribute each_sibling_leaf_set.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def each_sibling_leaf_set @each_sibling_leaf_set end |
#left_leaves ⇒ Object
Returns the value of attribute left_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def left_leaves @left_leaves end |
#name ⇒ Object
Returns the value of attribute name.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def name @name end |
#non_parent_leaves ⇒ Object
Returns the value of attribute non_parent_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def non_parent_leaves @non_parent_leaves end |
#other_leaves ⇒ Object
Returns the value of attribute other_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def other_leaves @other_leaves end |
#parent_leaves ⇒ Object
Returns the value of attribute parent_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def parent_leaves @parent_leaves end |
#right_leaves ⇒ Object
Returns the value of attribute right_leaves.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def right_leaves @right_leaves end |
#single_tag_info ⇒ Object
Returns the value of attribute single_tag_info.
279 280 281 |
# File 'lib/tree_clusters.rb', line 279 def single_tag_info @single_tag_info end |
Instance Method Details
#==(clade) ⇒ Object
Compares two Clades field by field.
If all instance variables are == than the two clades are == as well.
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/tree_clusters.rb', line 338 def == clade ( self.name == clade.name && self.all_leaves == clade.all_leaves && self.left_leaves == clade.left_leaves && self.right_leaves == clade.right_leaves && self.all_sibling_leaves == clade.all_sibling_leaves && self.each_sibling_leaf_set == clade.each_sibling_leaf_set && self.parent_leaves == clade.parent_leaves && self.other_leaves == clade.other_leaves && self.single_tag_info == clade.single_tag_info ) end |
#eql?(clade) ⇒ Boolean
Alias for ==
353 354 355 |
# File 'lib/tree_clusters.rb', line 353 def eql? clade self == clade end |