A library for working with phylogenetic and population genetic data.
v0.27.0
phylo_factor.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_PHYLO_FACTOR_H_
2 #define GENESIS_TREE_MASS_TREE_PHYLO_FACTOR_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 
36 
37 #include <functional>
38 #include <unordered_set>
39 #include <vector>
40 
41 namespace genesis {
42 namespace tree {
43 
44 // =================================================================================================
45 // Forward Declarations
46 // =================================================================================================
47 
48 class Subtree;
49 class Tree;
50 using MassTree = Tree;
51 
52 // =================================================================================================
53 // Phylogenetic Factorization
54 // =================================================================================================
55 
62 {
66  size_t edge_index;
67 
71  std::unordered_set<size_t> edge_indices_primary;
72 
76  std::unordered_set<size_t> edge_indices_secondary;
77 
81  std::vector<double> balances;
82 
87 
98  std::vector<double> all_objective_values;
99 };
100 
111 std::unordered_set<size_t> phylo_factor_subtree_indices(
112  Subtree const& subtree,
113  std::unordered_set<size_t> const& candidate_edges
114 );
115 
121  BalanceData const& data,
122  std::unordered_set<size_t> const& candidate_edges,
123  std::function<double( std::vector<double> const& balances )> objective
124 );
125 
159 std::vector<PhyloFactor> phylogenetic_factorization(
160  BalanceData const& data,
161  std::function<double( std::vector<double> const& balances )> objective,
162  size_t max_iterations = 0,
163  std::function<void( size_t iteration, size_t max_iterations )> log_progress = {}
164 );
165 
166 } // namespace tree
167 } // namespace genesis
168 
169 #endif // include guard
genesis::tree::phylo_factor_subtree_indices
std::unordered_set< size_t > phylo_factor_subtree_indices(Subtree const &subtree, std::unordered_set< size_t > const &candidate_edges)
Helper function for phylogenetic_factorization() to find the constrained subtrees that are split by a...
Definition: phylo_factor.cpp:65
genesis::tree::PhyloFactor::balances
std::vector< double > balances
The balances for all Samples calculated on the two sets of edge indices of this factor.
Definition: phylo_factor.hpp:81
balances.hpp
genesis::tree::MassTree
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Definition: placement/function/operators.hpp:54
genesis::tree::PhyloFactor::edge_index
size_t edge_index
The edge that this factor found to be maximizing for the objective function.
Definition: phylo_factor.hpp:66
genesis::tree::PhyloFactor
A single phylogenetic factor.
Definition: phylo_factor.hpp:61
genesis::tree::PhyloFactor::all_objective_values
std::vector< double > all_objective_values
For reference, all other objective values for the other edges of the tree.
Definition: phylo_factor.hpp:98
genesis::tree::BalanceData
Data needed to calculate balances.
Definition: balances.hpp:170
genesis::tree::PhyloFactor::objective_value
double objective_value
The objective value obtained from the objective function using the balances.
Definition: phylo_factor.hpp:86
genesis::tree::PhyloFactor::edge_indices_secondary
std::unordered_set< size_t > edge_indices_secondary
The set of edges on the non-root (secondary) side of the edge that belongs to this factor.
Definition: phylo_factor.hpp:76
genesis::tree::Subtree
Reference to a subtree of a Tree.
Definition: subtree.hpp:69
matrix.hpp
genesis::tree::phylo_factor_find_best_edge
PhyloFactor phylo_factor_find_best_edge(BalanceData const &data, std::unordered_set< size_t > const &candidate_edges, std::function< double(std::vector< double > const &balances)> objective)
Helper function for phylogenetic_factorization() that tries all candidate edges to find the one that ...
Definition: phylo_factor.cpp:183
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::phylogenetic_factorization
std::vector< PhyloFactor > phylogenetic_factorization(BalanceData const &data, std::function< double(std::vector< double > const &balances)> objective, size_t max_iterations, std::function< void(size_t iteration, size_t max_iterations)> log_progress)
Calculate the Phylogenetic Factorization (PhyloFactor) of a set of MassTrees.
Definition: phylo_factor.cpp:263
genesis::tree::PhyloFactor::edge_indices_primary
std::unordered_set< size_t > edge_indices_primary
The set of edges on the root (primary) side of the edge that belongs to this factor.
Definition: phylo_factor.hpp:71