Class: TreeClusters::Clade

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_clusters/clade.rb

Overview

Represents a clade in a NewickTree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, tree, metadata = nil) ⇒ Clade

Note:

If a node name is quoted, then those quotes are removed first.

Returns a new instance of Clade.

Parameters:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tree_clusters/clade.rb', line 22

def initialize node, tree,  = nil
  tree_taxa = tree.unquoted_taxa

  @node = node
  @name       = unquote node.name
  @all_leaves = descendant_leaves node

  if (children = node.children).count == 2
    lchild, rchild = node.children

    @left_leaves = descendant_leaves lchild

    @right_leaves = descendant_leaves rchild
  end

  siblings = node.siblings
  # assert siblings.count == 1,
  #        "Node #{node.name} has more than one sibling."

  @each_sibling_leaf_set = siblings.
      map {|node| descendant_leaves node}

  @all_sibling_leaves = @each_sibling_leaf_set.flatten.uniq

  parent = node.parent
  assert parent,
         "Noge #{node.name} has no parent. Is it the root?"
  @parent_leaves = descendant_leaves parent

  @other_leaves =
      Object::Set.new(tree_taxa) - Object::Set.new(all_leaves)

  @non_parent_leaves =
      Object::Set.new(tree_taxa) - Object::Set.new(parent_leaves)

  if 
            = 
    @all_tags        ||= get_all_tags
    @single_tag_info ||= get_single_tag_info
  else
    @single_tag_info = nil
  end
end

Instance Attribute Details

#all_leavesObject

Returns the value of attribute all_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def all_leaves
  @all_leaves
end

#all_sibling_leavesObject

Returns the value of attribute all_sibling_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def all_sibling_leaves
  @all_sibling_leaves
end

#all_tagsObject

Returns the value of attribute all_tags.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def all_tags
  @all_tags
end

#each_sibling_leaf_setObject

Returns the value of attribute each_sibling_leaf_set.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def each_sibling_leaf_set
  @each_sibling_leaf_set
end

#left_leavesObject

Returns the value of attribute left_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def left_leaves
  @left_leaves
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def name
  @name
end

#nodeObject

Returns the value of attribute node.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def node
  @node
end

#non_parent_leavesObject

Returns the value of attribute non_parent_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def non_parent_leaves
  @non_parent_leaves
end

#other_leavesObject

Returns the value of attribute other_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def other_leaves
  @other_leaves
end

#parent_leavesObject

Returns the value of attribute parent_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def parent_leaves
  @parent_leaves
end

#right_leavesObject

Returns the value of attribute right_leaves.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def right_leaves
  @right_leaves
end

#single_tag_infoObject

Returns the value of attribute single_tag_info.



4
5
6
# File 'lib/tree_clusters/clade.rb', line 4

def single_tag_info
  @single_tag_info
end

Instance Method Details

#==(clade) ⇒ Object

Compares two Clades field by field.

If all instance variables are == than the two clades are == as well.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tree_clusters/clade.rb', line 70

def == clade
  (
  self.name == clade.name &&
      self.all_leaves == clade.all_leaves &&
      self.left_leaves == clade.left_leaves &&
      self.right_leaves == clade.right_leaves &&
      self.all_sibling_leaves == clade.all_sibling_leaves &&
      self.each_sibling_leaf_set == clade.each_sibling_leaf_set &&
      self.parent_leaves == clade.parent_leaves &&
      self.other_leaves == clade.other_leaves &&
      self.single_tag_info == clade.single_tag_info &&
      self.all_tags == clade.all_tags
  )
end

#eql?(clade) ⇒ Boolean

Alias for ==

Returns:

  • (Boolean)


86
87
88
# File 'lib/tree_clusters/clade.rb', line 86

def eql? clade
  self == clade
end