Class: Bio::Tree::Node
- Inherits:
-
Object
- Object
- Bio::Tree::Node
- Defined in:
- lib/bio-alignment/tree.rb
Instance Method Summary collapse
-
#children ⇒ Object
Get the children of this Node.
- #descendents ⇒ Object
-
#distance(other) ⇒ Object
Get the distance to another node.
-
#inject_tree(tree) ⇒ Object
Add tree information to this node, so it can be queried.
-
#leaf? ⇒ Boolean
Is this Node a leaf?.
-
#leaves ⇒ Object
Return the leaves of this node.
-
#nearest ⇒ Object
Find the nearest and dearest, i.e.
-
#nearest_child ⇒ Object
Get child node with the shortest edge - note that if there are more than one, the first will be picked.
-
#nearest_children ⇒ Object
Get the child nodes with the shortest edge - returns an Array.
-
#parent ⇒ Object
Get the parents of this Node.
-
#siblings ⇒ Object
Get the direct sibling nodes (i.e. parent.children).
Instance Method Details
#children ⇒ Object
Get the children of this Node
52 53 54 |
# File 'lib/bio-alignment/tree.rb', line 52 def children @tree.children(self) end |
#descendents ⇒ Object
56 57 58 |
# File 'lib/bio-alignment/tree.rb', line 56 def descendents @tree.descendents(self) end |
#distance(other) ⇒ Object
Get the distance to another node
82 83 84 |
# File 'lib/bio-alignment/tree.rb', line 82 def distance other @tree.distance(self,other) end |
#inject_tree(tree) ⇒ Object
Add tree information to this node, so it can be queried
41 42 43 44 |
# File 'lib/bio-alignment/tree.rb', line 41 def inject_tree tree @tree = tree self end |
#leaf? ⇒ Boolean
Is this Node a leaf?
47 48 49 |
# File 'lib/bio-alignment/tree.rb', line 47 def leaf? children.size == 0 end |
#leaves ⇒ Object
Return the leaves of this node
71 72 73 |
# File 'lib/bio-alignment/tree.rb', line 71 def leaves @tree.leaves(self) end |
#nearest ⇒ Object
Find the nearest and dearest, i.e. the leafs attached to the parent node
77 78 79 |
# File 'lib/bio-alignment/tree.rb', line 77 def nearest @tree.leaves(parent) - [self] end |
#nearest_child ⇒ Object
Get child node with the shortest edge - note that if there are more than one, the first will be picked
88 89 90 91 92 93 94 |
# File 'lib/bio-alignment/tree.rb', line 88 def nearest_child c = nil children.each do |n| c=n if not c or distance(n)<distance(c) end c end |
#nearest_children ⇒ Object
Get the child nodes with the shortest edge - returns an Array
97 98 99 100 101 102 103 104 |
# File 'lib/bio-alignment/tree.rb', line 97 def nearest_children min_distance = distance(nearest_child) cs = [] children.each do |n| cs << n if distance(n) == min_distance end cs end |
#parent ⇒ Object
Get the parents of this Node
61 62 63 |
# File 'lib/bio-alignment/tree.rb', line 61 def parent @tree.parent(self) end |
#siblings ⇒ Object
Get the direct sibling nodes (i.e. parent.children)
66 67 68 |
# File 'lib/bio-alignment/tree.rb', line 66 def siblings parent.children - [self] end |