9#ifndef __DISTANCE_TO_PARENT_H_INCLUDED__
10#define __DISTANCE_TO_PARENT_H_INCLUDED__
12#include "../../simulator/DiscreteTimeWrightFisher.hpp"
13#include "../container/Forest.hpp"
14#include "../container/Tree.hpp"
36 unsigned int m_ancestral_Wright_Fisher_N;
54 unsigned int m_distance_to_parent = 0;
88 return m_distance_to_parent;
95 m_distance_to_parent = l;
116 int d = node.
cell().time() - node.parent().cell().time();
118 node.
cell().distance_to_parent(l);
122 node.
cell().distance_to_parent(0);
135 static auto make_forest(std::map<coord_type, unsigned int>
const &sample_counts,
time_type const &sampling_time)
138 for (
auto const &it : sample_counts)
140 forest.
insert(it.first, std::vector<tree_type>(it.second,
tree_type(sampling_time)));
152 m_ancestral_Wright_Fisher_N = value;
162 return m_ancestral_Wright_Fisher_N;
171 return [](
auto &parent,
auto const &child) {
return parent.add_child(child); };
195 template <
typename Generator>
199 auto WF_init = [&t_curr](
time_type const &t) {
204 auto tree = WF_model::coalesce(forest, m_ancestral_Wright_Fisher_N, gen,
branch(), WF_init);
206 tree.visit_subtrees_by_pre_order_DFS(computer);
219 auto preorder = [&
newick](
auto const &node) {
220 if (node.has_children())
225 auto inorder = [&
newick](
auto const &) {
newick +=
","; };
226 auto postorder = [&
newick](
auto const &node) {
227 if (node.has_children())
232 if (node.has_parent())
235 newick += std::to_string(node.cell().distance_to_parent());
238 tree.visit_subtrees_by_generic_DFS(preorder, inorder, postorder);
257 unsigned int m_ancestral_Wright_Fisher_N;
266 void ancestral_Wright_Fisher_N(
unsigned int value)
268 m_ancestral_Wright_Fisher_N = value;
280 unsigned int m_distance_to_parent = 0;
335 return m_distance_to_parent;
342 m_distance_to_parent = l;
358 int d = node.
cell().time() - node.parent().cell().time();
360 node.
cell().distance_to_parent(l);
364 node.
cell().distance_to_parent(0);
378 template <
typename F>
379 static auto make_forest(std::map<coord_type, unsigned int>
const &sample_counts,
time_type const &sampling_time,
383 for (
auto const &it : sample_counts)
385 cell_type c(get_name(it.first, sampling_time), sampling_time);
386 forest.
insert(it.first, std::vector<tree_type>(it.second,
tree_type(c)));
403 template <
typename T,
typename F1,
typename F2>
404 static auto make_forest(std::vector<T> sample,
time_type const &sampling_time, F1 get_location, F2 get_name)
407 for (
auto const &it : sample)
409 cell_type c(get_name(it, sampling_time), sampling_time);
410 forest.insert(get_location(it, sampling_time),
tree_type(c));
420 return [](
auto &parent,
auto const &child) {
return parent.add_child(child); };
438 template <
typename Generator>
442 auto WF_init = [&t_curr](
time_type const &t) {
447 auto tree = WF_model::coalesce(forest, m_ancestral_Wright_Fisher_N, gen,
branch(), WF_init);
449 tree.visit_subtrees_by_pre_order_DFS(computer);
460 auto preorder = [&
newick](
auto const &node) {
461 if (node.has_children())
466 auto inorder = [&
newick](
auto const &) {
newick +=
","; };
467 auto postorder = [&
newick](
auto const &node) {
468 if (node.has_children())
473 if (node.has_parent())
475 newick += node.cell().name();
477 newick += std::to_string(node.cell().distance_to_parent());
480 tree.visit_subtrees_by_generic_DFS(preorder, inorder, postorder);
Collection of geo-localized coalescing trees.
Definition Forest.hpp:32
iterator insert(Position const &position, Tree const &tree)
insert a new tree at a given position
Definition Forest.hpp:177
Data structure for representing tree topologies where each node contains a data field.
Definition Tree.hpp:29
const CellT & cell() const
Cell accessor.
Definition Tree.hpp:286
bool has_parent() const
Checks whether the tree has a parent.
Definition Tree.hpp:140
Definition distance_to_parent.hpp:51
time_type time() const
Get time of node creation.
Definition distance_to_parent.hpp:72
void time(time_type const &t)
Set time of node creation.
Definition distance_to_parent.hpp:79
void distance_to_parent(unsigned int l)
Set distance to parent node, in number of generations.
Definition distance_to_parent.hpp:93
cell_type(time_type t)
Constructor.
Definition distance_to_parent.hpp:62
unsigned int distance_to_parent() const
Get distance to parent node, in number of generations.
Definition distance_to_parent.hpp:86
cell_type()=default
Default constructor.
Inner class defining what data type the tree stores.
Definition distance_to_parent.hpp:276
time_type time() const
Get time of node creation.
Definition distance_to_parent.hpp:305
void name(std::string const &name)
Set name of the node.
Definition distance_to_parent.hpp:326
void time(time_type const &t)
Set time of node creation.
Definition distance_to_parent.hpp:312
cell_type()=default
Default constructor.
cell_type(time_type const &t)
Constructor for inner nodes (no name for them!)
Definition distance_to_parent.hpp:295
void distance_to_parent(unsigned int l)
Set distance to parent node, in number of generations.
Definition distance_to_parent.hpp:340
cell_type(std::string const &name, time_type const &t)
Constructor for tip nodes (leaves)
Definition distance_to_parent.hpp:288
std::string name() const
Get name of the node.
Definition distance_to_parent.hpp:319
unsigned int distance_to_parent() const
Get distance to parent node, in number of generations.
Definition distance_to_parent.hpp:333
Definition distance_to_parent.hpp:255
static auto make_forest(std::map< coord_type, unsigned int > const &sample_counts, time_type const &sampling_time, F get_name)
Make a forest respecting the policy from a geographic sample.
Definition distance_to_parent.hpp:379
tree_type find_mrca(forest_type const &forest, time_type const &first_time, Generator &gen) const
Coalesce the given forest into a discrete time Wright-Fisher model.
Definition distance_to_parent.hpp:439
std::string treat(tree_type &tree) const
Visit the whole tree and builds its Newick formula.
Definition distance_to_parent.hpp:457
quetzal::coalescence::container::Tree< cell_type > tree_type
The type used to represent a genealogy.
Definition distance_to_parent.hpp:346
Space coord_type
Geographic coordinate type.
Definition distance_to_parent.hpp:271
static auto init()
Get the functor interface required to initialize a node.
Definition distance_to_parent.hpp:426
quetzal::coalescence::container::Forest< coord_type, tree_type > forest_type
The type used to represent a spatial forest of genealogies.
Definition distance_to_parent.hpp:348
static auto branch()
Get the functor interface required to branch a parent node to a child node.
Definition distance_to_parent.hpp:418
Time time_type
Time type.
Definition distance_to_parent.hpp:273
Policy class for coalescing gene copies into a Newick formula.
Definition distance_to_parent.hpp:34
Time time_type
Definition distance_to_parent.hpp:46
static auto branch()
Get the functor interface required to branch a parent node to a child node.
Definition distance_to_parent.hpp:169
tree_type find_mrca(forest_type const &forest, time_type const &first_time, Generator &gen) const
Coalesce the given forest into a discrete time Wright-Fisher model.
Definition distance_to_parent.hpp:196
static auto init()
Get the functor interface required to initialize a node.
Definition distance_to_parent.hpp:178
unsigned int ancestral_Wright_Fisher_N() const
Get the size of the putative ancestral Wright-Fisher population preceding the spatial history.
Definition distance_to_parent.hpp:160
static auto make_forest(std::map< coord_type, unsigned int > const &sample_counts, time_type const &sampling_time)
Make a forest respecting the policy from a geographic sample.
Definition distance_to_parent.hpp:135
quetzal::coalescence::container::Tree< cell_type > tree_type
Definition distance_to_parent.hpp:102
Space coord_type
Definition distance_to_parent.hpp:42
void ancestral_Wright_Fisher_N(unsigned int value)
Set the size of the putative ancestral Wright-Fisher population preceding the spatial history.
Definition distance_to_parent.hpp:150
static std::string treat(tree_type &tree)
Visit the whole tree and builds its Newick formula.
Definition distance_to_parent.hpp:216
Discrete time simulation in a Wright-Fisher Population.
Definition DiscreteTimeWrightFisher.hpp:33
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21
Treatment to operate on a DFS on the tree to compute branches length.
Definition distance_to_parent.hpp:111
Definition distance_to_parent.hpp:353