20 #include <range/v3/view/chunk.hpp> 91 class sequence_file_input_format<format_genbank>
95 using format_tag = format_genbank;
100 sequence_file_input_format() noexcept = default;
101 sequence_file_input_format(sequence_file_input_format const &) = delete;
104 sequence_file_input_format & operator=(sequence_file_input_format const &) = delete;
105 sequence_file_input_format(sequence_file_input_format &&) noexcept = default;
106 sequence_file_input_format & operator=(sequence_file_input_format &&) noexcept = default;
107 ~sequence_file_input_format() noexcept = default;
111 template <typename stream_type,
112 typename seq_legal_alph_type,
bool seq_qual_combined,
116 void read(stream_type & stream,
117 sequence_file_input_options<seq_legal_alph_type, seq_qual_combined> const & options,
120 qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
126 throw parse_error{
"An entry has to start with the code word LOCUS."};
129 if constexpr (!detail::decays_to_ignore_v<id_type>)
131 if (options.embl_genbank_complete_header)
155 while (!(is_char<'O'>(*
std::ranges::begin(stream_view)) || options.embl_genbank_complete_header))
160 auto constexpr is_end =
is_char<
'/'> ;
161 if constexpr (!detail::decays_to_ignore_v<seq_type>)
163 auto constexpr is_legal_alph = is_in_alphabet<seq_legal_alph_type>;
168 if (!is_legal_alph(c))
170 throw parse_error{
std::string{
"Encountered an unexpected letter: "} +
171 is_legal_alph.msg.str() +
172 " evaluated to false on " +
173 detail::make_printable(c)};
191 class sequence_file_output_format<format_genbank>
195 using format_tag = format_genbank;
200 sequence_file_output_format() noexcept = default;
201 sequence_file_output_format(sequence_file_output_format const &) = delete;
204 sequence_file_output_format & operator=(sequence_file_output_format const &) = delete;
205 sequence_file_output_format(sequence_file_output_format &&) noexcept = default;
206 sequence_file_output_format & operator=(sequence_file_output_format &&) noexcept = default;
207 ~sequence_file_output_format() noexcept = default;
211 template <typename stream_type,
215 void write(stream_type & stream,
216 sequence_file_output_options const & options,
217 seq_type && sequence,
219 qual_type && SEQAN3_DOXYGEN_ONLY(qualities))
222 size_t sequence_size{0};
223 [[maybe_unused]]
char buffer[50];
224 if constexpr (!detail::decays_to_ignore_v<seq_type>)
228 if constexpr (detail::decays_to_ignore_v<id_type>)
230 throw std::logic_error{
"The ID field may not be set to ignore when writing genbank files."};
234 throw std::runtime_error{
"The ID field may not be empty when writing genbank files."};
236 else if (options.embl_genbank_complete_header)
245 auto res =
std::to_chars(&buffer[0], &buffer[0] +
sizeof(buffer), sequence_size);
246 std::copy(&buffer[0], res.ptr, stream_it);
251 if constexpr (detail::decays_to_ignore_v<seq_type>)
253 throw std::logic_error{
"The SEQ field may not be set to ignore when writing genbank files."};
257 throw std::runtime_error{
"The SEQ field may not be empty when writing genbank files."};
262 auto seq = sequence | ranges::view::chunk(60);
266 while (bp < sequence_size)
278 detail::write_eol(stream_it,
false);
281 detail::write_eol(stream_it,
false);
::ranges::equal equal
Alias for ranges::equal. Determines if two sets of elements are the same.
Definition: algorithm:54
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
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
::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
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.
auto constexpr take_until_or_throw_and_consume
A view adaptor that returns elements from the underlying range until the functor evaluates to true (t...
Definition: take_until.hpp:641
Provides seqan3::dna5, container aliases and string literals.
Provides std::from_chars and std::to_chars if not defined in the stl <charconv> header.
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::view::interleave.
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.
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition: interleave.hpp:387
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
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
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