ʻOhana
Population structure, admixture history, and selection using learning methods.
Public Types | Public Member Functions
jade::basic_rerooted_tree< TValue > Class Template Reference

A template for a class that maintains a list of paths from all leaf nodes to the rerooted node with the name "0". More...

#include <jade.rerooted_tree.hpp>

+ Inheritance diagram for jade::basic_rerooted_tree< TValue >:
+ Collaboration diagram for jade::basic_rerooted_tree< TValue >:

Public Types

typedef TValue value_type
 The value type. More...
 
typedef basic_tree_path< value_typepath_type
 The tree path type. More...
 
typedef basic_newick_node< value_typenode_type
 The Newick node type. More...
 
typedef std::unique_ptr< node_typenode_ptr_type
 The Newick node pointer type. More...
 
typedef std::vector< path_typevector_type
 The tree path vector type. More...
 

Public Member Functions

 basic_rerooted_tree ()
 Initialize a new instance of the class. More...
 
 basic_rerooted_tree (const node_type &node)
 Initialize a new instance of the class. More...
 
size_t get_rk () const
 
path_type get_overlap (const size_t node1, const size_t node2) const
 
const path_typeget_path (const size_t index) const
 
node_typeget_tree ()
 
const node_typeget_tree () const
 
void reset (const node_type &node)
 Resets the tree maintained by this instance. More...
 

Detailed Description

template<typename TValue>
class jade::basic_rerooted_tree< TValue >

A template for a class that maintains a list of paths from all leaf nodes to the rerooted node with the name "0".

Definition at line 19 of file jade.rerooted_tree.hpp.

Member Typedef Documentation

◆ node_ptr_type

template<typename TValue >
typedef std::unique_ptr<node_type> jade::basic_rerooted_tree< TValue >::node_ptr_type

The Newick node pointer type.

Definition at line 32 of file jade.rerooted_tree.hpp.

◆ node_type

template<typename TValue >
typedef basic_newick_node<value_type> jade::basic_rerooted_tree< TValue >::node_type

The Newick node type.

Definition at line 29 of file jade.rerooted_tree.hpp.

◆ path_type

template<typename TValue >
typedef basic_tree_path<value_type> jade::basic_rerooted_tree< TValue >::path_type

The tree path type.

Definition at line 26 of file jade.rerooted_tree.hpp.

◆ value_type

template<typename TValue >
typedef TValue jade::basic_rerooted_tree< TValue >::value_type

The value type.

Definition at line 23 of file jade.rerooted_tree.hpp.

◆ vector_type

template<typename TValue >
typedef std::vector<path_type> jade::basic_rerooted_tree< TValue >::vector_type

The tree path vector type.

Definition at line 35 of file jade.rerooted_tree.hpp.

Constructor & Destructor Documentation

◆ basic_rerooted_tree() [1/2]

template<typename TValue >
jade::basic_rerooted_tree< TValue >::basic_rerooted_tree ( )
inline

Initialize a new instance of the class.

Definition at line 40 of file jade.rerooted_tree.hpp.

41  : _rk (0)
42  , _node_ptr ()
43  , _vector ()
44  {
45  }
+ Here is the caller graph for this function:

◆ basic_rerooted_tree() [2/2]

template<typename TValue >
jade::basic_rerooted_tree< TValue >::basic_rerooted_tree ( const node_type node)
inlineexplicit

Initialize a new instance of the class.

Parameters
nodeThe node to validate and reroot.

Definition at line 50 of file jade.rerooted_tree.hpp.

52  : _rk (_validate_tree(node))
53  , _node_ptr (node.find_name("0")->reroot())
54  , _vector ()
55  {
56  const auto & tree = *_node_ptr;
57 
58  //
59  // Create a list of tree paths, one for each leaf node.
60  //
61  _vector.reserve(_rk);
62  for (size_t i = 1; i <= _rk; i++)
63  {
64  std::ostringstream name_stream;
65  name_stream << i;
66 
67  const auto name = name_stream.str();
68  const auto node_ptr = tree.find_name(name.c_str());
69  _vector.emplace_back(*node_ptr);
70  }
71  }

Member Function Documentation

◆ get_overlap()

template<typename TValue >
path_type jade::basic_rerooted_tree< TValue >::get_overlap ( const size_t  node1,
const size_t  node2 
) const
inline
Returns
The overlapping path between two nodes and the root node.
Parameters
node1The first node.
node2The second node.

Definition at line 84 of file jade.rerooted_tree.hpp.

88  {
89  return _vector[node1] & _vector[node2];
90  }
+ Here is the caller graph for this function:

◆ get_path()

template<typename TValue >
const path_type& jade::basic_rerooted_tree< TValue >::get_path ( const size_t  index) const
inline
Returns
The tree path for the node with the name that corresponds to the specified index.
Parameters
indexThe index of the node.

Definition at line 96 of file jade.rerooted_tree.hpp.

99  {
100  assert(index < _vector.size());
101  return _vector[index];
102  }

◆ get_rk()

template<typename TValue >
size_t jade::basic_rerooted_tree< TValue >::get_rk ( ) const
inline
Returns
The rooted K value.

Definition at line 76 of file jade.rerooted_tree.hpp.

77  {
78  return _rk;
79  }
+ Here is the caller graph for this function:

◆ get_tree() [1/2]

template<typename TValue >
node_type& jade::basic_rerooted_tree< TValue >::get_tree ( )
inline
Returns
A reference to the rerooted tree.

Definition at line 107 of file jade.rerooted_tree.hpp.

108  {
109  return *_node_ptr;
110  }
+ Here is the caller graph for this function:

◆ get_tree() [2/2]

template<typename TValue >
const node_type& jade::basic_rerooted_tree< TValue >::get_tree ( ) const
inline
Returns
A reference to the rerooted tree.

Definition at line 115 of file jade.rerooted_tree.hpp.

116  {
117  return *_node_ptr;
118  }

◆ reset()

template<typename TValue >
void jade::basic_rerooted_tree< TValue >::reset ( const node_type node)
inline

Resets the tree maintained by this instance.

Parameters
nodeThe node to validate and reroot.

Definition at line 123 of file jade.rerooted_tree.hpp.

125  {
126  *this = basic_rerooted_tree(node);
127  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file:
jade::basic_rerooted_tree::basic_rerooted_tree
basic_rerooted_tree()
Initialize a new instance of the class.
Definition: jade.rerooted_tree.hpp:40