A library for working with phylogenetic and population genetic data.
v0.27.0
balances.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_BALANCES_H_
2 #define GENESIS_TREE_MASS_TREE_BALANCES_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 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 "genesis/tree/tree.hpp"
36 
37 #include <vector>
38 #include <unordered_set>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Forward Declarations
45 // =================================================================================================
46 
47 using MassTree = Tree;
48 
49 // =================================================================================================
50 // Balance Settings
51 // =================================================================================================
52 
77 {
78  enum class WeightTendency
79  {
83  kNone,
84 
89  kMedian,
90 
96 
102  };
103 
104  enum class WeightNorm
105  {
109  kNone,
110 
115  kManhattan,
116 
121  kEuclidean,
122 
127  kMaximum,
128 
133  kAitchison
134  };
135 
141 
146 
151 
156 };
157 
158 // =================================================================================================
159 // Balance Data
160 // =================================================================================================
161 
171 {
180 
198 
214 
229  std::vector<double> taxon_weights;
230 };
231 
232 // =================================================================================================
233 // Balances and Weights Calculations
234 // =================================================================================================
235 
249  std::vector<MassTree> const& trees,
250  BalanceSettings settings = {}
251 );
252 
262 BalanceData mass_balance_data(
263  MassTree const& tree,
264  BalanceSettings settings = {}
265 );
266 
275 std::vector<double> mass_balance(
276  BalanceData const& data,
277  std::unordered_set<size_t> const& numerator_edge_indices,
278  std::unordered_set<size_t> const& denominator_edge_indices
279 );
280 
292 double mass_balance(
293  BalanceData const& data,
294  std::unordered_set<size_t> const& numerator_edge_indices,
295  std::unordered_set<size_t> const& denominator_edge_indices,
296  size_t tree_index
297 );
298 
299 } // namespace tree
300 } // namespace genesis
301 
302 #endif // include guard
genesis::tree::BalanceSettings::WeightTendency::kGeometricMean
@ kGeometricMean
Use the geometric mean of the taxon masses.
genesis::tree::mass_balance
std::vector< double > mass_balance(BalanceData const &data, std::unordered_set< size_t > const &numerator_edge_indices, std::unordered_set< size_t > const &denominator_edge_indices)
Calculate the balance of edge masses between two sets of edges.
Definition: balances.cpp:357
genesis::tree::BalanceSettings::WeightNorm
WeightNorm
Definition: balances.hpp:104
genesis::tree::BalanceData::edge_masses
utils::Matrix< double > edge_masses
The relative per-edge masses per original input Tree.
Definition: balances.hpp:197
genesis::tree::BalanceSettings::norm
WeightNorm norm
Set the term for the norm of relative abundances for calculating the taxon weights.
Definition: balances.hpp:145
genesis::tree::BalanceSettings::WeightTendency::kNone
@ kNone
Use no tendency, that is, use 1.0 for this term.
genesis::tree::BalanceSettings::WeightNorm::kAitchison
@ kAitchison
Use the Aitchison norm of the relative abundances of the taxon.
genesis::tree::MassTree
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Definition: placement/function/operators.hpp:54
tree.hpp
Header of Tree class.
genesis::tree::BalanceSettings::pseudo_count_summand_all
double pseudo_count_summand_all
Set the constant that is added to all taxon masses to avoid zero counts.
Definition: balances.hpp:150
genesis::tree::BalanceSettings::WeightNorm::kMaximum
@ kMaximum
Use the Maximum norm of the relative abundances of the taxon.
genesis::tree::mass_balance_data
BalanceData mass_balance_data(std::vector< MassTree > const &trees, BalanceSettings settings)
Calculate the data needed to calculate balances on MassTrees.
Definition: balances.cpp:64
genesis::tree::BalanceData::raw_edge_masses
utils::Matrix< double > raw_edge_masses
The absolute raw per-edge masses per original input Tree.
Definition: balances.hpp:213
genesis::tree::BalanceData
Data needed to calculate balances.
Definition: balances.hpp:170
genesis::utils::Matrix< double >
genesis::tree::BalanceSettings
Settings to calculate balances and the Phylogenetic ILR Transform.
Definition: balances.hpp:76
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::tree::BalanceData::taxon_weights
std::vector< double > taxon_weights
The taxon/edge weights calculated from mulitple trees.
Definition: balances.hpp:229
matrix.hpp
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::BalanceSettings::WeightTendency::kArithmeticMean
@ kArithmeticMean
Use the arithmetic mean of the taxon masses.
genesis::tree::BalanceSettings::WeightNorm::kNone
@ kNone
Use no norm, that is, use 1.0 for this term.
genesis::tree::BalanceSettings::WeightTendency
WeightTendency
Definition: balances.hpp:78
genesis::tree::BalanceSettings::pseudo_count_summand_zeros
double pseudo_count_summand_zeros
Set the constant that is added to taxon masses that are zero, to avoid zero counts.
Definition: balances.hpp:155
genesis::tree::BalanceData::tree
Tree tree
The Tree on which to calculate balances.
Definition: balances.hpp:179
genesis::tree::BalanceSettings::WeightNorm::kManhattan
@ kManhattan
Use the Manhattan norm of the relative abundances of the taxon.
genesis::tree::BalanceSettings::WeightNorm::kEuclidean
@ kEuclidean
Use the Euclidean norm of the relative abundances of the taxon.
genesis::tree::BalanceSettings::tendency
WeightTendency tendency
Set the term for asssing the central tendency of taxon masses for calculating the taxon weights.
Definition: balances.hpp:140
genesis::tree::BalanceSettings::WeightTendency::kMedian
@ kMedian
Use the median of the taxon masses.