|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
55 bool with_pendant_length
59 #pragma omp parallel for
60 for(
size_t pppai = 0; pppai < pquery_a.
placements.size(); ++pppai ) {
61 auto const& place_a = pquery_a.
placements[ pppai ];
63 #pragma omp parallel for
64 for(
size_t pppbi = 0; pppbi < pquery_b.
placements.size(); ++pppbi ) {
65 auto const& place_b = pquery_b.
placements[ pppbi ];
68 if (place_a.edge_index == place_b.edge_index) {
70 dist = std::abs(place_a.proximal_length - place_b.proximal_length);
76 pp = place_a.proximal_length
77 + node_distances(place_a.primary_node_index, place_b.primary_node_index)
78 + place_b.proximal_length;
81 pd = place_a.proximal_length
82 + node_distances(place_a.primary_node_index, place_b.secondary_node_index)
83 + place_b.branch_length - place_b.proximal_length;
86 dp = place_a.branch_length - place_a.proximal_length
87 + node_distances(place_a.secondary_node_index, place_b.primary_node_index)
88 + place_b.proximal_length;
91 dist = std::min({ pp, pd, dp });
95 if (with_pendant_length) {
96 dist += place_a.pendant_length + place_b.pendant_length;
98 dist *= place_a.like_weight_ratio * place_b.like_weight_ratio;
111 template<
typename DistanceFunction>
115 DistanceFunction distance_function
119 #pragma omp parallel for
123 #pragma omp parallel for
127 double dist = distance_function( place_a, place_b );
128 dist *= place_a.like_weight_ratio * place_b.like_weight_ratio;
142 bool with_pendant_length
149 if( with_pendant_length ) {
196 dist = std::min({ pp, pd, dp });
227 size_t const pp = node_path_lengths(
233 size_t const ps = node_path_lengths(
239 size_t const sp = node_path_lengths(
244 return std::min({ pp, ps, sp }) + 1;
254 template<
typename DistanceFunction>
260 #pragma omp parallel for
264 double dist = distance_function( placement );
265 dist *= placement.like_weight_ratio;
303 return std::min( pd, dd );
347 return edge_path_lengths( placement.
edge().
index(), edge.
index() );
double sum(const Histogram &h)
PlacementTreeEdge const & edge() const
Get the PlacementTreeEdge where this PqueryPlacement is placed.
Simple POD struct that stores the information of a Pquery in a simple format for speeding up some cal...
double pquery_distance(Pquery const &pquery, tree::TreeNode const &node, utils::Matrix< double > const &node_distances)
Calculate the weighted distance between the PqueryPlacements of a Pquery and a tree::TreeNode,...
double pquery_distance(PqueryPlain const &pquery_a, PqueryPlain const &pquery_b, utils::Matrix< double > const &node_distances, bool with_pendant_length)
Calculate the weighted distance between two plain pqueries. It is mainly a helper method for distance...
size_t index() const
Return the index of this Edge.
TreeNode & secondary_node()
Return the TreeNode of this TreeEdge that points away from the root.
size_t placement_path_length_distance(PqueryPlacement const &placement, tree::TreeEdge const &edge, utils::Matrix< size_t > const &edge_path_lengths)
Calculate the discrete distance from a PqueryPlacement to an edge, measured as the number of nodes be...
PqueryPlacement & placement_at(size_t index)
Return the PqueryPlacement at a certain index.
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
double placement_distance(PqueryPlacement const &place_a, PqueryPlacement const &place_b, utils::Matrix< double > const &node_distances)
Calculate the distance between two PqueryPlacements, using their position on the tree::TreeEdges,...
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
TreeNode & primary_node()
Return the TreeNode of this TreeEdge that points towards the root.
double pquery_path_length_distance(Pquery const &pquery, tree::TreeEdge const &edge, utils::Matrix< size_t > const &edge_path_lengths)
Calculate the weighted discrete distance between the PqueryPlacements of a Pquery and a tree::TreeEdg...
size_t placement_size() const
Return the number of PqueryPlacements stored in this Pquery.
double placement_distance(PqueryPlacement const &placement, tree::TreeNode const &node, utils::Matrix< double > const &node_distances)
Calculate the distance in branch length units between a PqueryPlacement and a tree::TreeNode.
Header of PqueryPlain class.
Common class containing the commonly needed data for tree edges.
One placement position of a Pquery on a Tree.
size_t index() const
Return the index of this Node.
std::vector< PqueryPlacementPlain > placements
double proximal_length
Distance of this placement to the next node towards the root.
double pendant_length
Length of the attached branch of this placement.