105 template <
typename stream_type,
106 typename seq_legal_alph_type,
107 bool structured_seq_combined,
111 typename structure_type,
112 typename energy_type,
114 typename comment_type,
115 typename offset_type>
124 react_type & SEQAN3_DOXYGEN_ONLY(
react),
125 react_type & SEQAN3_DOXYGEN_ONLY(
react_err),
126 comment_type & SEQAN3_DOXYGEN_ONLY(
comment),
127 offset_type & SEQAN3_DOXYGEN_ONLY(
offset))
129 auto stream_view = detail::istreambuf(stream);
132 constexpr auto is_id =
is_char<
'>'>;
133 if (is_id(*begin(stream_view)))
135 if constexpr (!detail::decays_to_ignore_v<id_type>)
143 detail::consume(stream_view | detail::take_line_or_throw);
148 | detail::take_line_or_throw
155 detail::consume(stream_view | detail::take_line_or_throw);
158 else if constexpr (!detail::decays_to_ignore_v<id_type>)
160 constexpr auto is_legal_seq = char_is_valid_for<seq_legal_alph_type>;
161 if (!is_legal_seq(*begin(stream_view)))
164 +
" and char_is_valid_for<" + detail::type_name_as_string<seq_legal_alph_type>
165 +
">" +
" evaluated to false on " + detail::make_printable(*begin(stream_view))};
170 if constexpr (!detail::decays_to_ignore_v<seq_type>)
172 constexpr auto is_legal_seq = char_is_valid_for<seq_legal_alph_type>;
174 stream_view | detail::take_line_or_throw
176 | std::views::transform(
177 [is_legal_seq](
char const c)
179 if (!is_legal_seq(c))
182 +
"char_is_valid_for<"
183 + detail::type_name_as_string<seq_legal_alph_type>
184 +
"> evaluated to false on " + detail::make_printable(c)};
193 detail::consume(stream_view | detail::take_line_or_throw);
197 [[maybe_unused]] int64_t structure_length{};
198 if constexpr (!detail::decays_to_ignore_v<structure_type>)
200 if constexpr (structured_seq_combined)
203 using alph_type =
typename std::ranges::range_value_t<structure_type>::structure_alphabet_type;
209 if constexpr (!detail::decays_to_ignore_v<bpp_type>)
210 detail::bpp_from_rna_structure<alph_type>(
bpp,
structure);
214 using alph_type = std::ranges::range_value_t<structure_type>;
216 structure_length = std::ranges::distance(
structure);
218 if constexpr (!detail::decays_to_ignore_v<bpp_type>)
219 detail::bpp_from_rna_structure<alph_type>(
bpp,
structure);
222 else if constexpr (!detail::decays_to_ignore_v<bpp_type>)
224 detail::bpp_from_rna_structure<wuss51>(
bpp, read_structure<wuss51>(stream_view));
225 structure_length = std::ranges::distance(
bpp);
229 detail::consume(stream_view | detail::take_until(
is_space));
232 if constexpr (!detail::decays_to_ignore_v<seq_type>
233 && !(detail::decays_to_ignore_v<structure_type> && detail::decays_to_ignore_v<bpp_type>))
235 if (std::ranges::distance(
seq) != structure_length)
236 throw parse_error{
"Found sequence and associated structure of different length."};
240 if constexpr (!detail::decays_to_ignore_v<energy_type>)
242 std::string e_str = stream_view | detail::take_line
247 size_t num_processed;
249 if (num_processed != e_str.
size())
257 detail::consume(stream_view | detail::take_line);
259 detail::consume(stream_view | detail::take_until(!
is_space));
263 template <
typename stream_type,
267 typename structure_type,
268 typename energy_type,
270 typename comment_type,
271 typename offset_type>
276 bpp_type && SEQAN3_DOXYGEN_ONLY(
bpp),
279 react_type && SEQAN3_DOXYGEN_ONLY(
react),
280 react_type && SEQAN3_DOXYGEN_ONLY(
react_err),
281 comment_type && SEQAN3_DOXYGEN_ONLY(
comment),
282 offset_type && SEQAN3_DOXYGEN_ONLY(
offset))
287 if constexpr (!detail::decays_to_ignore_v<id_type>)
289 if (!std::ranges::empty(
id))
299 if constexpr (!detail::decays_to_ignore_v<seq_type>)
301 if (std::ranges::empty(
seq))
302 throw std::runtime_error{
"The SEQ field may not be empty when writing Vienna files."};
309 throw std::logic_error{
"The SEQ and STRUCTURED_SEQ fields may not both be set to ignore "
310 "when writing Vienna files."};
314 if constexpr (!detail::decays_to_ignore_v<structure_type>)
320 if constexpr (!detail::decays_to_ignore_v<energy_type>)
340 if (len < 0 || len >= 100)
349 else if constexpr (!detail::decays_to_ignore_v<energy_type>)
351 throw std::logic_error{
"The ENERGY field cannot be written to a Vienna file without providing STRUCTURE."};
362 template <
typename alph_type,
typename stream_view_type>
363 auto read_structure(stream_view_type & stream_view)
365 constexpr auto is_legal_structure = char_is_valid_for<alph_type>;
366 return stream_view | detail::take_until(
is_space)
367 | std::views::transform(
368 [is_legal_structure](
char const c)
370 if (!is_legal_structure(c))
373 + detail::type_name_as_string<alph_type>
374 +
"> evaluated to false on " + detail::make_printable(c)};
378 | views::char_to<alph_type>;
Core alphabet concept and free function/type trait wrappers.
T back_inserter(T... args)
Provides alphabet adaptations for standard char types.
Provides seqan3::views::char_to.
Provides various utility functions.
Provides various transformation traits used by the range module.
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
@ energy
Energy of a folded sequence, represented by one float number.
@ comment
Comment field of arbitrary content, usually a string.
@ structure
Fixed interactions, usually a string of structure alphabet characters.
@ bpp
Base pair probability matrix of interactions, usually a matrix of float numbers.
@ react
Reactivity values of the sequence characters given in a vector of float numbers.
@ react_err
Reactivity error values given in a vector corresponding to seqan3::field::react.
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
@ 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::std::ranges::to to
Converts a range to a container. <dl class="no-api">This entity is not part of the SeqAn API....
Definition: to.hpp:26
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.
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: structure_file/output_options.hpp:26
bool add_carriage_return
The default plain text line-ending is "\n", but on Windows an additional carriage return is recommend...
Definition: structure_file/output_options.hpp:30
int precision
The precision for writing floating point types.
Definition: structure_file/output_options.hpp:33
Provides seqan3::structure_file_output_options.
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::ranges::to.
Provides seqan3::views::to_char.
Provides traits to inspect some information of a type, for example its name.
Provides the WUSS format for RNA structure.