A library for working with phylogenetic and population genetic data.
v0.32.0
fastx_output_stream.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_FORMATS_FASTX_OUTPUT_STREAM_H_
2 #define GENESIS_SEQUENCE_FORMATS_FASTX_OUTPUT_STREAM_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 
37 
39 
40 #include <iterator>
41 #include <iostream>
42 
43 #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
44 
45  #include <string_view>
46 
47 #endif
48 
49 namespace genesis {
50 namespace sequence {
51 
52 // =================================================================================================
53 // Forward declarations and typedefs
54 // =================================================================================================
55 
56 template<class Writer>
58 
61 
62 // =================================================================================================
63 // Fasta and Fastq Output Stream
64 // =================================================================================================
65 
83 template<class Writer>
85 {
86 public:
87 
88  // -------------------------------------------------------------------------
89  // Member Types
90  // -------------------------------------------------------------------------
91 
93 
94  // -------------------------------------------------------------------------
95  // Constructors and Rule of Five
96  // -------------------------------------------------------------------------
97 
98  FastxOutputStream() = delete;
99 
101  std::shared_ptr<utils::BaseOutputTarget> target
102  )
103  : target_( target )
104  , writer_()
105  {}
106 
108  std::shared_ptr<utils::BaseOutputTarget> target,
109  Writer const& writer
110  )
111  : target_( target )
112  , writer_( writer )
113  {}
114 
115  ~FastxOutputStream() = default;
116 
117  FastxOutputStream( self_type const& ) = default;
118  FastxOutputStream( self_type&& ) = default;
119 
120  self_type& operator= ( self_type const& ) = default;
121  self_type& operator= ( self_type&& ) = default;
122 
123  // -------------------------------------------------------------------------
124  // Accessors
125  // -------------------------------------------------------------------------
126 
127  self_type const& operator<< ( Sequence const& sequence ) const
128  {
129  writer_.write( sequence, target_ );
130  return *this;
131  }
132 
133  self_type const& write( Sequence const& sequence ) const
134  {
135  writer_.write( sequence, target_ );
136  return *this;
137  }
138 
143  template<
144  typename T = Writer,
145  typename std::enable_if< std::is_same<T, FastqWriter>::value >::type* = nullptr
146  >
147  self_type const& write( Sequence const& sequence, std::string const& quality_string ) const
148  {
149  writer_.write( sequence, quality_string, target_ );
150  return *this;
151  }
152 
153  #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
154 
161  template<
162  typename T = Writer,
163  typename std::enable_if< std::is_same<T, FastqWriter>::value >::type* = nullptr
164  >
165  self_type const& write(
166  std::string_view const& label,
167  std::string_view const& sites,
168  std::string_view const& quality
169  ) const {
170  writer_.write( label, sites, quality, target_ );
171  return *this;
172  }
173 
174  #endif
175 
176  // -------------------------------------------------------------------------
177  // Settings
178  // -------------------------------------------------------------------------
179 
180  std::shared_ptr<utils::BaseOutputTarget> output_target() const
181  {
182  return target_;
183  }
184 
191  Writer& writer()
192  {
193  return writer_;
194  }
195 
196  Writer const& writer() const
197  {
198  return writer_;
199  }
200 
201  // -------------------------------------------------------------------------
202  // Data Members
203  // -------------------------------------------------------------------------
204 
205 private:
206 
207  std::shared_ptr<utils::BaseOutputTarget> target_;
208  Writer writer_;
209 };
210 
211 } // namespace sequence
212 } // namespace genesis
213 
214 #endif // include guard
genesis::sequence::FastxOutputStream::operator<<
self_type const & operator<<(Sequence const &sequence) const
Definition: fastx_output_stream.hpp:127
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::FastxOutputStream::output_target
std::shared_ptr< utils::BaseOutputTarget > output_target() const
Definition: fastx_output_stream.hpp:180
fasta_writer.hpp
fastq_writer.hpp
genesis::sequence::FastxOutputStream::FastxOutputStream
FastxOutputStream(std::shared_ptr< utils::BaseOutputTarget > target)
Definition: fastx_output_stream.hpp:100
genesis::sequence::FastxOutputStream::self_type
FastxOutputStream self_type
Definition: fastx_output_stream.hpp:92
genesis::sequence::FastxOutputStream::FastxOutputStream
FastxOutputStream(std::shared_ptr< utils::BaseOutputTarget > target, Writer const &writer)
Definition: fastx_output_stream.hpp:107
genesis::sequence::FastxOutputStream::~FastxOutputStream
~FastxOutputStream()=default
genesis::sequence::FastxOutputStream::write
self_type const & write(Sequence const &sequence) const
Definition: fastx_output_stream.hpp:133
genesis::sequence::FastxOutputStream::FastxOutputStream
FastxOutputStream()=delete
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::FastxOutputStream
Write Fasta or Fastq data, sequentially.
Definition: fastx_output_stream.hpp:57
genesis::sequence::FastxOutputStream::write
self_type const & write(Sequence const &sequence, std::string const &quality_string) const
Writer overload for Fastq files where the quality_string is provided instead of taken from the sequen...
Definition: fastx_output_stream.hpp:147
output_target.hpp
genesis::sequence::FastxOutputStream::operator=
self_type & operator=(self_type const &)=default
genesis::sequence::FastxOutputStream::writer
Writer & writer()
Return the Writer used for this iterator.
Definition: fastx_output_stream.hpp:191
genesis::sequence::FastxOutputStream::writer
Writer const & writer() const
Definition: fastx_output_stream.hpp:196
sequence.hpp