A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
placement/pquery/distances.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
31 // #include <algorithm>
32 // #include <assert.h>
33 // #include <string>
34 // #include <vector>
35 // #include <unordered_map>
36 // #include <unordered_set>
37 
39 // #include "genesis/utils/utils.hpp"
40 
41 namespace genesis {
42 namespace placement {
43 
44 /*
45 // =================================================================================================
46 // Distance Measuring
47 // =================================================================================================
48 
49 double distance (
50  const PqueryPlacement& placement,
51  const PlacementTreeNode& node,
52  const Matrix<double>& node_distance_matrix
53 ) {
54  double pp, pd, dp;
55 
56  // proximal-proximal case
57  pp = placement.proximal_length
58  + node_distance_matrix(placement.edge->primary_node()->index(), node.index());
59 
60  // proximal-distal case
61  pd = placement.proximal_length
62  + node_distance_matrix(placement.edge->primary_node()->index(), node.index());
63 
64  // distal-proximal case
65  dp = placement.edge->data.branch_length - placement.proximal_length
66  + node_distance_matrix(placement.edge->secondary_node()->index(), node.index());
67 
68  // find min of the three cases
69  double dist = std::min(pp, std::min(pd, dp));
70 
71  // If needed, use pendant length.
72  if (with_pendant_length) {
73  dist += placement.pendant_length;
74  }
75 
76  return dist;
77 }
78 
79 double distance (
80  const Pquery& pquery,
81  const PlacementTreeNode& node,
82  const Matrix<double>& node_distance_matrix
83 ) {
84  double sum = 0.0;
85 
86  // TODO good candidate for a for_all algorithm or sum, or reduce, or whatever the name is.
87  for (const auto& place : pquery) {
88  sum += distance(place, node, node_distance_matrix) * place.like_weight_ratio;
89  }
90 
91  return sum;
92 }
93 */
94 
95 } // namespace placement
96 } // namespace genesis