30#include <seqan3/io/detail/record.hpp>
60template <detail::fields_specialisation selected_field_
ids_ = fields<field::seq, field::
id, field::structure>,
61 detail::type_list_of_structure_file_output_formats val
id_formats_ = type_list<format_vienna>>
89 static_assert([] ()
constexpr
91 for (
field f : selected_field_ids::as_array)
92 if (!field_ids::contains(f))
96 "You selected a field that is not valid for structure files, please refer to the documentation "
97 "of structure_file_output::field_ids for the accepted values.");
99 static_assert([] ()
constexpr
104 }(),
"You may not select field::structured_seq and either of field::seq and field::structure "
105 "at the same time.");
123 using iterator = detail::out_file_iterator<structure_file_output>;
165 primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
167 std::ios_base::out | std::ios::binary);
169 if (!primary_stream->good())
170 throw file_open_error{
"Could not open file " + filename.
string() +
" for writing."};
173 secondary_stream = detail::make_secondary_ostream(*primary_stream, filename);
176 detail::set_format(format, filename);
195 template <output_stream stream_t, structure_file_output_format file_format>
197 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
char>
200 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
202 primary_stream{&stream, stream_deleter_noop},
203 secondary_stream{&stream, stream_deleter_noop},
204 format{detail::structure_file_output_format_exposer<file_format>{}}
206 static_assert(list_traits::contains<file_format, valid_formats>,
207 "You selected a format that is not in the valid_formats of this file.");
211 template <output_stream stream_t, structure_file_output_format file_format>
213 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
char>
216 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
218 primary_stream{
new stream_t{std::move(stream)}, stream_deleter_default},
219 secondary_stream{&*primary_stream, stream_deleter_noop},
220 format{detail::structure_file_output_format_exposer<file_format>{}}
222 static_assert(list_traits::contains<file_format, valid_formats>,
223 "You selected a format that is not in the valid_formats of this file.");
290 template <
typename record_t>
293 requires detail::record_like<record_t>
296 write_record(detail::get_or_ignore<field::seq>(r),
297 detail::get_or_ignore<field::id>(r),
298 detail::get_or_ignore<field::bpp>(r),
299 detail::get_or_ignore<field::structure>(r),
300 detail::get_or_ignore<field::structured_seq>(r),
301 detail::get_or_ignore<field::energy>(r),
302 detail::get_or_ignore<field::react>(r),
303 detail::get_or_ignore<field::react_err>(r),
304 detail::get_or_ignore<field::comment>(r),
305 detail::get_or_ignore<field::offset>(r));
329 template <
typename tuple_t>
336 write_record(detail::get_or_ignore<selected_field_ids::index_of(
field::seq)>(t),
337 detail::get_or_ignore<selected_field_ids::index_of(
field::id)>(t),
338 detail::get_or_ignore<selected_field_ids::index_of(
field::bpp)>(t),
341 detail::get_or_ignore<selected_field_ids::index_of(
field::energy)>(t),
342 detail::get_or_ignore<selected_field_ids::index_of(
field::react)>(t),
344 detail::get_or_ignore<selected_field_ids::index_of(
field::comment)>(t),
345 detail::get_or_ignore<selected_field_ids::index_of(
field::offset)>(t));
371 template <
typename arg_t,
typename ...arg_types>
398 template <std::ranges::input_range rng_t>
404 for (
auto &&
record : range)
436 template <std::ranges::input_range rng_t>
447 template <std::ranges::input_range rng_t>
466 return *secondary_stream;
486 stream_ptr_t primary_stream{
nullptr, stream_deleter_noop};
488 stream_ptr_t secondary_stream{
nullptr, stream_deleter_noop};
491 using format_type =
typename detail::variant_from_tags<
valid_formats,
492 detail::structure_file_output_format_exposer>::type;
498 template <
typename seq_type,
501 typename structure_type,
502 typename structured_seq_type,
503 typename energy_type,
505 typename comment_type,
506 typename offset_type>
507 void write_record(seq_type && seq,
510 structure_type && structure,
511 structured_seq_type && structured_seq,
512 energy_type && energy,
514 react_type && react_error,
515 comment_type && comment,
516 offset_type && offset)
518 static_assert(detail::decays_to_ignore_v<structured_seq_type> ||
519 (detail::decays_to_ignore_v<seq_type> && detail::decays_to_ignore_v<structure_type>),
520 "You may not select field::structured_seq and either of field::seq and field::structure "
521 "at the same time.");
523 assert(!
format.valueless_by_exception());
526 if constexpr (!detail::decays_to_ignore_v<structured_seq_type>)
528 f.write_structure_record(*secondary_stream,
530 structured_seq | views::elements<0>,
533 structured_seq | views::elements<1>,
542 f.write_structure_record(*secondary_stream,
567template <output_stream stream_t,
569 detail::fields_specialisation selected_field_ids>
575template <output_stream stream_t,
A class for writing structured sequence files, e.g. Stockholm, Connect, Vienna, ViennaRNA bpp matrix ...
Definition: output.hpp:63
std::default_sentinel_t sentinel
The type returned by end().
Definition: output.hpp:127
void push_back(tuple_t &&t)
Write a record in form of a std::tuple to the file.
Definition: output.hpp:330
structure_file_output(stream_t &stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from an existing stream and with specified format.
Definition: output.hpp:199
void const_reference
The const reference type (void).
Definition: output.hpp:117
detail::out_file_iterator< structure_file_output > iterator
The iterator type of this view (an output iterator).
Definition: output.hpp:123
char stream_char_type
Character type of the stream(s).
Definition: output.hpp:74
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition: output.hpp:291
structure_file_output(stream_t &&stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: output.hpp:215
structure_file_output & operator=(structure_file_output &&)=default
Move assignment is defaulted.
structure_file_output_options options
The options are public and its members can be set directly.
Definition: output.hpp:459
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: output.hpp:70
structure_file_output()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
structure_file_output(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: output.hpp:161
friend structure_file_output operator|(rng_t &&range, structure_file_output &&f)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: output.hpp:448
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition: output.hpp:372
friend structure_file_output & operator|(rng_t &&range, structure_file_output &f)
Write a range of records (or tuples) to the file.
Definition: output.hpp:437
void size_type
The size type (void).
Definition: output.hpp:119
structure_file_output(stream_t &&, file_format const &, selected_field_ids const &) -> structure_file_output< selected_field_ids, type_list< file_format > >
Deduction of the selected fields, the file format and the stream type.
void reference
The reference type (void).
Definition: output.hpp:115
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition: output.hpp:248
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: output.hpp:267
structure_file_output(stream_t &, file_format const &, selected_field_ids const &) -> structure_file_output< selected_field_ids, type_list< file_format > >
This is an overloaded member function, provided for convenience. It differs from the above function o...
structure_file_output & operator=(structure_file_output const &)=delete
Copy assignment is explicitly deleted, because you can't have multiple access to the same file.
structure_file_output(structure_file_output &&)=default
Move construction is defaulted.
void value_type
The value type (void).
Definition: output.hpp:113
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: output.hpp:72
structure_file_output & operator=(rng_t &&range)
Write a range of records (or tuples) to the file.
Definition: output.hpp:399
void const_iterator
The const iterator type is void, because files are not const-iterable.
Definition: output.hpp:125
~structure_file_output()=default
Destructor is defaulted.
structure_file_output(structure_file_output const &)=delete
Copy construction is explicitly deleted, because you can't have multiple access to the same file.
Provides seqan3::views::elements.
The <filesystem> header from C++17's standard library.
field
An enumerator for the fields used in file formats.
Definition: record.hpp:63
@ 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.
@ structured_seq
Sequence and fixed interactions combined in one range.
@ id
The identifier, usually a string.
@ seq
The "sequence", usually a range of nucleotides or amino acids.
constexpr bool contains
Whether a type occurs in a type list or not.
Definition: traits.hpp:231
Whether a type behaves like a tuple.
Provides exceptions used in the I/O module.
Provides various utility functions required only for output.
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
Provides the seqan3::detail::out_file_iterator class template.
The <ranges> header from C++20's standard library.
Provides the seqan3::record template and the seqan3::field enum.
Provides seqan3::detail::record_like.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:128
The class template that file records are based on; behaves like a std::tuple.
Definition: record.hpp:191
The options type defines various option members that influence the behaviour of all or some formats.
Definition: output_options.hpp:26
Type that contains multiple types.
Definition: type_list.hpp:29
Provides seqan3::structure_file_output_options.
Provides traits for seqan3::type_list.
Provides seqan3::tuple_like.
Provides seqan3::views::convert.
Provides seqan3::views::zip.