A library for working with phylogenetic and population genetic data.
v0.27.0
tree_set.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"
35 
37 
38 #include <stdexcept>
39 #include <vector>
40 
41 namespace genesis {
42 namespace tree {
43 
44 // =================================================================================================
45 // Tree Set Functions
46 // =================================================================================================
47 
48 Tree* find_tree( TreeSet& tree_set, std::string const& name )
49 {
50  for( size_t i = 0; i < tree_set.size(); ++i ) {
51  if( tree_set.name_at(i) == name ) {
52  return &tree_set[i];
53  }
54  }
55  return nullptr;
56 }
57 
58 Tree const* find_tree( TreeSet const& tree_set, std::string const& name )
59 {
60  for( size_t i = 0; i < tree_set.size(); ++i ) {
61  if( tree_set.name_at(i) == name ) {
62  return &tree_set[i];
63  }
64  }
65  return nullptr;
66 }
67 
68 // =================================================================================================
69 // Comparators
70 // =================================================================================================
71 
72 bool equal(
73  TreeSet const& tree_set,
74  std::function<bool( TreeNode const&, TreeNode const& )> node_comparator,
75  std::function<bool( TreeEdge const&, TreeEdge const& )> edge_comparator
76 ) {
77  return equal( tree_set.trees(), node_comparator, edge_comparator );
78 }
79 
80 // bool all_equal( TreeSet const& tree_set )
81 // {
82 // // If all pairs of two adjacent trees are equal, all of them are.
83 // // Thus, we do not need a complete pairwise comparision.
84 // for (size_t i = 1; i < tree_set.size(); i++) {
85 // if( ! equal( tree_set[i-1].tree, tree_set[i].tree )) {
86 // return false;
87 // }
88 // }
89 // return true;
90 // }
91 
93 {
94  return identical_topology( tree_set.trees() );
95 }
96 
97 } // namespace tree
98 } // namespace genesis
genesis::tree::find_tree
Tree * find_tree(TreeSet &tree_set, std::string const &name)
Get the first Tree in a TreeSet that is stored with a given name, or nullptr if not found.
Definition: tree_set.cpp:48
genesis::tree::TreeSet::size
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
Definition: tree_set.hpp:228
genesis::placement::tree_set
tree::TreeSet tree_set(SampleSet const &sample_set)
Return a TreeSet containing all the trees of the SampleSet.
Definition: sample_set.cpp:156
tree.hpp
Header of Tree class.
tree_set.hpp
genesis::tree::TreeSet::name_at
std::string const & name_at(size_t index) const
Definition: tree_set.hpp:138
tree_set.hpp
genesis::tree::identical_topology
bool identical_topology(Tree const &lhs, Tree const &rhs, bool identical_indices)
Return whether both trees have an identical topology.
Definition: tree/function/operators.cpp:170
genesis::tree::equal
bool equal(Tree const &lhs, Tree const &rhs, std::function< bool(TreeNode const &, TreeNode const &) > node_comparator, std::function< bool(TreeEdge const &, TreeEdge const &) > edge_comparator)
Compare two trees for equality given binary comparator functionals for their nodes and edges.
Definition: tree/function/operators.cpp:81
genesis::tree::TreeSet
Definition: tree_set.hpp:48
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::tree::TreeEdge
Definition: edge.hpp:60
genesis::tree::TreeNode
Definition: tree/tree/node.hpp:58
genesis::tree::TreeSet::trees
std::vector< Tree > const & trees() const
Definition: tree_set.hpp:198
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
operators.hpp
Tree operator functions.