A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree/default/functions.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_DEFAULT_FUNCTIONS_H_
2 #define GENESIS_TREE_DEFAULT_FUNCTIONS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 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 
35 
36 #include <set>
37 #include <string>
38 #include <unordered_set>
39 #include <vector>
40 
41 namespace genesis {
42 namespace tree {
43 
44 // =================================================================================================
45 // Forward Declarations
46 // =================================================================================================
47 
48 class Tree;
49 class TreeNode;
50 class TreeSet;
51 
52 // =================================================================================================
53 // Node Names
54 // =================================================================================================
55 
65 std::unordered_set<std::string> node_names(
66  Tree const& tree,
67  bool leaves_only = false
68 );
69 
79 utils::SortedVector<std::string> node_names_sorted(
80  Tree const& tree,
81  bool leaves_only = false
82 );
83 
91 std::unordered_set<std::string> node_names(
92  TreeSet const& tree_set,
93  bool leaves_only = false
94 );
95 
103 utils::SortedVector<std::string> node_names_sorted(
104  TreeSet const& tree_set,
105  bool leaves_only = false
106 );
107 
111 TreeNode const* find_node(
112  Tree const& tree,
113  std::string const& name,
114  bool replace_underscores = false
115 );
116 
120 TreeNode* find_node(
121  Tree& tree,
122  std::string const& name,
123  bool replace_underscores = false
124 );
125 
126 // =================================================================================================
127 // Branch Length
128 // =================================================================================================
129 
133 double length( Tree const& tree );
134 
139 double height( Tree const& tree );
140 
145 double diameter( Tree const& tree );
146 
151 std::vector<double> branch_lengths( Tree const& tree );
152 
159  Tree& tree,
160  double length = 1.0
161 );
162 
170  Tree& tree,
171  double factor = 1.0
172 );
173 
186 Tree average_branch_length_tree( TreeSet const& tset );
187 
188 } // namespace tree
189 } // namespace genesis
190 
191 #endif // include guard
std::unordered_set< std::string > node_names(Tree const &tree, bool leaves_only)
Returns an unordered set of all TreeNode names of a Tree.
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...
utils::SortedVector< std::string > node_names_sorted(Tree const &tree, bool leaves_only)
Returns a set of all TreeNode names of a Tree.
TreeNode const * find_node(Tree const &tree, const std::string &name, bool replace_underscores)
Finds a Node, given its name. If not found, nullptr is returned.
void set_all_branch_lengths(Tree &tree, double length)
Set all branch lengths of a Tree to a given value.
Tree average_branch_length_tree(TreeSet const &tset)
Return a Tree where the branch lengths are the average of the Trees in the TreeSet, given that they all have the same topology.
tree::TreeSet tree_set(SampleSet const &sample_set)
Return a TreeSet containing all the trees of the SampleSet.
Definition: sample_set.cpp:157
double length(Tree const &tree)
Get the length of the tree, i.e., the sum of all 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.
double diameter(Tree const &tree)
Get the diameter of the tree, i.e., the longest distance between any two nodes, measured using the br...
void scale_all_branch_lengths(Tree &tree, double factor)
Scale all branch lengths of a Tree by a given factor.