21 #include <range/v3/view/chunk.hpp> 22 #include <range/v3/view/repeat_n.hpp> 92 class sequence_file_input_format<format_embl>
96 using format_tag = format_embl;
101 sequence_file_input_format() noexcept = default;
102 sequence_file_input_format(sequence_file_input_format const &) = delete;
105 sequence_file_input_format & operator=(sequence_file_input_format const &) = delete;
106 sequence_file_input_format(sequence_file_input_format &&) noexcept = default;
107 sequence_file_input_format & operator=(sequence_file_input_format &&) noexcept = default;
108 ~sequence_file_input_format() noexcept = default;
112 template <typename stream_type,
113 typename seq_legal_alph_type,
bool seq_qual_combined,
117 void read(stream_type & stream,
118 sequence_file_input_options<seq_legal_alph_type, seq_qual_combined> const & options,
121 qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
129 if (idbuffer !=
"ID")
130 throw parse_error{
"An entry has to start with the code word ID."};
132 if constexpr (!detail::decays_to_ignore_v<id_type>)
134 if (options.embl_genbank_complete_header)
142 id.push_back(*stream_it);
144 }
while (*stream_it !=
'Q');
154 if (options.truncate_ids)
176 }
while (*stream_it !=
'Q');
181 auto constexpr is_end =
is_char<
'/'> ;
182 if constexpr (!detail::decays_to_ignore_v<seq_type>)
187 auto constexpr is_legal_alph = is_in_alphabet<seq_legal_alph_type>;
190 if (!is_legal_alph(c))
192 throw parse_error{
std::string{
"Encountered an unexpected letter: "} +
193 is_legal_alph.msg.str() +
194 " evaluated to false on " +
195 detail::make_printable(c)};
216 class sequence_file_output_format<format_embl>
220 using format_tag = format_embl;
225 sequence_file_output_format() noexcept = default;
226 sequence_file_output_format(sequence_file_output_format const &) = delete;
229 sequence_file_output_format & operator=(sequence_file_output_format const &) = delete;
230 sequence_file_output_format(sequence_file_output_format &&) noexcept = default;
231 sequence_file_output_format & operator=(sequence_file_output_format &&) noexcept = default;
232 ~sequence_file_output_format() noexcept = default;
236 template <typename stream_type,
240 void write(stream_type & stream,
241 sequence_file_output_options const & options,
242 seq_type && sequence,
244 qual_type && SEQAN3_DOXYGEN_ONLY(qualities))
247 [[maybe_unused]]
size_t sequence_size = 0;
248 [[maybe_unused]]
char buffer[50];
249 if constexpr (!detail::decays_to_ignore_v<seq_type>)
253 if constexpr (detail::decays_to_ignore_v<id_type>)
255 throw std::logic_error{
"The ID field may not be set to ignore when writing embl files."};
262 if (options.embl_genbank_complete_header)
271 auto res =
std::to_chars(&buffer[0], &buffer[0] +
sizeof(buffer), sequence_size);
272 std::copy(&buffer[0], res.ptr, stream_it);
279 if constexpr (detail::decays_to_ignore_v<seq_type>)
281 throw std::logic_error{
"The SEQ field may not be set to ignore when writing embl files."};
289 auto res =
std::to_chars(&buffer[0], &buffer[0] +
sizeof(buffer), sequence_size);
290 std::copy(&buffer[0], res.ptr, stream_it);
292 auto seqChunk = sequence | ranges::view::chunk(60);
295 for (
auto chunk : seqChunk)
298 | ranges::view::chunk(10)
302 bp =
std::min(sequence_size, bp + 60);
303 uint8_t num_blanks = 60 * i - bp;
304 num_blanks += num_blanks / 10;
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition: predicate.hpp:83
Provides seqan3::view::istreambuf.
auto constexpr take_until
A view adaptor that returns elements from the underlying range until the functor evaluates to true (o...
Definition: take_until.hpp:599
::ranges::ostreambuf_iterator ostreambuf_iterator
Alias for ranges::ostreambuf_iterator. Writes successive characters onto the output stream from which...
Definition: iterator.hpp:56
constexpr auto istreambuf
A view factory that returns a view over the stream buffer of an input stream.
Definition: istreambuf.hpp:245
::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 std::from_chars and std::to_chars if not defined in the stl <charconv> header.
constexpr auto join
Flattens a View of ranges into a View.
Definition: ranges:683
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
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.
auto constexpr is_digit
Checks whether c is a digital character.
Definition: predicate.hpp:287
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.
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:97
Provides various transformation traits used by the range module.
auto constexpr is_space
Checks whether c is a space character.
Definition: predicate.hpp:146
auto constexpr is_cntrl
Checks whether c is a control character.
Definition: predicate.hpp:110
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 const char_to
A view over an alphabet, given a range of characters.
Definition: char_to.hpp:70