A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree/printer/table.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
33 #include "genesis/tree/tree.hpp"
34 // #include "genesis/lib/utils/text/table.hpp"
35 
36 #include <assert.h>
37 #include <sstream>
38 #include <vector>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Print Table
45 // =================================================================================================
46 
47 void PrinterTable::print( std::ostream& out, Tree const& tree )
48 {
49  /*
50  // nodes
51  auto node_table = utils::Table();
52  node_table.add_column("Node");
53  node_table.add_column("Main Link").justify(utils::Table::Column::Justification::kRight);
54  node_table.add_column("...");
55 
56  for (size_t i = 0; i < tree.node_count(); ++i) {
57  node_table << std::to_string( i )
58  << std::to_string( tree.node_at(i)->link()->index() )
59  << tree.node_at(i)->dump();
60  }
61  out << utils::simple_layout()(node_table) << "\n";
62  */
63 
64  // nodes
65  for (size_t i = 0; i < tree.node_count(); ++i) {
66  out << "Node " << i << " \t Main Link: " << tree.node_at(i).link().index() << "\n";
67  }
68  out << "\n";
69 
70  // edges
71  for (size_t i = 0; i < tree.edge_count(); ++i) {
72  out << "Edge " << i
73  << " \t Link P: " << tree.edge_at(i).primary_link().index()
74  << " \t Link S: " << tree.edge_at(i).secondary_link().index()
75  << "\n";
76  }
77  out << "\n";
78 
79  // links
80  for (size_t i = 0; i < tree.link_count(); ++i) {
81  out << "Link " << i
82  << " \t Next: " << tree.link_at(i).next().index()
83  << " \t Outer: " << tree.link_at(i).outer().index()
84  << " \t Node: " << tree.link_at(i).node().index()
85  << " \t Edge: " << tree.link_at(i).edge().index()
86  << "\n";
87  }
88 }
89 
90 std::string PrinterTable::print( Tree const& tree )
91 {
92  std::ostringstream res;
93  print( res, tree );
94  return res.str();
95 }
96 
97 } // namespace tree
98 } // namespace genesis
TreeLink & secondary_link()
Return the TreeLink of this TreeEdge that points away from the root.
Definition: edge.hpp:129
size_t index() const
Return the index of this Edge.
Definition: edge.hpp:105
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
Definition: tree/tree.cpp:304
size_t index() const
Return the index of this Node.
Definition: node.hpp:100
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
Definition: tree/tree.cpp:284
size_t node_count() const
Return the number of TreeNodes of the Tree.
Definition: tree/tree.cpp:350
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
TreeLink & link()
Return the TreeLink that points towards the root.
Definition: node.hpp:127
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Definition: tree/tree.cpp:358
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
Definition: tree/tree.cpp:324
void print(std::ostream &out, Tree const &tree)
Header of Tree class.
TreeLink & primary_link()
Return the TreeLink of this TreeEdge that points towards the root.
Definition: edge.hpp:113
size_t link_count() const
Return the number of TreeLinks of the Tree.
Definition: tree/tree.cpp:342