Class: Bio::Tree::Node

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

Instance Method Summary collapse

Instance Method Details

#alignmentObject

Return the alignment attached to the tree



109
110
111
# File 'lib/bio-alignment/tree.rb', line 109

def alignment
  @alignment
end

#childrenObject

Get the children of this Node



54
55
56
# File 'lib/bio-alignment/tree.rb', line 54

def children
  @tree.children(self)
end

#descendentsObject



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?

Returns:

  • (Boolean)


49
50
51
# File 'lib/bio-alignment/tree.rb', line 49

def leaf?
  children.size == 0
end

#leavesObject

Return the leaves of this node



73
74
75
# File 'lib/bio-alignment/tree.rb', line 73

def leaves
  @tree.leaves(self)
end

#nearestObject

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_childObject

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_childrenObject

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

#parentObject

Get the parents of this Node



63
64
65
# File 'lib/bio-alignment/tree.rb', line 63

def parent
  @tree.parent(self)
end

#sequenceObject



113
114
115
# File 'lib/bio-alignment/tree.rb', line 113

def sequence
  @alignment.find(name)
end

#siblingsObject

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