96 template <
typename stream_type,
97 typename seq_legal_alph_type,
98 typename stream_pos_type,
104 stream_pos_type & position_buffer,
107 qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
112 position_buffer = stream.tellg();
114 auto stream_view = detail::istreambuf(stream);
115 auto stream_it = std::ranges::begin(stream_view);
117 if (!(std::ranges::equal(stream_view | detail::take_until_or_throw(
is_cntrl ||
is_blank),
119 throw parse_error{
"An entry has to start with the code word LOCUS."};
122 if constexpr (!detail::decays_to_ignore_v<id_type>)
128 while (!
is_char<
'O'>(*std::ranges::begin(stream_view)))
130 std::ranges::copy(stream_view | detail::take_line_or_throw
138 detail::consume(stream_view | detail::take_until(!
is_blank));
140 auto read_id_until = [&stream_view, &
id](
auto predicate)
142 std::ranges::copy(stream_view | detail::take_until_or_throw(predicate)
152 detail::consume(stream_view | detail::take_line_or_throw);
158 detail::consume(stream_view | detail::take_line_or_throw);
161 detail::consume(stream_view | detail::take_line_or_throw);
162 constexpr auto is_end =
is_char<
'/'>;
163 if constexpr (!detail::decays_to_ignore_v<seq_type>)
165 constexpr auto is_legal_alph = char_is_valid_for<seq_legal_alph_type>;
168 | detail::take_until_or_throw(is_end)
169 | std::views::transform(
170 [is_legal_alph](
char const c)
172 if (!is_legal_alph(c))
175 +
"char_is_valid_for<"
176 + detail::type_name_as_string<seq_legal_alph_type>
177 +
"> evaluated to false on " + detail::make_printable(c)};
186 detail::consume(stream_view | detail::take_until_or_throw(is_end));
189 std::ranges::advance(stream_it, 3u, std::ranges::end(stream_view));
193 template <
typename stream_type,
201 qual_type && SEQAN3_DOXYGEN_ONLY(qualities))
204 size_t sequence_size{0};
205 [[maybe_unused]]
char buffer[50];
206 if constexpr (!detail::decays_to_ignore_v<seq_type>)
207 sequence_size = std::ranges::size(
sequence);
210 if constexpr (detail::decays_to_ignore_v<id_type>)
212 throw std::logic_error{
"The ID field may not be set to ignore when writing genbank files."};
214 else if (std::ranges::empty(
id))
216 throw std::runtime_error{
"The ID field may not be empty when writing genbank files."};
220 std::ranges::copy(
id, stream_it);
225 std::ranges::copy(
id, stream_it);
227 auto res = std::to_chars(&buffer[0], &buffer[0] +
sizeof(buffer), sequence_size);
228 std::copy(&buffer[0], res.ptr, stream_it);
233 if constexpr (detail::decays_to_ignore_v<seq_type>)
235 throw std::logic_error{
"The SEQ field may not be set to ignore when writing genbank files."};
237 else if (std::ranges::empty(
sequence))
239 throw std::runtime_error{
"The SEQ field may not be empty when writing genbank files."};
248 while (bp < sequence_size)
259 detail::write_eol(stream_it,
false);
262 detail::write_eol(stream_it,
false);
Core alphabet concept and free function/type trait wrappers.
T back_inserter(T... args)
Provides seqan3::views::char_to.
The <charconv> header from C++17's standard library.
Provides seqan3::views::chunk.
Provides various utility functions.
Provides various transformation traits used by the range module.
Provides seqan3::dna5, container aliases and string literals.
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:63
auto const char_to
A view over an alphabet, given a range of characters.
Definition char_to.hpp:67
@ id
The identifier, usually a string.
@ seq
The "sequence", usually a range of nucleotides or amino acids.
constexpr auto is_blank
Checks whether c is a blank character.
Definition predicate.hpp:142
constexpr auto is_digit
Checks whether c is a digital character.
Definition predicate.hpp:262
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition predicate.hpp:63
constexpr auto is_space
Checks whether c is a space character.
Definition predicate.hpp:125
constexpr auto is_cntrl
Checks whether c is a control character.
Definition predicate.hpp:90
seqan::stl::views::chunk chunk
A view adaptor that divides a range into chunks. <dl class="no-api">This entity is not part of the Se...
Definition chunk.hpp:26
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:379
The generic concept for a (biological) sequence.
Provides seqan3::views::interleave.
Provides various utility functions.
Provides seqan3::detail::istreambuf.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides character predicates for tokenisation.
Provides seqan3::sequence_file_output_options.
Thrown if there is a parse error, such as reading an unexpected character from an input stream.
Definition io/exception.hpp:48
The options type defines various option members that influence the behaviour of all or some formats.
Definition sequence_file/output_options.hpp:26
bool embl_genbank_complete_header
Complete header given for embl or genbank.
Definition sequence_file/output_options.hpp:45
Provides seqan3::detail::take_line and seqan3::detail::take_line_or_throw.
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Provides seqan3::views::to_char.
Provides traits to inspect some information of a type, for example its name.