50 #include <range/v3/algorithm/equal.hpp> 51 #include <range/v3/view/zip.hpp> 62 #include <seqan3/io/detail/record.hpp> 278 template <detail::fields_concept selected_field_
ids_ = fields<field::SEQ, field::ID, field::STRUCTURE>,
279 detail::type_list_of_structure_file_output_formats_concept val
id_formats_
280 = type_list<structure_file_format_vienna>,
281 ostream_concept<
char> stream_type_ = std::ofstream>
309 static_assert([] () constexpr
311 for (
field f : selected_field_ids::as_array)
312 if (!field_ids::contains(f))
316 "You selected a field that is not valid for structure files, please refer to the documentation " 317 "of structure_file_out::field_ids for the accepted values.");
319 static_assert([] () constexpr
321 return !(selected_field_ids::contains(field::STRUCTURED_SEQ) &&
322 (selected_field_ids::contains(field::SEQ) ||
323 (selected_field_ids::contains(field::STRUCTURE))));
324 }(),
"You may not select field::STRUCTURED_SEQ and either of field::SEQ and field::STRUCTURE " 325 "at the same time.");
331 using value_type = void;
332 using reference = void;
333 using const_reference = void;
334 using size_type = void;
338 using iterator = detail::out_file_iterator<structure_file_out>;
374 stream.open(_file_name, std::ios_base::out | std::ios::binary);
375 if (!stream.is_open())
379 detail::set_format(format, _file_name);
389 template <structure_file_output_format_concept file_format>
391 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
393 stream{std::move(_stream)}, format{file_format{}}
395 static_assert(meta::in<valid_formats, file_format>::value,
396 "You selected a format that is not in the valid_formats of this file.");
499 template <
typename tuple_t>
504 write_record(detail::get_or_ignore<selected_field_ids::index_of(field::SEQ)>(t),
505 detail::get_or_ignore<selected_field_ids::index_of(field::ID)>(t),
506 detail::get_or_ignore<selected_field_ids::index_of(field::BPP)>(t),
507 detail::get_or_ignore<selected_field_ids::index_of(field::STRUCTURE)>(t),
508 detail::get_or_ignore<selected_field_ids::index_of(field::STRUCTURED_SEQ)>(t),
509 detail::get_or_ignore<selected_field_ids::index_of(field::ENERGY)>(t),
510 detail::get_or_ignore<selected_field_ids::index_of(field::REACT)>(t),
511 detail::get_or_ignore<selected_field_ids::index_of(field::REACT_ERR)>(t),
512 detail::get_or_ignore<selected_field_ids::index_of(field::COMMENT)>(t),
513 detail::get_or_ignore<selected_field_ids::index_of(
field::OFFSET)>(t));
554 template <
typename arg_t,
typename ... arg_types>
592 template <std::ranges::InputRange rng_t>
596 for (
auto &&
record : range)
645 template <std::ranges::InputRange rng_t>
654 template <std::ranges::InputRange rng_t>
705 template <
typename typelist,
typename field_
ids>
708 write_columns(detail::range_wrap_ignore(detail::get_or_ignore<field::SEQ>(r)),
709 detail::range_wrap_ignore(detail::get_or_ignore<field::ID>(r)),
710 detail::range_wrap_ignore(detail::get_or_ignore<field::BPP>(r)),
711 detail::range_wrap_ignore(detail::get_or_ignore<field::STRUCTURE>(r)),
712 detail::range_wrap_ignore(detail::get_or_ignore<field::STRUCTURED_SEQ>(r)),
713 detail::range_wrap_ignore(detail::get_or_ignore<field::ENERGY>(r)),
714 detail::range_wrap_ignore(detail::get_or_ignore<field::REACT>(r)),
715 detail::range_wrap_ignore(detail::get_or_ignore<field::REACT_ERR>(r)),
716 detail::range_wrap_ignore(detail::get_or_ignore<field::COMMENT>(r)),
717 detail::range_wrap_ignore(detail::get_or_ignore<field::OFFSET>(r)));
758 template <
typename ... arg_types>
763 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::SEQ)>(t)),
764 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::ID)>(t)),
765 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::BPP)>(t)),
766 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::STRUCTURE)>(t)),
767 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::STRUCTURED_SEQ)>(t)),
768 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::ENERGY)>(t)),
769 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::REACT)>(t)),
770 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::REACT_ERR)>(t)),
771 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(field::COMMENT)>(t)),
772 detail::range_wrap_ignore(detail::get_or_ignore<selected_field_ids::index_of(
field::OFFSET)>(t)));
791 std::string file_name;
797 using format_type = detail::transfer_template_args_onto_t<valid_formats, std::variant>;
802 template <
typename seq_type,
805 typename structure_type,
806 typename structured_seq_type,
807 typename energy_type,
809 typename comment_type,
810 typename offset_type>
811 void write_record(seq_type && seq,
814 structure_type && structure,
815 structured_seq_type && structured_seq,
816 energy_type && energy,
818 react_type && react_error,
819 comment_type && comment,
820 offset_type && offset)
822 static_assert(detail::decays_to_ignore_v<structured_seq_type> ||
823 (detail::decays_to_ignore_v<seq_type> && detail::decays_to_ignore_v<structure_type>),
824 "You may not select field::STRUCTURED_SEQ and either of field::SEQ and field::STRUCTURE " 825 "at the same time.");
827 assert(!format.valueless_by_exception());
828 std::visit([&] (
auto & f)
830 if constexpr (!detail::decays_to_ignore_v<structured_seq_type>)
834 structured_seq | view::convert<typename structured_seq_type::sequence_alphabet_type>,
837 structured_seq | view::convert<typename structured_seq_type::structure_alphabet_type>,
871 void write_columns(seq_type && seq,
874 structure_type && structure,
875 structured_seq_type && structured_seq,
876 energy_type && energy,
878 react_type && react_error,
879 comment_type && comment,
880 offset_type && offset)
891 "At least one of the columns must not be set to std::ignore.");
896 "You may not select field::STRUCTURED_SEQ and either of field::SEQ and field::STRUCTURE " 897 "at the same time.");
899 assert(!format.valueless_by_exception());
900 std::visit([&] (
auto & f)
904 auto zipped = ranges::view::zip(structured_seq,
id, bpp, energy, react, react_error, comment, offset);
906 for (
auto && v : zipped)
925 auto zipped = ranges::view::zip(seq,
id, bpp, structure, energy, react, react_error, comment, offset);
927 for (
auto && v : zipped)
929 f.write(stream, options, std::get<0>(v), std::get<1>(v), std::get<2>(v), std::get<3>(v),
930 std::get<4>(v), std::get<5>(v), std::get<6>(v), std::get<7>(v), std::get<8>(v));
944 template <ostream_concept<
char> stream_type,
945 structure_file_output_format_concept file_format,
946 detail::fields_concept selected_field_
ids>
950 std::remove_reference_t<stream_type>>;
auto const convert
A view that converts each element in the input range (implicitly or via static_cast).
Definition: convert.hpp:89
friend structure_file_out operator|(rng_t &&range, structure_file_out &&f) requires tuple_like_concept< reference_t< rng_t >>
Definition: output.hpp:655
structure_file_out & operator=(std::tuple< arg_types... > const &t)
Write columns (wrapped in a std::tuple) to the file.
Definition: output.hpp:759
The "sequence", usually a range of nucleotides or amino acids.
structure_file_out & operator=(rng_t &&range) requires tuple_like_concept< reference_t< rng_t >>
Write a range of records (or tuples) to the file.
Definition: output.hpp:593
structure_file_out & operator=(record< typelist, field_ids > const &r)
Write columns (wrapped in a seqan3::record) to the file.
Definition: output.hpp:706
structure_file_out(filesystem::path const &_file_name, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: output.hpp:370
~structure_file_out()=default
Destructor is defaulted.
Provides exceptions used in the I/O module.
Sequence and fixed interactions combined in one range.
Energy of a folded sequence, represented by one float number.
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: output.hpp:292
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: output.hpp:458
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:208
Provides seqan3::type_list and auxiliary metafunctions.
Whether a type behaves like a tuple.
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: output.hpp:290
Comment field of arbitrary content, usually a string.
Meta-header for the structure module. It includes all headers from alphabet/structure/.
Provides seqan3::view::convert.
void push_back(tuple_t &&t) requires tuple_like_concept< tuple_t >
Write a record in form of a std::tuple to the file.
Definition: output.hpp:500
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
detail::out_file_iterator< structure_file_out > iterator
The iterator type of this view (an output iterator).
Definition: output.hpp:338
Base pair probability matrix of interactions, usually a matrix of float numbers.
structure_file_output_options options
The options are public and its members can be set directly.
Definition: output.hpp:778
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem...
Definition: exception.hpp:62
A class template that holds a choice of seqan3::field.
Definition: record.hpp:136
Provides seqan3::structure_file_output_options.
Provides seqan3::tuple_like_concept.
Reactivity error values given in a vector corresponding to REACT.
Provides the seqan3::record template and the seqan3::field enum.
Sequence (SEQ) relative start position (0-based), unsigned value.
The identifier, usually a string.
Adaptations of concepts from the Ranges TS.
stream_type_ stream_type
The type of the underlying stream.
Definition: output.hpp:294
std::ptrdiff_t difference_type
A signed integer type, usually std::ptrdiff_t.
Definition: output.hpp:336
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition: output.hpp:439
std::ranges::default_sentinel sentinel
The type returned by end().
Definition: output.hpp:342
Fixed interactions, usually a string of structure alphabet characters.
The options type defines various option members that influence the behaviour of all or some formats...
Definition: output_options.hpp:50
A class for writing structured sequence files, e.g. Stockholm, Connect, Vienna, ViennaRNA bpp matrix ...
Definition: output.hpp:282
structure_file_out()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...
Provides C++20 additions to the type_traits header.
Provides various metafunctions on generic types.
Provides the seqan3::detail::out_file_iterator class template.
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:54
structure_file_out & operator=(structure_file_out const &)=delete
Copy assignment is explicitly deleted, because you can't have multiple access to the same file...
field
An enumerator for the fields used in file formats.Some of the fields are shared between formats...
Definition: record.hpp:63
structure_file_out(stream_type &&_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:390
void const_iterator
The const iterator type is void, because files are not const-iterable.
Definition: output.hpp:340
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition: output.hpp:555
Reactivity values of the sequence characters given in a vector of float numbers.
friend structure_file_out & operator|(rng_t &&range, structure_file_out &f) requires tuple_like_concept< reference_t< rng_t >>
Write a range of records (or tuples) to the file.
Definition: output.hpp:646
::ranges::default_sentinel default_sentinel
Alias for ranges::default_sentinel. Empty sentinel type for use with iterator types that know the bou...
Definition: ranges:215