A library for working with phylogenetic and population genetic data.
v0.27.0
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-2019 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 <cassert>
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
genesis::tree::TreeEdge::primary_link
TreeLink & primary_link()
Return the TreeLink of this TreeEdge that points towards the root.
Definition: edge.hpp:114
genesis::tree::Tree::node_count
size_t node_count() const
Return the number of TreeNodes of the Tree.
Definition: tree/tree.hpp:264
genesis::tree::Tree::link_count
size_t link_count() const
Return the number of TreeLinks of the Tree.
Definition: tree/tree.hpp:256
tree.hpp
Header of Tree class.
genesis::tree::TreeEdge::index
size_t index() const
Return the index of this Edge.
Definition: edge.hpp:106
genesis::tree::Tree::node_at
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
Definition: tree/tree.hpp:220
genesis::tree::Tree::edge_at
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
Definition: tree/tree.hpp:238
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::tree::TreeNode::link
TreeLink & link()
Return the TreeLink that points towards the root.
Definition: tree/tree/node.hpp:129
genesis::tree::PrinterTable::print
void print(std::ostream &out, Tree const &tree)
Definition: tree/printer/table.cpp:47
genesis::tree::Tree::link_at
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
Definition: tree/tree.hpp:202
genesis::tree::TreeNode::index
size_t index() const
Return the index of this Node.
Definition: tree/tree/node.hpp:102
genesis::tree::TreeEdge::secondary_link
TreeLink & secondary_link()
Return the TreeLink of this TreeEdge that points away from the root.
Definition: edge.hpp:130
genesis::tree::Tree::edge_count
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Definition: tree/tree.hpp:272
table.hpp