Class: Bio::Tree
- Inherits:
-
Object
- Object
- Bio::Tree
- Defined in:
- lib/bio-alignment/tree.rb
Overview
Here we add to BioRuby’s Bio::Tree classes
Defined Under Namespace
Classes: Node
Instance Method Summary collapse
- #clone ⇒ Object
-
#clone_subtree(start_node) ⇒ Object
Create a deep clone of the tree.
-
#clone_tree_without_branch(node) ⇒ Object
Clone a tree without the branch starting at node.
-
#find(name) ⇒ Object
End of injecting Node functionality.
-
#map ⇒ Object
Walk the ordered tree leaves, calling into the block, and return an array.
Instance Method Details
#clone ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/bio-alignment/tree.rb', line 153 def clone new_tree = self.class.new nodes.each do |x| new_tree.add_node(x) end self.each_edge do |node1, node2, edge| if new_tree.include?(node1) and new_tree.include?(node2) then new_tree.add_edge(node1, node2, edge) end end new_tree end |
#clone_subtree(start_node) ⇒ Object
Create a deep clone of the tree
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/bio-alignment/tree.rb', line 117 def clone_subtree start_node new_tree = self.class.new list = [start_node] + start_node.descendents list.each do |x| new_tree.add_node(x) end each_edge do |node1, node2, edge| if new_tree.include?(node1) and new_tree.include?(node2) new_tree.add_edge(node1, node2, edge) end end new_tree end |
#clone_tree_without_branch(node) ⇒ Object
Clone a tree without the branch starting at node
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/bio-alignment/tree.rb', line 132 def clone_tree_without_branch node new_tree = self.class.new original = [root] + root.descendents # p "Original",original skip = [node] + node.descendents # p "Skip",skip # p "Retain",root.descendents - skip nodes.each do |x| if not skip.include?(x) new_tree.add_node(x) else end end each_edge do |node1, node2, edge| if new_tree.include?(node1) and new_tree.include?(node2) new_tree.add_edge(node1, node2, edge) end end new_tree end |
#find(name) ⇒ Object
End of injecting Node functionality
107 108 109 |
# File 'lib/bio-alignment/tree.rb', line 107 def find name get_node_by_name(name) end |
#map ⇒ Object
Walk the ordered tree leaves, calling into the block, and return an array
112 113 114 |
# File 'lib/bio-alignment/tree.rb', line 112 def map leaves.map { | leaf | yield leaf } end |