A library for working with phylogenetic and population genetic data.
v0.27.0
heatmap_colorization.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FUNCTIONS_HEATMAP_COLORIZATION_H_
2 #define GENESIS_POPULATION_FUNCTIONS_HEATMAP_COLORIZATION_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2021 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
40 
41 #include <string>
42 #include <vector>
43 
44 namespace genesis {
45 namespace population {
46 
47 // =================================================================================================
48 // Heatmap Colorization
49 // =================================================================================================
50 
55 {
56 public:
57 
58  // -------------------------------------------------------------------------
59  // Typedefs and Enums
60  // -------------------------------------------------------------------------
61 
63 
64  struct Spectrum
65  {
66  Spectrum() = default;
67  Spectrum( std::string const& chromosome )
69  {}
70 
71  std::string chromosome;
72  std::vector<std::vector<double>> values;
73  };
74 
75  // -------------------------------------------------------------------------
76  // Constructors and Rule of Five
77  // -------------------------------------------------------------------------
78 
79  HeatmapColorization() = default;
80 
81  explicit HeatmapColorization( std::vector<utils::Color> const& palette )
82  {
83  color_map_.palette( palette );
84  }
85 
86  ~HeatmapColorization() = default;
87 
88  HeatmapColorization( HeatmapColorization const& ) = default;
90 
93 
94  // -------------------------------------------------------------------------
95  // Heatmap Functions
96  // -------------------------------------------------------------------------
97 
98  std::pair<utils::Matrix<utils::Color>, double> spectrum_to_image(
99  Spectrum const& spectrum
100  ) const;
101 
102  std::pair<utils::SvgGroup, double> spectrum_to_svg(
103  Spectrum const& spectrum,
104  utils::SvgMatrixSettings settings = {}
105  ) const;
106 
107  double spectrum_to_bmp_file(
108  Spectrum const& spectrum,
109  std::shared_ptr<utils::BaseOutputTarget> target
110  ) const;
111 
112  // -------------------------------------------------------------------------
113  // Settings
114  // -------------------------------------------------------------------------
115 
116  bool log_scale() const
117  {
118  return log_scale_;
119  }
120 
121  self_type& log_scale( bool value )
122  {
123  log_scale_ = value;
124  return *this;
125  }
126 
127  bool diverging_scale() const
128  {
129  return diverging_scale_;
130  }
131 
132  self_type& diverging_scale( bool value )
133  {
134  diverging_scale_ = value;
135  return *this;
136  }
137 
138  bool invert_vertically() const
139  {
140  return invert_vertically_;
141  }
142 
144  {
145  invert_vertically_ = value;
146  return *this;
147  }
148 
149  bool max_per_column() const
150  {
151  return max_per_column_;
152  }
153 
154  self_type& max_per_column( bool value )
155  {
156  max_per_column_ = value;
157  return *this;
158  }
159 
161  {
162  return color_map_.mask_color();
163  }
164 
166  {
167  color_map_.mask_color( value );
168  return *this;
169  }
170 
172  {
173  return use_empty_window_color_;
174  }
175 
177  {
178  use_empty_window_color_ = value;
179  return *this;
180  }
181 
182  self_type& palette( std::vector<utils::Color> const& value )
183  {
184  color_map_.palette( value );
185  return *this;
186  }
187 
189  {
190  return color_map_;
191  }
192 
193  // -------------------------------------------------------------------------
194  // Data Members
195  // -------------------------------------------------------------------------
196 
197 private:
198 
199  bool log_scale_ = false;
200  bool diverging_scale_ = false;
201  bool invert_vertically_ = true;
202  bool max_per_column_ = false;
203 
204  bool use_empty_window_color_ = true;
205  utils::ColorMap color_map_;
206 
207 };
208 
209 } // namespace population
210 } // namespace genesis
211 
212 #endif // include guard
genesis::utils::ColorMap
Store a list of colors and offer them as a map for values in range [ 0.0, 1.0 ].
Definition: map.hpp:61
genesis::utils::Color
Definition: color.hpp:47
genesis::population::HeatmapColorization::spectrum_to_image
std::pair< utils::Matrix< utils::Color >, double > spectrum_to_image(Spectrum const &spectrum) const
Definition: heatmap_colorization.cpp:55
genesis::population::HeatmapColorization::invert_vertically
self_type & invert_vertically(bool value)
Definition: heatmap_colorization.hpp:143
genesis::population::HeatmapColorization::~HeatmapColorization
~HeatmapColorization()=default
genesis::population::HeatmapColorization::use_empty_window_color
self_type & use_empty_window_color(bool value)
Definition: heatmap_colorization.hpp:176
genesis::population::HeatmapColorization
Definition: heatmap_colorization.hpp:54
genesis::population::HeatmapColorization::empty_window_color
utils::Color const & empty_window_color() const
Definition: heatmap_colorization.hpp:160
genesis::population::HeatmapColorization::log_scale
self_type & log_scale(bool value)
Definition: heatmap_colorization.hpp:121
map.hpp
genesis::population::HeatmapColorization::Spectrum::chromosome
std::string chromosome
Definition: heatmap_colorization.hpp:71
genesis::population::HeatmapColorization::spectrum_to_bmp_file
double spectrum_to_bmp_file(Spectrum const &spectrum, std::shared_ptr< utils::BaseOutputTarget > target) const
Definition: heatmap_colorization.cpp:205
group.hpp
genesis::population::HeatmapColorization::spectrum_to_svg
std::pair< utils::SvgGroup, double > spectrum_to_svg(Spectrum const &spectrum, utils::SvgMatrixSettings settings={}) const
Definition: heatmap_colorization.cpp:194
genesis::population::HeatmapColorization::diverging_scale
self_type & diverging_scale(bool value)
Definition: heatmap_colorization.hpp:132
genesis::population::HeatmapColorization::palette
self_type & palette(std::vector< utils::Color > const &value)
Definition: heatmap_colorization.hpp:182
genesis::population::HeatmapColorization::invert_vertically
bool invert_vertically() const
Definition: heatmap_colorization.hpp:138
genesis::population::HeatmapColorization::diverging_scale
bool diverging_scale() const
Definition: heatmap_colorization.hpp:127
matrix.hpp
genesis::population::HeatmapColorization::Spectrum::values
std::vector< std::vector< double > > values
Definition: heatmap_colorization.hpp:72
genesis::population::HeatmapColorization::HeatmapColorization
HeatmapColorization(std::vector< utils::Color > const &palette)
Definition: heatmap_colorization.hpp:81
genesis::utils::SvgMatrixSettings
Definition: formats/svg/matrix.hpp:56
genesis::population::HeatmapColorization::color_map
utils::ColorMap & color_map()
Definition: heatmap_colorization.hpp:188
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
genesis::population::HeatmapColorization::HeatmapColorization
HeatmapColorization()=default
genesis::population::HeatmapColorization::max_per_column
self_type & max_per_column(bool value)
Definition: heatmap_colorization.hpp:154
color.hpp
Header of Color class.
genesis::population::HeatmapColorization::Spectrum
Definition: heatmap_colorization.hpp:64
genesis::population::HeatmapColorization::use_empty_window_color
bool use_empty_window_color() const
Definition: heatmap_colorization.hpp:171
genesis::population::HeatmapColorization::operator=
HeatmapColorization & operator=(HeatmapColorization const &)=default
genesis::population::HeatmapColorization::empty_window_color
self_type & empty_window_color(utils::Color const &value)
Definition: heatmap_colorization.hpp:165
matrix.hpp
genesis::utils::ColorMap::palette
ColorMap & palette(std::vector< Color > const &value)
Definition: map.hpp:219
genesis::population::HeatmapColorization::log_scale
bool log_scale() const
Definition: heatmap_colorization.hpp:116
output_target.hpp
genesis::population::HeatmapColorization::Spectrum::Spectrum
Spectrum()=default
genesis::utils::ColorMap::mask_color
Color const & mask_color() const
Color that indicates values equal to ColorNormalization::mask_value() or non-finite values.
Definition: map.hpp:101
genesis::population::HeatmapColorization::max_per_column
bool max_per_column() const
Definition: heatmap_colorization.hpp:149
genesis::population::HeatmapColorization::Spectrum::Spectrum
Spectrum(std::string const &chromosome)
Definition: heatmap_colorization.hpp:67