A library for working with phylogenetic and population genetic data.
v0.32.0
tree/common_tree/functions.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_COMMON_TREE_FUNCTIONS_H_
2 #define GENESIS_TREE_COMMON_TREE_FUNCTIONS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <set>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 namespace tree {
40 
41 // =================================================================================================
42 // Forward Declarations
43 // =================================================================================================
44 
45 class Tree;
46 class TreeNode;
47 class TreeSet;
48 
49 // =================================================================================================
50 // Node Names
51 // =================================================================================================
52 
62 std::vector<std::string> node_names(
63  Tree const& tree,
64  bool leaves_only = false
65 );
66 
74 std::vector<std::string> node_names(
75  std::vector<Tree> const& tree_set,
76  bool leaves_only = false
77 );
78 
86 TreeNode const* find_node(
87  Tree const& tree,
88  std::string const& name,
89  bool throw_on_failure = false,
90  bool replace_underscores = false
91 );
92 
98 TreeNode* find_node(
99  Tree& tree,
100  std::string const& name,
101  bool throw_on_failure = false,
102  bool replace_underscores = false
103 );
104 
112 std::vector<TreeNode const*> find_nodes(
113  Tree const& tree,
114  std::vector<std::string> const& node_names,
115  bool throw_on_failure = false,
116  bool replace_underscores = false
117 );
118 
124 std::vector<TreeNode*> find_nodes(
125  Tree& tree,
126  std::vector<std::string> const& node_names,
127  bool throw_on_failure = false,
128  bool replace_underscores = false
129 );
130 
131 // =================================================================================================
132 // Branch Length
133 // =================================================================================================
134 
138 double length( Tree const& tree );
139 
144 double height( Tree const& tree );
145 
150 double diameter( Tree const& tree );
151 
156 std::vector<double> branch_lengths( Tree const& tree );
157 
164  Tree& tree,
165  double length = 1.0
166 );
167 
175  Tree& tree,
176  double factor = 1.0
177 );
178 
191 Tree average_branch_length_tree( std::vector<Tree> const& tset );
192 
193 } // namespace tree
194 } // namespace genesis
195 
196 #endif // include guard
genesis::tree::height
double height(Tree const &tree)
Get the height of the tree, i.e., the longest distance from the root to a leaf, measured using the br...
Definition: tree/common_tree/functions.cpp:169
genesis::tree::node_names
std::vector< std::string > node_names(Tree const &tree, bool leaves_only)
Returns a list of all TreeNode names of a Tree.
Definition: tree/common_tree/functions.cpp:52
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
genesis::tree::length
double length(Tree const &tree)
Get the length of the tree, i.e., the sum of all branch lengths.
Definition: tree/common_tree/functions.cpp:160
genesis::tree::diameter
double diameter(Tree const &tree)
Get the diameter of the tree, i.e., the longest distance between any two nodes, measured using the br...
Definition: tree/common_tree/functions.cpp:178
genesis::tree::branch_lengths
std::vector< double > branch_lengths(Tree const &tree)
Get a vector of all branch lengths of a Tree, index by the edge index.
Definition: tree/common_tree/functions.cpp:213
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::find_nodes
std::vector< TreeNode const * > find_nodes(Tree const &tree, std::vector< std::string > const &node_names, bool throw_on_failure, bool replace_underscores)
Find TreeNodes in a Tree, given their name.
Definition: tree/common_tree/functions.cpp:122
genesis::tree::average_branch_length_tree
Tree average_branch_length_tree(std::vector< Tree > const &tset)
Return a Tree where the branch lengths are the average of the Trees in the given vector of Trees or T...
Definition: tree/common_tree/functions.cpp:242
genesis::tree::find_node
TreeNode const * find_node(Tree const &tree, const std::string &name, bool throw_on_failure, bool replace_underscores)
Finds a Node, given its name.
Definition: tree/common_tree/functions.cpp:84
genesis::tree::scale_all_branch_lengths
void scale_all_branch_lengths(Tree &tree, double factor)
Scale all branch lengths of a Tree by a given factor.
Definition: tree/common_tree/functions.cpp:233
genesis::tree::set_all_branch_lengths
void set_all_branch_lengths(Tree &tree, double length)
Set all branch lengths of a Tree to a given value.
Definition: tree/common_tree/functions.cpp:224