ʻOhana
Population structure, admixture history, and selection using learning methods.
jade.nwk2cov.hpp
1 /* -------------------------------------------------------------------------
2  Ohana
3  Copyright (c) 2015-2020 Jade Cheng (\___/)
4  Jade Cheng <info@jade-cheng.com> (='.'=)
5  ------------------------------------------------------------------------- */
6 
7 #ifndef JADE_NWK2COV_HPP__
8 #define JADE_NWK2COV_HPP__
9 
10 #include "jade.matrix.hpp"
11 #include "jade.rerooted_tree.hpp"
12 
13 namespace jade
14 {
15  ///
16  /// A template for a class that converts Newick-formatted trees to
17  /// covariance matrices.
18  ///
19  template <typename TValue>
21  {
22  public:
23  /// The value type.
24  typedef TValue value_type;
25 
26  /// The Newick node type.
28 
29  /// The matrix type.
31 
32  /// The rerooted tree type.
34 
35  ///
36  /// Executes the program through the specified streams.
37  ///
38  static void execute(
39  std::istream & in, ///< The input stream.
40  std::ostream & out) ///< The output stream.
41  {
42  const newick_node_type node (in);
43  const rerooted_tree_type tree (node);
44 
45  const auto rk = tree.get_rk();
46  matrix_type c (rk, rk);
47 
48  for (size_t i = 0; i < rk; i++)
49  for (size_t j = 0; j <= i; j++)
50  c(i, j) = tree.get_overlap(i, j).get_length();
51 
53 
55  out << c;
56  }
57  };
58 }
59 
60 #endif // JADE_NWK2COV_HPP__
jade::basic_nwk2cov
A template for a class that converts Newick-formatted trees to covariance matrices.
Definition: jade.nwk2cov.hpp:21
jade::basic_rerooted_tree::get_rk
size_t get_rk() const
Definition: jade.rerooted_tree.hpp:76
jade::basic_nwk2cov::execute
static void execute(std::istream &in, std::ostream &out)
Executes the program through the specified streams.
Definition: jade.nwk2cov.hpp:38
jade::basic_nwk2cov::newick_node_type
basic_newick_node< value_type > newick_node_type
The Newick node type.
Definition: jade.nwk2cov.hpp:27
jade::basic_rerooted_tree::get_overlap
path_type get_overlap(const size_t node1, const size_t node2) const
Definition: jade.rerooted_tree.hpp:84
jade::basic_matrix< value_type >::set_high_precision
static void set_high_precision(std::ostream &out)
Sets the specified stream to scientific notation with a high precision.
Definition: jade.matrix.hpp:1154
jade::basic_newick_node
A template class representing a node from a Newick tree.
Definition: jade.newick.hpp:19
jade::basic_tree_path::get_length
value_type get_length() const
Definition: jade.tree_path.hpp:59
jade::basic_nwk2cov::value_type
TValue value_type
The value type.
Definition: jade.nwk2cov.hpp:24
jade::basic_nwk2cov::rerooted_tree_type
basic_rerooted_tree< value_type > rerooted_tree_type
The rerooted tree type.
Definition: jade.nwk2cov.hpp:33
jade::basic_rerooted_tree< value_type >
jade::basic_matrix::copy_lower_to_upper
void copy_lower_to_upper()
Copies the elements in the lower triangle of the square matrix to the corresponding upper triangle el...
Definition: jade.matrix.hpp:266
jade::basic_nwk2cov::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.nwk2cov.hpp:30
jade::basic_matrix< value_type >