A library for working with phylogenetic and population genetic data.
v0.32.0
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-2023 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 <lczech@carnegiescience.edu>
20  Department of Plant Biology, Carnegie Institution For Science
21  260 Panama Street, Stanford, CA 94305, USA
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 const& edge : smp.tree().edges() ) {
87  auto const placements_on_edge = place_map[ edge.index() ].size();
88 
89  if( placements_on_edge > 0) {
90  double val;
91  if (linear) {
92  val = placements_on_edge / max_placements_per_edge;
93  } else {
94  val = log( placements_on_edge ) / log( max_placements_per_edge );
95  }
96  ret[edge.index()] = utils::heat_gradient(val);
97  }
98 
99  // LOG_DBG << edge.placements.size() << " --> "
100  // << 100 * edge.placements.size() / max_placements_per_edge_
101  // << " = " << edge_color.dump();
102  }
103 
104  return ret;
105 }
106 
107 } // namespace placement
108 } // namespace genesis
genesis::utils::Color
Definition: color.hpp:47
genesis::placement::Sample::tree
PlacementTree & tree()
Get the PlacementTree of this Sample.
Definition: sample.cpp:124
genesis::placement::placement_count_max_edge
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.
Definition: placement/function/functions.cpp:789
placement_tree.hpp
genesis::placement::Sample
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
Definition: sample.hpp:68
functions.hpp
Provides functions for working with Placements and Pqueries.
edge_color.hpp
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
functions.hpp
Color operators and functions.
genesis::utils::heat_gradient
Color heat_gradient(double percentage)
Return a Color that represents a heat gradient for a given percentage value.
Definition: utils/color/functions.cpp:203
genesis::tree::Tree::edges
utils::Range< IteratorEdges > edges()
Definition: tree/tree.hpp:452
color.hpp
Header of Color class.
genesis::placement::placements_per_edge
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.
Definition: placement/function/helper.cpp:106
sample.hpp
genesis::placement::placement_color_count_gradient
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.
Definition: placement/formats/edge_color.cpp:71
helper.hpp
genesis::tree::Tree::edge_count
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Definition: tree/tree.hpp:272