Class: Bio::Tree::Node
- Inherits:
-
Object
- Object
- Bio::Tree::Node
- Defined in:
- lib/bio-alignment/tree.rb
Instance Method Summary collapse
-
#alignment ⇒ Object
Return the alignment attached to the tree.
-
#children ⇒ Object
Get the children of this Node.
- #descendents ⇒ Object
-
#distance(other) ⇒ Object
Get the distance to another node.
-
#inject_tree(tree, alignment) ⇒ 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.
- #sequence ⇒ Object
-
#siblings ⇒ Object
Get the direct sibling nodes (i.e. parent.children).
Instance Method Details
#alignment ⇒ Object
Return the alignment attached to the tree
109 110 111 |
# File 'lib/bio-alignment/tree.rb', line 109 def alignment @alignment end |
#children ⇒ Object
Get the children of this Node
54 55 56 |
# File 'lib/bio-alignment/tree.rb', line 54 def children @tree.children(self) end |
#descendents ⇒ Object
58 59 60 |
# File 'lib/bio-alignment/tree.rb', line 58 def descendents @tree.descendents(self) end |
#distance(other) ⇒ Object
Get the distance to another node
84 85 86 |
# File 'lib/bio-alignment/tree.rb', line 84 def distance other @tree.distance(self,other) end |
#inject_tree(tree, alignment) ⇒ Object
Add tree information to this node, so it can be queried
41 42 43 44 45 46 |
# File 'lib/bio-alignment/tree.rb', line 41 def inject_tree tree, alignment @tree = tree @tree.freeze @alignment = alignment self end |
#leaf? ⇒ Boolean
Is this Node a leaf?
49 50 51 |
# File 'lib/bio-alignment/tree.rb', line 49 def leaf? children.size == 0 end |
#leaves ⇒ Object
Return the leaves of this node
73 74 75 |
# File 'lib/bio-alignment/tree.rb', line 73 def leaves @tree.leaves(self) end |
#nearest ⇒ Object
Find the nearest and dearest, i.e. the leafs attached to the parent node
79 80 81 |
# File 'lib/bio-alignment/tree.rb', line 79 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
90 91 92 93 94 95 96 |
# File 'lib/bio-alignment/tree.rb', line 90 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
99 100 101 102 103 104 105 106 |
# File 'lib/bio-alignment/tree.rb', line 99 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
63 64 65 |
# File 'lib/bio-alignment/tree.rb', line 63 def parent @tree.parent(self) end |
#sequence ⇒ Object
113 114 115 |
# File 'lib/bio-alignment/tree.rb', line 113 def sequence @alignment.find(name) end |
#siblings ⇒ Object
Get the direct sibling nodes (i.e. parent.children)
68 69 70 |
# File 'lib/bio-alignment/tree.rb', line 68 def siblings parent.children - [self] end |