A library for working with phylogenetic and population genetic data.
v0.32.0
fastq_writer.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_FORMATS_FASTQ_WRITER_H_
2 #define GENESIS_SEQUENCE_FORMATS_FASTQ_WRITER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 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@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
35 
36 #include <iosfwd>
37 #include <string>
38 
39 #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
40 
41  #include <string_view>
42 
43 #endif
44 
45 namespace genesis {
46 namespace sequence {
47 
48 // =================================================================================================
49 // Forward Declarations
50 // =================================================================================================
51 
52 class Sequence;
53 class SequenceSet;
54 
55 // =================================================================================================
56 // Fastq Writer
57 // =================================================================================================
58 
80 {
81 public:
82 
83  // ---------------------------------------------------------------------
84  // Constructor and Rule of Five
85  // ---------------------------------------------------------------------
86 
87  FastqWriter() = default;
88  ~FastqWriter() = default;
89 
90  FastqWriter( FastqWriter const& ) = default;
91  FastqWriter( FastqWriter&& ) = default;
92 
93  FastqWriter& operator= ( FastqWriter const& ) = default;
94  FastqWriter& operator= ( FastqWriter&& ) = default;
95 
96  // ---------------------------------------------------------------------
97  // Writing
98  // ---------------------------------------------------------------------
99 
106  void write(
107  Sequence const& sequence,
108  std::shared_ptr<utils::BaseOutputTarget> target
109  ) const;
110 
122  void write(
123  Sequence const& sequence,
124  std::string const& quality,
125  std::shared_ptr<utils::BaseOutputTarget> target
126  ) const;
127 
134  void write(
135  SequenceSet const& sequence_set,
136  std::shared_ptr<utils::BaseOutputTarget> target
137  ) const;
138 
139  #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
140 
148  void write(
149  std::string_view const& label,
150  std::string_view const& sites,
151  std::string_view const& quality,
152  std::shared_ptr<utils::BaseOutputTarget> target
153  ) const;
154 
155  #endif
156 
157  // ---------------------------------------------------------------------
158  // Properties
159  // ---------------------------------------------------------------------
160 
173  FastqWriter& line_length( size_t value )
174  {
175  line_length_ = value;
176  return *this;
177  }
178 
184  size_t line_length() const
185  {
186  return line_length_;
187  }
188 
203  FastqWriter& fill_missing_quality( unsigned char value )
204  {
205  fill_missing_quality_ = value;
206  return *this;
207  }
208 
212  unsigned char fill_missing_quality() const
213  {
214  return fill_missing_quality_;
215  }
216 
226  FastqWriter& repeat_label( bool value )
227  {
228  repeat_label_ = value;
229  return *this;
230  }
231 
236  bool repeat_label() const
237  {
238  return repeat_label_;
239  }
240 
241  // ---------------------------------------------------------------------
242  // Internal Members
243  // ---------------------------------------------------------------------
244 
245 private:
246 
247  std::string make_filled_quality_string_(
248  size_t length
249  ) const;
250 
251  void write_sequence_(
252  std::string const& label,
253  std::string const& sites,
254  std::string const& quality,
255  std::ostream& os
256  ) const;
257 
258  // ---------------------------------------------------------------------
259  // Members
260  // ---------------------------------------------------------------------
261 
262 private:
263 
264  size_t line_length_ = 0;
265  unsigned char fill_missing_quality_ = 255;
266  bool repeat_label_ = false;
267 
268 };
269 
270 } // namespace sequence
271 } // namespace genesis
272 
273 #endif // include guard
genesis::sequence::FastqWriter::line_length
size_t line_length() const
Get the current line length.
Definition: fastq_writer.hpp:184
genesis::sequence::FastqWriter::~FastqWriter
~FastqWriter()=default
genesis::sequence::FastqWriter::operator=
FastqWriter & operator=(FastqWriter const &)=default
genesis::sequence::FastqWriter::FastqWriter
FastqWriter()=default
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::FastqWriter::repeat_label
FastqWriter & repeat_label(bool value)
Set whether to repeat the sequence identifier (label) on the third line of each sequence.
Definition: fastq_writer.hpp:226
genesis::sequence::FastqWriter::fill_missing_quality
FastqWriter & fill_missing_quality(unsigned char value)
Set the value to fill the quality scores of sequences that do not have a phread score assigned to the...
Definition: fastq_writer.hpp:203
genesis::tree::length
double length(Tree const &tree)
Get the length of the tree, i.e., the sum of all branch lengths.
Definition: tree/common_tree/functions.cpp:160
genesis::sequence::FastqWriter
Write Fastq data.
Definition: fastq_writer.hpp:79
genesis::sequence::FastqWriter::write
void write(Sequence const &sequence, std::shared_ptr< utils::BaseOutputTarget > target) const
Write a single Sequence to an output target, using the Fastq format.
Definition: fastq_writer.cpp:114
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::FastqWriter::line_length
FastqWriter & line_length(size_t value)
Set the line length, which determines after how many chars (Sequence sites) lines breaks are inserted...
Definition: fastq_writer.hpp:173
output_target.hpp
genesis::sequence::FastqWriter::repeat_label
bool repeat_label() const
Get whether the setting to repeat the sequence identifier (label) on the third line is set.
Definition: fastq_writer.hpp:236
genesis::sequence::FastqWriter::fill_missing_quality
unsigned char fill_missing_quality() const
Get the current value to fill missing phred quality scores.
Definition: fastq_writer.hpp:212