A library for working with phylogenetic and population genetic data.
v0.32.0
fasta_writer.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_FORMATS_FASTA_WRITER_H_
2 #define GENESIS_SEQUENCE_FORMATS_FASTA_WRITER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 Lucas Czech and HITS gGmbH
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 
35 
36 #include <iosfwd>
37 #include <string>
38 
39 namespace genesis {
40 namespace sequence {
41 
42 // =================================================================================================
43 // Forward Declarations
44 // =================================================================================================
45 
46 class Sequence;
47 class SequenceSet;
48 
49 // =================================================================================================
50 // Fasta Writer
51 // =================================================================================================
52 
68 {
69 public:
70 
71  // ---------------------------------------------------------------------
72  // Typedefs and Enums
73  // ---------------------------------------------------------------------
74 
78  enum class AbundanceNotation
79  {
83  kNone,
84 
89 
93  kSize
94  };
95 
96  // ---------------------------------------------------------------------
97  // Constructor and Rule of Five
98  // ---------------------------------------------------------------------
99 
100  FastaWriter() = default;
101  ~FastaWriter() = default;
102 
103  FastaWriter( FastaWriter const& ) = default;
104  FastaWriter( FastaWriter&& ) = default;
105 
106  FastaWriter& operator= ( FastaWriter const& ) = default;
107  FastaWriter& operator= ( FastaWriter&& ) = default;
108 
109  // ---------------------------------------------------------------------
110  // Writing
111  // ---------------------------------------------------------------------
112 
119  void write( Sequence const& sequence, std::shared_ptr<utils::BaseOutputTarget> target ) const;
120 
127  void write( SequenceSet const& sequence_set, std::shared_ptr<utils::BaseOutputTarget> target ) const;
128 
132  void write_sequence( Sequence const& sequence, std::ostream& os ) const;
133 
134  // ---------------------------------------------------------------------
135  // Properties
136  // ---------------------------------------------------------------------
137 
145  FastaWriter& line_length( size_t value );
146 
152  size_t line_length() const;
153 
160 
165 
166  // ---------------------------------------------------------------------
167  // Members
168  // ---------------------------------------------------------------------
169 
170 private:
171 
172  size_t line_length_ = 80;
173  AbundanceNotation abundance_notation_ = AbundanceNotation::kNone;
174 
175 };
176 
177 } // namespace sequence
178 } // namespace genesis
179 
180 #endif // include guard
genesis::sequence::FastaWriter::write_sequence
void write_sequence(Sequence const &sequence, std::ostream &os) const
Write a single Sequence to an output stream in Fasta format.
Definition: fasta_writer.cpp:63
genesis::sequence::FastaWriter::AbundanceNotation
AbundanceNotation
Enumeration of types for how to write Sequence abundances.
Definition: fasta_writer.hpp:78
genesis::sequence::FastaWriter::operator=
FastaWriter & operator=(FastaWriter const &)=default
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::FastaWriter
Write Fasta data.
Definition: fasta_writer.hpp:67
genesis::sequence::FastaWriter::AbundanceNotation::kUnderscore
@ kUnderscore
Write abundances appaneded by an underscore: abc_123.
genesis::sequence::FastaWriter::FastaWriter
FastaWriter()=default
genesis::sequence::FastaWriter::line_length
size_t line_length() const
Get the current line length.
Definition: fasta_writer.cpp:108
genesis::sequence::FastaWriter::abundance_notation
AbundanceNotation abundance_notation() const
Get the current setting for how to write abundances.
Definition: fasta_writer.cpp:119
genesis::sequence::FastaWriter::~FastaWriter
~FastaWriter()=default
genesis::sequence::FastaWriter::write
void write(Sequence const &sequence, std::shared_ptr< utils::BaseOutputTarget > target) const
Write a single Sequence to an output target, using the Fasta format.
Definition: fasta_writer.cpp:50
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
output_target.hpp
genesis::sequence::FastaWriter::AbundanceNotation::kSize
@ kSize
Write abundances appended as a text of the form abc;size=123
genesis::sequence::FastaWriter::AbundanceNotation::kNone
@ kNone
Do not write abundances. This is the default.