102 template <
typename stream_type,
103 typename seq_legal_alph_type,
104 bool structured_seq_combined,
108 typename structure_type,
109 typename energy_type,
111 typename comment_type,
112 typename offset_type>
121 react_type & SEQAN3_DOXYGEN_ONLY(
react),
122 react_type & SEQAN3_DOXYGEN_ONLY(
react_err),
123 comment_type & SEQAN3_DOXYGEN_ONLY(
comment),
124 offset_type & SEQAN3_DOXYGEN_ONLY(
offset))
126 auto stream_view = detail::istreambuf(stream);
129 constexpr auto is_id =
is_char<
'>'>;
130 if (is_id(*begin(stream_view)))
132 if constexpr (!detail::decays_to_ignore_v<id_type>)
140 detail::consume(stream_view | detail::take_line_or_throw);
145 | detail::take_line_or_throw
152 detail::consume(stream_view | detail::take_line_or_throw);
155 else if constexpr (!detail::decays_to_ignore_v<id_type>)
157 constexpr auto is_legal_seq = char_is_valid_for<seq_legal_alph_type>;
158 if (!is_legal_seq(*begin(stream_view)))
161 +
" and char_is_valid_for<" + detail::type_name_as_string<seq_legal_alph_type>
162 +
">" +
" evaluated to false on " + detail::make_printable(*begin(stream_view))};
167 if constexpr (!detail::decays_to_ignore_v<seq_type>)
169 constexpr auto is_legal_seq = char_is_valid_for<seq_legal_alph_type>;
171 stream_view | detail::take_line_or_throw
173 | std::views::transform(
174 [is_legal_seq](
char const c)
176 if (!is_legal_seq(c))
179 +
"char_is_valid_for<"
180 + detail::type_name_as_string<seq_legal_alph_type>
181 +
"> evaluated to false on " + detail::make_printable(c)};
190 detail::consume(stream_view | detail::take_line_or_throw);
194 [[maybe_unused]] int64_t structure_length{};
195 if constexpr (!detail::decays_to_ignore_v<structure_type>)
197 if constexpr (structured_seq_combined)
200 using alph_type =
typename std::ranges::range_value_t<structure_type>::structure_alphabet_type;
206 if constexpr (!detail::decays_to_ignore_v<bpp_type>)
207 detail::bpp_from_rna_structure<alph_type>(
bpp,
structure);
211 using alph_type = std::ranges::range_value_t<structure_type>;
213 structure_length = std::ranges::distance(
structure);
215 if constexpr (!detail::decays_to_ignore_v<bpp_type>)
216 detail::bpp_from_rna_structure<alph_type>(
bpp,
structure);
219 else if constexpr (!detail::decays_to_ignore_v<bpp_type>)
221 detail::bpp_from_rna_structure<wuss51>(
bpp, read_structure<wuss51>(stream_view));
222 structure_length = std::ranges::distance(
bpp);
226 detail::consume(stream_view | detail::take_until(
is_space));
229 if constexpr (!detail::decays_to_ignore_v<seq_type>
230 && !(detail::decays_to_ignore_v<structure_type> && detail::decays_to_ignore_v<bpp_type>))
232 if (std::ranges::distance(
seq) != structure_length)
233 throw parse_error{
"Found sequence and associated structure of different length."};
237 if constexpr (!detail::decays_to_ignore_v<energy_type>)
239 std::string e_str = stream_view | detail::take_line
244 size_t num_processed;
246 if (num_processed != e_str.
size())
254 detail::consume(stream_view | detail::take_line);
256 detail::consume(stream_view | detail::take_until(!
is_space));
260 template <
typename stream_type,
264 typename structure_type,
265 typename energy_type,
267 typename comment_type,
268 typename offset_type>
273 bpp_type && SEQAN3_DOXYGEN_ONLY(
bpp),
276 react_type && SEQAN3_DOXYGEN_ONLY(
react),
277 react_type && SEQAN3_DOXYGEN_ONLY(
react_err),
278 comment_type && SEQAN3_DOXYGEN_ONLY(
comment),
279 offset_type && SEQAN3_DOXYGEN_ONLY(
offset))
284 if constexpr (!detail::decays_to_ignore_v<id_type>)
286 if (!std::ranges::empty(
id))
296 if constexpr (!detail::decays_to_ignore_v<seq_type>)
298 if (std::ranges::empty(
seq))
299 throw std::runtime_error{
"The SEQ field may not be empty when writing Vienna files."};
306 throw std::logic_error{
"The SEQ and STRUCTURED_SEQ fields may not both be set to ignore "
307 "when writing Vienna files."};
311 if constexpr (!detail::decays_to_ignore_v<structure_type>)
317 if constexpr (!detail::decays_to_ignore_v<energy_type>)
337 if (len < 0 || len >= 100)
346 else if constexpr (!detail::decays_to_ignore_v<energy_type>)
348 throw std::logic_error{
"The ENERGY field cannot be written to a Vienna file without providing STRUCTURE."};
359 template <
typename alph_type,
typename stream_view_type>
360 auto read_structure(stream_view_type & stream_view)
362 constexpr auto is_legal_structure = char_is_valid_for<alph_type>;
363 return stream_view | detail::take_until(
is_space)
364 | std::views::transform(
365 [is_legal_structure](
char const c)
367 if (!is_legal_structure(c))
370 + detail::type_name_as_string<alph_type>
371 +
"> evaluated to false on " + detail::make_printable(c)};
375 | 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:60
auto const char_to
A view over an alphabet, given a range of characters.
Definition char_to.hpp:64
@ 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:139
constexpr auto is_digit
Checks whether c is a digital character.
Definition predicate.hpp:259
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition predicate.hpp:60
constexpr auto is_space
Checks whether c is a space character.
Definition predicate.hpp:122
constexpr auto is_cntrl
Checks whether c is a control character.
Definition predicate.hpp:87
seqan::stl::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:23
Provides various utility functions.
Helper functions (e.g. conversions) for the structure IO submodule.
Provides seqan3::detail::istreambuf.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:45
The options type defines various option members that influence the behaviour of all or some formats.
Definition structure_file/output_options.hpp:23
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:27
int precision
The precision for writing floating point types.
Definition structure_file/output_options.hpp:30
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.