A toolkit for working with phylogenetic data.
v0.18.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-2017 Lucas Czech
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 
56 std::unordered_set<std::string> node_names(
57  Tree const& tree,
58  bool leaves_only = false
59 );
60 
61 utils::SortedVector<std::string> node_names_sorted(
62  Tree const& tree,
63  bool leaves_only = false
64 );
65 
66 std::unordered_set<std::string> node_names(
67  TreeSet const& tree_set,
68  bool leaves_only = false
69 );
70 
71 utils::SortedVector<std::string> node_names_sorted(
72  TreeSet const& tree_set,
73  bool leaves_only = false
74 );
75 
76 TreeNode const* find_node(
77  Tree const& tree,
78  std::string const& name,
79  bool replace_underscores = false
80 );
81 
82 TreeNode* find_node(
83  Tree& tree,
84  std::string const& name,
85  bool replace_underscores = false
86 );
87 
88 // =================================================================================================
89 // Branch Length
90 // =================================================================================================
91 
92 double length( Tree const& tree );
93 double height( Tree const& tree );
94 double diameter( Tree const& tree );
95 
96 std::vector<double> branch_lengths( Tree const& tree );
97 
99  Tree& tree,
100  double length = 1.0
101 );
102 
104  Tree& tree,
105  double factor = 1.0
106 );
107 
108 } // namespace tree
109 } // namespace genesis
110 
111 #endif // include guard
void set_all_branch_lengths(Tree &tree, double length)
Set all branch lengths of a Tree to a given value.
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...
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 scale_all_branch_lengths(Tree &tree, double factor)
Scale all branch lengths of a Tree by a given factor.
utils::SortedVector< std::string > node_names_sorted(Tree const &tree, bool leaves_only)
Returns a set of all TreeNode names of a Tree.
tree::TreeSet tree_set(SampleSet const &sample_set)
Return a TreeSet containing all the trees of the SampleSet.
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...