Class: Dphil::Tree
Overview
Phylogenetic Tree generated from parsing PAUP output.
Immutable.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #ci ⇒ Object
- #get_children(node) ⇒ Object
- #get_node(id) ⇒ Object
- #get_parent(node) ⇒ Object
-
#initialize(id = nil, lengths = nil, stats = nil, **opts) ⇒ Tree
constructor
A new instance of Tree.
- #root ⇒ Object
- #to_h ⇒ Object
- #tree_length ⇒ Object
Methods included from LDOutput
Constructor Details
#initialize(id = nil, lengths = nil, stats = nil, **opts) ⇒ Tree
Returns a new instance of Tree.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dphil/tree.rb', line 13 def initialize(id = nil, lengths = nil, stats = nil, **opts) @id = (opts[:id] || id).to_i if lengths.respond_to?(:to_str) && stats.respond_to?(:to_str) @nodes = nodes_from_lengths(parse_paup_lengths(lengths)) @stats = parse_paup_stats(stats) elsif (opts.keys & %i[nodes stats]).length == 2 @nodes = parse_json_nodes(opts[:nodes]) @stats = parse_json_stats(opts[:stats]) end @tree = tree_from_nodes(nodes) IceNine.deep_freeze(self) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/dphil/tree.rb', line 11 def id @id end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
11 12 13 |
# File 'lib/dphil/tree.rb', line 11 def nodes @nodes end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
11 12 13 |
# File 'lib/dphil/tree.rb', line 11 def stats @stats end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
11 12 13 |
# File 'lib/dphil/tree.rb', line 11 def tree @tree end |
Instance Method Details
#as_json(options = nil) ⇒ Object
35 36 37 |
# File 'lib/dphil/tree.rb', line 35 def as_json( = nil) to_h.as_json() end |
#ci ⇒ Object
59 60 61 |
# File 'lib/dphil/tree.rb', line 59 def ci stats[:ci] end |
#get_children(node) ⇒ Object
51 52 53 |
# File 'lib/dphil/tree.rb', line 51 def get_children(node) node.children&.map { |id| nodes[id] } end |
#get_node(id) ⇒ Object
43 44 45 |
# File 'lib/dphil/tree.rb', line 43 def get_node(id) nodes[id] end |
#get_parent(node) ⇒ Object
47 48 49 |
# File 'lib/dphil/tree.rb', line 47 def get_parent(node) nodes[node.parent] end |
#root ⇒ Object
39 40 41 |
# File 'lib/dphil/tree.rb', line 39 def root nodes[tree.id] end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/dphil/tree.rb', line 26 def to_h { id: id, root_id: tree.id, nodes: nodes, stats: stats, } end |
#tree_length ⇒ Object
55 56 57 |
# File 'lib/dphil/tree.rb', line 55 def tree_length stats[:length] end |