Class: Bio::Tree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-alignment/tree.rb

Instance Method Summary collapse

Instance Method Details

#childrenObject

Get the children of this Node



52
53
54
# File 'lib/bio-alignment/tree.rb', line 52

def children
  @tree.children(self)
end

#descendentsObject



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?

Returns:

  • (Boolean)


47
48
49
# File 'lib/bio-alignment/tree.rb', line 47

def leaf?
  children.size == 0
end

#leavesObject

Return the leaves of this node



71
72
73
# File 'lib/bio-alignment/tree.rb', line 71

def leaves
  @tree.leaves(self)
end

#nearestObject

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_childObject

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_childrenObject

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

#parentObject

Get the parents of this Node



61
62
63
# File 'lib/bio-alignment/tree.rb', line 61

def parent
  @tree.parent(self)
end

#siblingsObject

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