A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
placement/formats/edge_color.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 
32 
39 
40 #include <cmath>
41 
42 namespace genesis {
43 namespace placement {
44 
45 // =================================================================================================
46 // Placement Edge Color Functions
47 // =================================================================================================
48 
71 std::vector<utils::Color> placement_color_count_gradient( Sample const& smp, bool linear )
72 {
73  // Init the result vector with grey color for each edge.
74  auto ret = std::vector<utils::Color>( smp.tree().edge_count(), utils::Color(0.5,0.5,0.5) );
75 
76  // Get the highest number of placements on any edge.
77  // If this is zero, there are no placements, so we can immediately return.
78  auto const max_placements_per_edge = placement_count_max_edge(smp).second;
79  if (max_placements_per_edge == 0) {
80  return ret;
81  }
82 
83  auto place_map = placements_per_edge( smp );
84 
85  // Calculate the heat gradient color based on the number of placements for each edge.
86  for (auto it = smp.tree().begin_edges(); it != smp.tree().end_edges(); ++it) {
87  auto const& edge = **it;
88  auto const placements_on_edge = place_map[ edge.index() ].size();
89 
90  if( placements_on_edge > 0) {
91  double val;
92  if (linear) {
93  val = placements_on_edge / max_placements_per_edge;
94  } else {
95  val = log( placements_on_edge ) / log( max_placements_per_edge );
96  }
97  ret[edge.index()] = utils::heat_gradient(val);
98  }
99 
100  // LOG_DBG << edge.placements.size() << " --> "
101  // << 100 * edge.placements.size() / max_placements_per_edge_
102  // << " = " << edge_color.dump();
103  }
104 
105  return ret;
106 }
107 
108 } // namespace placement
109 } // namespace genesis
IteratorEdges begin_edges()
Definition: tree/tree.cpp:498
std::vector< std::vector< PqueryPlacement const * > > placements_per_edge(Sample const &smp, bool only_max_lwr_placements)
Return a mapping from each PlacementTreeEdges to the PqueryPlacements that are placed on that edge...
IteratorEdges end_edges()
Definition: tree/tree.cpp:503
PlacementTree & tree()
Get the PlacementTree of this Sample.
Definition: sample.cpp:119
std::vector< utils::Color > placement_color_count_gradient(Sample const &smp, bool linear)
Returns a vector with a Color for each edge that visualizes the number of placements on that edge...
Provides functions for working with Placements and Pqueries.
std::pair< PlacementTreeEdge const *, size_t > placement_count_max_edge(Sample const &smp)
Get the number of placements on the edge with the most placements, and a pointer to this edge...
Header of Color class.
Color heat_gradient(double percentage)
Return a Color that represents a heat gradient for a given percentage value.
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Definition: tree/tree.cpp:358
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
Definition: sample.hpp:68
Color operators and functions.