A library for working with phylogenetic and population genetic data.
v0.32.0
simple.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_PRINTERS_SIMPLE_H_
2 #define GENESIS_SEQUENCE_PRINTERS_SIMPLE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 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 <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <iosfwd>
35 #include <map>
36 #include <string>
37 
38 namespace genesis {
39 namespace sequence {
40 
41 // =================================================================================================
42 // Forward Declarations
43 // =================================================================================================
44 
45 class Sequence;
46 class SequenceSet;
47 
48 // =================================================================================================
49 // Printer Simple
50 // =================================================================================================
51 
62 {
63 public:
64 
65  // -------------------------------------------------------------------------
66  // Typedefs and Enums
67  // -------------------------------------------------------------------------
68 
78  enum class ColorMode {
82  kNone,
83 
88 
93  };
94 
98  enum class LabelMode {
102  kNone,
103 
108  kSameLine,
109 
114  };
115 
116  // -------------------------------------------------------------------------
117  // Constructors and Rule of Five
118  // -------------------------------------------------------------------------
119 
120  PrinterSimple() = default;
121  ~PrinterSimple() = default;
122 
123  PrinterSimple( PrinterSimple const& ) = default;
124  PrinterSimple( PrinterSimple&& ) = default;
125 
126  PrinterSimple& operator= ( PrinterSimple const& ) = default;
127  PrinterSimple& operator= ( PrinterSimple&& ) = default;
128 
129  // -------------------------------------------------------------------------
130  // Print
131  // -------------------------------------------------------------------------
132 
136  void print(
137  std::ostream& out,
138  Sequence const& seq
139  ) const;
140 
144  void print(
145  std::ostream& out,
146  SequenceSet const& set
147  ) const;
148 
152  std::string print(
153  Sequence const& seq
154  ) const;
155 
159  std::string print(
160  SequenceSet const& set
161  ) const;
162 
168  std::string operator() (
169  Sequence const& seq
170  ) const;
171 
177  std::string operator() (
178  SequenceSet const& set
179  ) const;
180 
181  // -------------------------------------------------------------------------
182  // Properties
183  // -------------------------------------------------------------------------
184 
192  PrinterSimple& sequence_limit( size_t value );
193 
199  size_t sequence_limit() const;
200 
207  PrinterSimple& line_length( size_t value );
208 
214  size_t line_length() const;
215 
223  PrinterSimple& length_limit( size_t value );
224 
230  size_t length_limit() const;
231 
244  PrinterSimple& color_map( std::map<char, std::string> const& value );
245 
251  std::map<char, std::string> const& color_map() const;
252 
259 
265  ColorMode color_mode() const;
266 
273 
280  LabelMode label_mode() const;
281 
282  // -------------------------------------------------------------------------
283  // Internal Functions
284  // -------------------------------------------------------------------------
285 
286 private:
287 
288  void print_character_(
289  std::ostream& out,
290  char site
291  ) const;
292 
293  void print_sites_(
294  std::ostream& out,
295  Sequence const& seq
296  ) const;
297 
298  void print_sequence_(
299  std::ostream& out,
300  Sequence const& seq,
301  size_t label_len = 0
302  ) const;
303 
304  // -------------------------------------------------------------------------
305  // Data Members
306  // -------------------------------------------------------------------------
307 
308 private:
309 
310  size_t sequence_limit_ = 0;
311  size_t line_length_ = 0;
312  size_t length_limit_ = 0;
313 
314  std::map<char, std::string> color_map_;
315 
316  ColorMode color_mode_ = ColorMode::kBackground;
317  LabelMode label_mode_ = LabelMode::kSameLine;
318 };
319 
320 } // namespace sequence
321 } // namespace genesis
322 
323 #endif // include guard
genesis::sequence::PrinterSimple::color_map
std::map< char, std::string > const & color_map() const
Get the currently set list of colors for each Sequence character.
Definition: simple.cpp:156
genesis::sequence::PrinterSimple::operator=
PrinterSimple & operator=(PrinterSimple const &)=default
genesis::sequence::PrinterSimple::LabelMode::kSameLine
@ kSameLine
The label is printed on the line where the Sequence sites start, separated from them by ": ".
genesis::sequence::PrinterSimple::operator()
std::string operator()(Sequence const &seq) const
Return a string representing the print of a single Sequence.
Definition: simple.cpp:101
genesis::sequence::PrinterSimple::sequence_limit
size_t sequence_limit() const
Get the currently set limit for how many Sequences to print.
Definition: simple.cpp:123
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::PrinterSimple::print
void print(std::ostream &out, Sequence const &seq) const
Print a single Sequence to a stream.
Definition: simple.cpp:49
genesis::sequence::PrinterSimple::ColorMode::kNone
@ kNone
No color, even if a color_map() is provided.
genesis::sequence::PrinterSimple
Simple printer class for Sequences and SequenceSets.
Definition: simple.hpp:61
genesis::sequence::PrinterSimple::LabelMode
LabelMode
Modes for how to print Sequence labels.
Definition: simple.hpp:98
genesis::sequence::PrinterSimple::length_limit
size_t length_limit() const
Get the currently set length limit.
Definition: simple.cpp:145
genesis::sequence::PrinterSimple::ColorMode
ColorMode
Modes for how the Sequence sites are colored.
Definition: simple.hpp:78
genesis::sequence::PrinterSimple::LabelMode::kNone
@ kNone
No label is printed.
genesis::sequence::PrinterSimple::line_length
size_t line_length() const
Get the currently set line length, i.e., when to wrap.
Definition: simple.cpp:134
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::sequence::SequenceSet
Store a set of Sequences.
Definition: sequence_set.hpp:53
genesis::sequence::PrinterSimple::LabelMode::kSeparateLine
@ kSeparateLine
The label is printed on a line preceeding the Sequence sites.
genesis::sequence::PrinterSimple::color_mode
ColorMode color_mode() const
Get the currently set color mode.
Definition: simple.cpp:167
genesis::sequence::PrinterSimple::ColorMode::kForeground
@ kForeground
Color the text foreground of the characters, leave the background at default.
genesis::sequence::PrinterSimple::ColorMode::kBackground
@ kBackground
Color the text background of the characters, set the foreground to black.
genesis::sequence::PrinterSimple::~PrinterSimple
~PrinterSimple()=default
genesis::sequence::PrinterSimple::PrinterSimple
PrinterSimple()=default
genesis::sequence::PrinterSimple::label_mode
LabelMode label_mode() const
Get the currently set LabelMode.
Definition: simple.cpp:178