21 #include <range/v3/algorithm/copy.hpp> 22 #include <range/v3/view/chunk.hpp> 23 #include <range/v3/view/join.hpp> 24 #include <range/v3/view/remove_if.hpp> 101 class sequence_file_input_format<format_fastq>
105 using format_tag = format_fastq;
110 sequence_file_input_format() noexcept = default;
111 sequence_file_input_format(sequence_file_input_format const &) = delete;
114 sequence_file_input_format & operator=(sequence_file_input_format const &) = delete;
115 sequence_file_input_format(sequence_file_input_format &&) noexcept = default;
116 sequence_file_input_format & operator=(sequence_file_input_format &&) noexcept = default;
117 ~sequence_file_input_format() noexcept = default;
121 template <typename stream_type,
122 typename seq_legal_alph_type,
bool seq_qual_combined,
126 void read(stream_type & stream,
127 sequence_file_input_options<seq_legal_alph_type, seq_qual_combined> const & options,
130 qual_type & qualities)
133 auto stream_it =
begin(stream_view);
136 size_t sequence_size_before = 0;
137 size_t sequence_size_after = 0;
138 if constexpr (!detail::decays_to_ignore_v<seq_type>)
139 sequence_size_before =
size(sequence);
142 if (*stream_it !=
'@')
144 throw parse_error{
std::string{
"Expected '@' on beginning of ID line, got: "} +
145 detail::make_printable(*stream_it)};
149 if constexpr (!detail::decays_to_ignore_v<id_type>)
151 if (options.truncate_ids)
173 if constexpr (!detail::decays_to_ignore_v<seq_type>)
175 auto constexpr is_legal_alph = is_in_alphabet<seq_legal_alph_type>;
178 if (!is_legal_alph(c))
180 throw parse_error{
std::string{
"Encountered an unexpected letter: "} +
181 is_legal_alph.msg.str() +
182 " evaluated to false on " +
183 detail::make_printable(c)};
189 sequence_size_after =
size(sequence);
193 auto it =
begin(seq_view);
194 auto it_end =
end(seq_view);
198 ++sequence_size_after;
203 if (*stream_it !=
'+')
205 throw parse_error{
std::string{
"Expected '+' on beginning of 2nd ID line, got: "} +
206 detail::make_printable(*stream_it)};
213 if constexpr (seq_qual_combined)
218 begin(qualities) + sequence_size_before);
220 else if constexpr (!detail::decays_to_ignore_v<qual_type>)
227 detail::consume(qview);
235 class sequence_file_output_format<format_fastq>
239 using format_tag = format_fastq;
244 sequence_file_output_format() noexcept = default;
245 sequence_file_output_format(sequence_file_output_format const &) = delete;
248 sequence_file_output_format & operator=(sequence_file_output_format const &) = delete;
249 sequence_file_output_format(sequence_file_output_format &&) noexcept = default;
250 sequence_file_output_format & operator=(sequence_file_output_format &&) noexcept = default;
251 ~sequence_file_output_format() noexcept = default;
255 template <typename stream_type,
259 void write(stream_type & stream,
260 sequence_file_output_options const & options,
261 seq_type && sequence,
263 qual_type && qualities)
268 if constexpr (detail::decays_to_ignore_v<id_type>)
270 throw std::logic_error{
"The ID field may not be set to ignore when writing FASTQ files."};
280 detail::write_eol(stream_it, options.add_carriage_return);
284 if constexpr (detail::decays_to_ignore_v<seq_type>)
286 throw std::logic_error{
"The SEQ and SEQ_QUAL fields may not both be set to ignore when writing FASTQ files."};
295 detail::write_eol(stream_it, options.add_carriage_return);
299 if constexpr (!detail::decays_to_ignore_v<id_type>)
303 if (options.fastq_double_id)
306 detail::write_eol(stream_it, options.add_carriage_return);
310 if constexpr (detail::decays_to_ignore_v<qual_type>)
312 throw std::logic_error{
"The QUAL and SEQ_QUAL fields may not both be set to ignore when writing FASTQ files."};
316 if (
empty(qualities))
321 assert(
size(sequence) ==
size(qualities));
326 detail::write_eol(stream_it, options.add_carriage_return);
Provides seqan3::view::istreambuf.
Provides various shortcuts for common std::ranges functions.
::ranges::ostreambuf_iterator ostreambuf_iterator
Alias for ranges::ostreambuf_iterator. Writes successive characters onto the output stream from which...
Definition: iterator.hpp:56
Provides seqan3::detail::ignore_output_iterator for writing to null stream.
constexpr auto istreambuf
A view factory that returns a view over the stream buffer of an input stream.
Definition: istreambuf.hpp:245
Provides seqan3::view::take.
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
Provides seqan3::dna5, container aliases and string literals.
Provides seqan3::view::take_line and seqan3::view::take_line_or_throw.
auto constexpr is_blank
Checks whether c is a blank character.
Definition: predicate.hpp:163
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
Provides seqan3::sequence_file_output_options.
Provides seqan3::view::take_until and seqan3::view::take_until_or_throw.
Provides various utility functions.
Provides various utility functions.
Provides seqan3::view::char_to.
auto constexpr take_line_or_throw
A view adaptor that returns a single line from the underlying range (throws if there is no end-of-lin...
Definition: take_line.hpp:92
Adaptations of concepts from the Ranges TS.
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
::ranges::copy copy
Alias for ranges::copy. Copies a range of elements to a new location.
Definition: algorithm:44
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition: to_char.hpp:66
Definition: aligned_sequence_concept.hpp:35
Provides character predicates for tokenisation.
Provides seqan3::ostream and seqan3::ostreambuf iterator.
auto constexpr take_until_or_throw
A view adaptor that returns elements from the underlying range until the functor evaluates to true (t...
Definition: take_until.hpp:613
T back_inserter(T... args)
Adaptations of algorithms from the Ranges TS.
::ranges::empty empty
Alias for ranges::empty. Checks whether a range is empty.
Definition: ranges:194
Provides seqan3::view::to_char.
Provides various transformation traits used by the range module.
auto constexpr is_space
Checks whether c is a space character.
Definition: predicate.hpp:146
Provides aliases for qualified.
auto constexpr is_cntrl
Checks whether c is a control character.
Definition: predicate.hpp:110
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:179
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: ranges:911
Provides seqan3::view::take_exactly and seqan3::view::take_exactly_or_throw.
constexpr auto filter
A range adaptor that takes a predicate and returns a view of the elements that satisfy the predicate...
Definition: ranges:565
auto constexpr take_exactly_or_throw
A view adaptor that returns the first size elements from the underlying range and also exposes size i...
Definition: take_exactly.hpp:94
auto const char_to
A view over an alphabet, given a range of characters.
Definition: char_to.hpp:70