A library for working with phylogenetic and population genetic data.
v0.32.0
tree/mass_tree/functions.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_FUNCTIONS_H_
2 #define GENESIS_TREE_MASS_TREE_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 
34 #include <cstddef>
35 #include <utility>
36 #include <vector>
37 
38 namespace genesis {
39 
40 // =================================================================================================
41 // Forward Declarations
42 // =================================================================================================
43 
44 namespace utils {
45 
46  template<typename T>
47  class Matrix;
48 
49 }
50 
51 namespace tree {
52 
53  class Tree;
54  class TreeSet;
55  class TreeNode;
56  class TreeEdge;
57 
58  using MassTree = Tree;
59 
60 }
61 
62 namespace tree {
63 
64 // =================================================================================================
65 // Manipulate Masses
66 // =================================================================================================
67 
78  MassTree const& lhs,
79  MassTree const& rhs,
80  double const scaler_lhs = 1.0,
81  double const scaler_rhs = 1.0
82 );
83 
95  MassTree& lhs,
96  MassTree const& rhs,
97  double const scaler_lhs = 1.0,
98  double const scaler_rhs = 1.0
99 );
100 
104 void mass_tree_clear_masses( MassTree& tree );
105 
109 void mass_tree_reverse_signs( MassTree& tree );
110 
114 void mass_tree_scale_masses( MassTree& tree, double factor );
115 
120 
126 
136 
147 
170 double mass_tree_binify_masses( MassTree& tree, size_t number_of_bins );
171 
172 // =================================================================================================
173 // Others
174 // =================================================================================================
175 
183 void mass_trees_make_average_branch_lengths( std::vector<MassTree>& mass_trees );
184 
191 std::vector<double> mass_tree_mass_per_edge( MassTree const& tree );
192 
201 utils::Matrix<double> mass_tree_mass_per_edge( std::vector<MassTree> const& mass_trees );
202 
211 std::vector<std::pair<double, double>> mass_tree_mass_per_edge_averaged( MassTree const& tree );
212 
223 double mass_tree_sum_of_masses( MassTree const& tree );
224 
246 bool mass_tree_validate( MassTree const& tree, double valid_total_mass_difference = -1.0);
247 
248 } // namespace tree
249 } // namespace genesis
250 
251 #endif // include guard
genesis::tree::mass_tree_merge_trees
MassTree mass_tree_merge_trees(MassTree const &lhs, MassTree const &rhs, double const scaler_lhs, double const scaler_rhs)
Merge all masses of two MassTrees into one and return it.
Definition: tree/mass_tree/functions.cpp:60
genesis::tree::mass_tree_center_masses_on_branches_averaged
double mass_tree_center_masses_on_branches_averaged(MassTree &tree)
Accumulate all masses of a MassTree at the average mass position per edge.
Definition: tree/mass_tree/functions.cpp:181
genesis::tree::MassTree
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Definition: placement/function/operators.hpp:54
genesis::tree::mass_tree_validate
bool mass_tree_validate(MassTree const &tree, double valid_total_mass_difference)
Validate the data on a MassTree.
Definition: tree/mass_tree/functions.cpp:423
genesis::tree::mass_tree_transform_to_unit_branch_lengths
void mass_tree_transform_to_unit_branch_lengths(MassTree &tree)
Set all branch lengths of a MassTree to 1.0, while keeping the relative position of all masses on the...
Definition: tree/mass_tree/functions.cpp:142
genesis::tree::mass_tree_reverse_signs
void mass_tree_reverse_signs(MassTree &tree)
Reverse the sign of each mass point on a MassTree.
Definition: tree/mass_tree/functions.cpp:104
genesis::tree::mass_tree_binify_masses
double mass_tree_binify_masses(MassTree &tree, size_t number_of_bins)
Accumulate all masses of a MassTree into bins on each branch.
Definition: tree/mass_tree/functions.cpp:222
genesis::tree::mass_tree_scale_masses
void mass_tree_scale_masses(MassTree &tree, double factor)
Scale all masses of a MassTree with the multiplicative factor factor.
Definition: tree/mass_tree/functions.cpp:115
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::mass_tree_merge_trees_inplace
void mass_tree_merge_trees_inplace(MassTree &lhs, MassTree const &rhs, double const scaler_lhs, double const scaler_rhs)
Merge all masses of two MassTrees by adding them to the first MassTree.
Definition: tree/mass_tree/functions.cpp:71
genesis::tree::mass_tree_center_masses_on_branches
double mass_tree_center_masses_on_branches(MassTree &tree)
Accumulate all masses of a MassTree on the centers of their edges.
Definition: tree/mass_tree/functions.cpp:158
genesis::tree::mass_tree_mass_per_edge
std::vector< double > mass_tree_mass_per_edge(MassTree const &tree)
Return a std::vector that contains the total mass for each edge of the given MassTree.
Definition: tree/mass_tree/functions.cpp:337
genesis::tree::mass_tree_sum_of_masses
double mass_tree_sum_of_masses(MassTree const &tree)
Return the total sum of all masses on the MassTree.
Definition: tree/mass_tree/functions.cpp:412
genesis::tree::mass_tree_normalize_masses
void mass_tree_normalize_masses(MassTree &tree)
Scale all masses of a MassTree so that they sum up to 1.0.
Definition: tree/mass_tree/functions.cpp:126
genesis::tree::mass_trees_make_average_branch_lengths
void mass_trees_make_average_branch_lengths(std::vector< MassTree > &mass_trees)
Change the branch lengths of all trees to their average, and move the masses accordingly in a proport...
Definition: tree/mass_tree/functions.cpp:271
genesis::tree::mass_tree_mass_per_edge_averaged
std::vector< std::pair< double, double > > mass_tree_mass_per_edge_averaged(MassTree const &tree)
Return a std::vector that contains the total Mass for each edge of the given MassTree (second value),...
Definition: tree/mass_tree/functions.cpp:379
genesis::tree::mass_tree_clear_masses
void mass_tree_clear_masses(MassTree &tree)
Clear all masses of a MassTree, while keeping its topology.
Definition: tree/mass_tree/functions.cpp:96