A library for working with phylogenetic data.
v0.25.0
heatmap_matrix.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FUNCTIONS_HEATMAP_MATRIX_H_
2 #define GENESIS_POPULATION_FUNCTIONS_HEATMAP_MATRIX_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 
35 
36 #include <cassert>
37 #include <string>
38 #include <vector>
39 
40 namespace genesis {
41 namespace population {
42 
43 // =================================================================================================
44 // Heatmap Accumulator
45 // =================================================================================================
46 
61 template<typename T>
63 {
64 public:
65 
66  // -------------------------------------------------------------------------
67  // Constructors and Rule of Five
68  // -------------------------------------------------------------------------
69 
71  : height_( height )
72  {}
73 
74  ~HeatmapMatrix() = default;
75 
76  HeatmapMatrix( HeatmapMatrix const& ) = default;
77  HeatmapMatrix( HeatmapMatrix&& ) = default;
78 
79  HeatmapMatrix& operator= ( HeatmapMatrix const& ) = default;
80  HeatmapMatrix& operator= ( HeatmapMatrix&& ) = default;
81 
82  // -------------------------------------------------------------------------
83  // Accessors
84  // -------------------------------------------------------------------------
85 
86  std::string const& chromosome() const
87  {
88  return chromosome_;
89  }
90 
91  size_t start() const
92  {
93  return start_;
94  }
95 
96  size_t end() const
97  {
98  return end_;
99  }
100 
101  size_t height() const
102  {
103  return height_;
104  }
105 
106  size_t width() const
107  {
108  return values_.size();
109  }
110 
118  std::vector<T>& get_column( size_t index )
119  {
120  assert( index < values_.size() );
121  assert( values_[index].size() == height_ );
122  return values_[index];
123  }
124 
128  std::vector<T> const& get_column( size_t index ) const
129  {
130  assert( index < values_.size() );
131  assert( values_[index].size() == height_ );
132  return values_[index];
133  }
134 
135  // -------------------------------------------------------------------------
136  // Modificators
137  // -------------------------------------------------------------------------
138 
139  HeatmapMatrix& chromosome( std::string const& value )
140  {
141  chromosome_ = value;
142  return *this;
143  }
144 
145  HeatmapMatrix& start( size_t value )
146  {
147  start_ = value;
148  return *this;
149  }
150 
151  HeatmapMatrix& end( size_t value )
152  {
153  end_ = value;
154  return *this;
155  }
156 
162  std::vector<T>& add_column()
163  {
164  // Add a new column to the end, default initialized with the specified height, and return it.
165  values.emplace_back( height_, T{} );
166  return values.back();
167  }
168 
169  // -------------------------------------------------------------------------
170  // Data Members
171  // -------------------------------------------------------------------------
172 
173 private:
174 
175  std::string chromosome_;
176  size_t start_;
177  size_t end_;
178 
179  size_t height_;
180  std::vector<std::vector<T>> values_;
181 
182 };
183 
184 } // namespace population
185 } // namespace genesis
186 
187 #endif // include guard
genesis::population::HeatmapMatrix::end
size_t end() const
Definition: heatmap_matrix.hpp:96
genesis::population::HeatmapMatrix::chromosome
std::string const & chromosome() const
Definition: heatmap_matrix.hpp:86
genesis::population::HeatmapMatrix::get_column
std::vector< T > & get_column(size_t index)
Return a specific column.
Definition: heatmap_matrix.hpp:118
genesis::population::HeatmapMatrix::add_column
std::vector< T > & add_column()
Add a column and return it.
Definition: heatmap_matrix.hpp:162
genesis::population::HeatmapMatrix::start
size_t start() const
Definition: heatmap_matrix.hpp:91
genesis::population::HeatmapMatrix::~HeatmapMatrix
~HeatmapMatrix()=default
matrix.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
genesis::population::HeatmapMatrix::end
HeatmapMatrix & end(size_t value)
Definition: heatmap_matrix.hpp:151
genesis::population::HeatmapMatrix::HeatmapMatrix
HeatmapMatrix(size_t height)
Definition: heatmap_matrix.hpp:70
genesis::population::HeatmapMatrix::operator=
HeatmapMatrix & operator=(HeatmapMatrix const &)=default
genesis::population::HeatmapMatrix::height
size_t height() const
Definition: heatmap_matrix.hpp:101
genesis::population::HeatmapMatrix
Matrix to capture and accumulate columns of per-position or per-window values along a chromosome.
Definition: heatmap_matrix.hpp:62
genesis::population::HeatmapMatrix::width
size_t width() const
Definition: heatmap_matrix.hpp:106
genesis::population::HeatmapMatrix::start
HeatmapMatrix & start(size_t value)
Definition: heatmap_matrix.hpp:145
genesis::population::HeatmapMatrix::chromosome
HeatmapMatrix & chromosome(std::string const &value)
Definition: heatmap_matrix.hpp:139
genesis::population::HeatmapMatrix::get_column
std::vector< T > const & get_column(size_t index) const
Return a specific column, const.
Definition: heatmap_matrix.hpp:128