44 #include <string_view> 47 #include <range/v3/algorithm/copy.hpp> 48 #include <range/v3/utility/iterator.hpp> 49 #include <range/v3/view/chunk.hpp> 50 #include <range/v3/view/join.hpp> 51 #include <range/v3/view/remove_if.hpp> 128 template <
typename stream_type,
129 typename seq_legal_alph_type,
bool seq_qual_combined,
133 void read(stream_type & stream,
137 qual_type & qualities)
140 decltype(std::istreambuf_iterator<char>{})>
141 {std::istreambuf_iterator<char>{stream},
142 std::istreambuf_iterator<char>{}};
144 auto stream_it = begin(stream_view);
147 size_t sequence_size_before = 0;
148 size_t sequence_size_after = 0;
149 if constexpr (!detail::decays_to_ignore_v<seq_type>)
150 sequence_size_before =
size(sequence);
153 if (*stream_it !=
'@')
155 throw parse_error{std::string{
"Expected '@' on beginning of ID line, got: "} +
156 detail::make_printable(*stream_it)};
160 if constexpr (!detail::decays_to_ignore_v<id_type>)
183 | ranges::view::remove_if(
is_space);
184 if constexpr (!detail::decays_to_ignore_v<seq_type>)
186 auto constexpr is_legal_alph = is_in_alphabet<seq_legal_alph_type>;
189 if (!is_legal_alph(c))
191 throw parse_error{std::string{
"Encountered an unexpected letter: "} +
192 is_legal_alph.msg.string() +
193 " evaluated to false on " +
194 detail::make_printable(c)};
200 sequence_size_after =
size(sequence);
204 auto it = begin(seq_view);
205 auto it_end = end(seq_view);
209 ++sequence_size_after;
214 if (*stream_it !=
'+')
216 throw parse_error{std::string{
"Expected '+' on beginning of 2nd ID line, got: "} +
217 detail::make_printable(*stream_it)};
222 auto qview = stream_view | ranges::view::remove_if(
is_space)
224 if constexpr (seq_qual_combined)
227 assert(std::addressof(sequence) == std::addressof(qualities));
229 begin(qualities) + sequence_size_before);
231 else if constexpr (!detail::decays_to_ignore_v<qual_type>)
238 detail::consume(qview);
242 if ((std::istreambuf_iterator<char>{stream} == std::istreambuf_iterator<char>{}) &&
250 template <
typename stream_type,
256 seq_type && sequence,
258 qual_type && qualities)
263 if constexpr (detail::decays_to_ignore_v<id_type>)
265 throw std::logic_error{
"The ID field may not be set to ignore when writing FASTQ files."};
270 throw std::runtime_error{
"The ID field may not be empty when writing FASTQ files."};
279 if constexpr (detail::decays_to_ignore_v<seq_type>)
281 throw std::logic_error{
"The SEQ and SEQ_QUAL fields may not both be set to ignore when writing FASTQ files."};
286 throw std::runtime_error{
"The SEQ field may not be empty when writing FASTQ files."};
294 if constexpr (!detail::decays_to_ignore_v<id_type>)
305 if constexpr (detail::decays_to_ignore_v<qual_type>)
307 throw std::logic_error{
"The QUAL and SEQ_QUAL fields may not both be set to ignore when writing FASTQ files."};
311 if (
empty(qualities))
312 throw std::runtime_error{
"The SEQ field may not be empty when writing FASTQ files."};
316 assert(
size(sequence) ==
size(qualities));
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: transform.hpp:95
Provides C++20 additions to the <iterator> header.
Contains various shortcuts for common std::ranges functions.
Provides seqan3::detail::ignore_output_iterator for writing to null stream.
Provides seqan3::view::take.
auto constexpr is_blank
Checks whether c is a blank character.
Definition: parse_condition.hpp:188
::ranges::copy copy
Alias for ranges::copy. Copies a range of elements to a new location.
Definition: ranges:200
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Contains seqan3::dna5, container aliases and string literals.
bool fastq_double_id
Whether to write the ID only '@' or also after '+' line.
Definition: output_options.hpp:61
::ranges::ostreambuf_iterator ostreambuf_iterator
Alias for ranges::ostreambuf_iterator. Output iterator that writes to std::basic_streambuf.
Definition: ranges:230
Provides seqan3::view::take_line and seqan3::view::take_line_or_throw.
Provides seqan3::view::subrange.
auto constexpr is_cntrl
Checks whether c is a control character.
Definition: parse_condition.hpp:135
Thrown if there is a parse error, such as reading an unexpected character from an input stream...
Definition: exception.hpp:70
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:471
Adaptations of concepts from the Ranges TS.
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition: to_char.hpp:88
std::ranges::iterator_range< it_t, sen_t > subrange
Create a view from a pair of iterator and sentinel.
Definition: subrange.hpp:96
bool add_carriage_return
The default plain text line-ending is "\n", but on Windows an additional carriage return is recommend...
Definition: output_options.hpp:66
auto constexpr is_space
Checks whether c is a space character.
Definition: parse_condition.hpp:171
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:462
The options type defines various option members that influence the behaviour of all or some formats...
Definition: output_options.hpp:48
::ranges::empty empty
Alias for ranges::empty. Checks whether a range is empty.
Definition: ranges:205
Provides seqan3::view::to_char.
Provides parse conditions for tokenization.
Provides various metafunctions used by the range module.
Contains aliases for qualified.
constexpr auto back_inserter(container_t &container)
Create a std::back_insert_iterator for the argument.
Definition: iterator:79
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
Provides seqan3::view::take_exactly and seqan3::view::take_exactly_or_throw.
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:122
auto const char_to
A view over an alphabet, given a range of characters.
Definition: char_to.hpp:92