32 #include <seqan3/io/detail/record.hpp> 168 template <detail::fields_specialisation selected_field_ids_ =
184 detail::type_list_of_alignment_file_output_formats valid_formats_ = type_list<format_sam, format_bam>,
185 typename ref_ids_type = ref_info_not_given>
219 static_assert([] () constexpr
221 for (
field f : selected_field_ids::as_array)
222 if (!field_ids::contains(f))
226 "You selected a field that is not valid for alignment files, " 227 "please refer to the documentation of " 228 "seqan3::alignment_file_output::field_ids for the accepted values.");
230 static_assert([] () constexpr
235 "You may not select field::alignment and field::cigar at the same time.");
253 using iterator = detail::out_file_iterator<alignment_file_output>;
303 primary_stream{
new std::ofstream{filename, std::ios_base::out | std::ios::binary}, stream_deleter_default}
306 if (!primary_stream->good())
310 secondary_stream = detail::make_secondary_ostream(*primary_stream, filename);
313 detail::set_format(format, filename);
332 template <output_stream stream_type, alignment_file_output_format file_format>
337 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
339 primary_stream{&stream, stream_deleter_noop},
340 secondary_stream{&stream, stream_deleter_noop},
341 format{detail::alignment_file_output_format_exposer<file_format>{}}
343 static_assert(list_traits::contains<file_format, valid_formats>,
344 "You selected a format that is not in the valid_formats of this file.");
348 template <output_stream stream_type, alignment_file_output_format file_format>
350 requires std::same_as<typename std::remove_reference_t<stream_type>::char_type,
stream_char_type>
353 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
355 primary_stream{
new stream_type{
std::move(stream)}, stream_deleter_default},
356 secondary_stream{&*primary_stream, stream_deleter_noop},
357 format{detail::alignment_file_output_format_exposer<file_format>{}}
359 static_assert(list_traits::contains<file_format, valid_formats>,
360 "You selected a format that is not in the valid_formats of this file.");
393 template <
typename ref_
ids_type_, std::ranges::forward_range ref_lengths_type>
398 ref_ids_type_ && ref_ids,
399 ref_lengths_type && ref_lengths,
404 initialise_header_information(ref_ids, ref_lengths);
428 template <output_stream stream_type,
430 typename ref_ids_type_,
431 std::ranges::forward_range ref_lengths_type>
433 requires std::same_as<std::remove_reference_t<ref_ids_type_>, ref_ids_type>
436 ref_ids_type_ && ref_ids,
437 ref_lengths_type && ref_lengths,
438 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
442 initialise_header_information(ref_ids, ref_lengths);
509 template <
typename record_t>
513 requires { requires detail::is_type_specialisation_of_v<remove_cvref_t<record_t>,
record>; }
519 write_record(detail::get_or<field::header_ptr>(r,
nullptr),
523 detail::get_or<field::offset>(r, 0u),
525 detail::get_or<field::ref_id>(r, std::ignore),
527 detail::get_or<field::alignment>(r, default_align_t{}),
530 detail::get_or<field::mapq>(r, 0u),
531 detail::get_or<field::mate>(r, default_mate_t{}),
533 detail::get_or<field::evalue>(r, 0u),
534 detail::get_or<field::bit_score>(r, 0u));
558 template <
typename tuple_t>
568 write_record(detail::get_or<selected_field_ids::index_of(field::header_ptr)>(t,
nullptr),
569 detail::get_or<selected_field_ids::index_of(field::seq)>(t,
std::string_view{}),
570 detail::get_or<selected_field_ids::index_of(field::qual)>(t,
std::string_view{}),
571 detail::get_or<selected_field_ids::index_of(field::id)>(t,
std::string_view{}),
572 detail::get_or<selected_field_ids::index_of(field::offset)>(t, 0u),
573 detail::get_or<selected_field_ids::index_of(field::ref_seq)>(t,
std::string_view{}),
574 detail::get_or<selected_field_ids::index_of(field::ref_id)>(t, std::ignore),
576 detail::get_or<selected_field_ids::index_of(field::alignment)>(t, default_align_t{}),
578 detail::get_or<selected_field_ids::index_of(field::flag)>(t,
sam_flag::none),
579 detail::get_or<selected_field_ids::index_of(field::mapq)>(t, 0u),
580 detail::get_or<selected_field_ids::index_of(field::mate)>(t, default_mate_t{}),
582 detail::get_or<selected_field_ids::index_of(field::evalue)>(t, 0u),
583 detail::get_or<selected_field_ids::index_of(field::bit_score)>(t, 0u));
609 template <
typename arg_t,
typename ...arg_types>
636 template <
typename rng_t>
642 for (
auto &&
record : range)
675 template <
typename rng_t>
686 template <
typename rng_t>
705 return *secondary_stream;
722 throw std::logic_error{
"Please construct your file with reference id and length information in order " 723 "to properly initialise the header before accessing it."};
743 stream_ptr_t primary_stream{
nullptr, stream_deleter_noop};
745 stream_ptr_t secondary_stream{
nullptr, stream_deleter_noop};
748 using format_type =
typename detail::variant_from_tags<
valid_formats,
749 detail::alignment_file_output_format_exposer>::type;
764 template <
typename ref_
ids_type_,
typename ref_lengths_type>
765 void initialise_header_information(ref_ids_type_ && ref_ids, ref_lengths_type && ref_lengths)
769 header_ptr = std::make_unique<alignment_file_header<ref_ids_type>>(std::forward<ref_ids_type_>(ref_ids));
771 for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
773 header_ptr->ref_id_info.emplace_back(ref_lengths[idx],
"");
779 auto &&
id = header_ptr->ref_ids()[idx];
780 header_ptr->ref_dict[std::span{std::ranges::data(
id),
std::ranges::size(
id)}] = idx;
784 header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
790 template <
typename record_header_ptr_t,
typename ...pack_type>
791 void write_record(record_header_ptr_t && record_header_ptr, pack_type && ...remainder)
793 static_assert((
sizeof...(pack_type) == 15),
"Wrong parameter list passed to write_record.");
795 assert(!format.valueless_by_exception());
802 f.write_alignment_record(*secondary_stream,
805 std::forward<pack_type>(remainder)...);
809 f.write_alignment_record(*secondary_stream,
812 std::forward<pack_type>(remainder)...);
816 f.write_alignment_record(*secondary_stream,
819 std::forward<pack_type>(remainder)...);
836 template <detail::fields_specialisation selected_field_
ids>
845 template <output_stream stream_type,
847 detail::fields_specialisation selected_field_ids>
856 template <output_stream stream_type,
858 detail::fields_specialisation selected_field_ids>
861 type_list<file_format>,
867 template <output_stream stream_type,
871 type_list<file_format>,
877 template <output_stream stream_type,
881 type_list<file_format>,
886 std::ranges::forward_range ref_ids_type,
887 std::ranges::forward_range ref_lengths_type>
891 selected_field_ids
const &)
893 typename alignment_file_output<>::valid_formats,
897 template <std::ranges::forward_range ref_ids_type,
898 std::ranges::forward_range ref_lengths_type>
903 typename alignment_file_output<>::valid_formats,
904 std::remove_reference_t<ref_ids_type>>;
907 template <output_stream stream_type,
908 std::ranges::forward_range ref_ids_type,
909 std::ranges::forward_range ref_lengths_type,
911 detail::fields_specialisation selected_field_ids>
916 selected_field_ids
const &)
918 type_list<file_format>,
919 std::remove_reference_t<ref_ids_type>>;
922 template <output_stream stream_type,
923 std::ranges::forward_range ref_ids_type,
924 std::ranges::forward_range ref_lengths_type,
926 detail::fields_specialisation selected_field_ids>
931 selected_field_ids
const &)
933 type_list<file_format>,
934 std::remove_reference_t<ref_ids_type>>;
937 template <output_stream stream_type,
938 std::ranges::forward_range ref_ids_type,
939 std::ranges::forward_range ref_lengths_type,
946 type_list<file_format>,
947 std::remove_reference_t<ref_ids_type>>;
950 template <output_stream stream_type,
951 std::ranges::forward_range ref_ids_type,
952 std::ranges::forward_range ref_lengths_type,
959 type_list<file_format>,
960 std::remove_reference_t<ref_ids_type>>;
alignment_file_output(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: output.hpp:301
alignment_file_output()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
void value_type
The value type (void).
Definition: output.hpp:243
~alignment_file_output()=default
Destructor is defaulted.
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: output.hpp:194
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:31
Provides exceptions used in the I/O module.
Specifies a range whose iterators may outlive the range and remain valid.
Sequence (REF_SEQ) relative start position (0-based), unsigned value.
detail::out_file_iterator< alignment_file_output > iterator
The iterator type of this view (an output iterator).
Definition: output.hpp:253
char stream_char_type
Character type of the stream(s).
Definition: output.hpp:198
The mate pair information given as a std::tuple of reference name, offset and template length...
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: output.hpp:196
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:225
Provides various utility functions required only for output.
void reference
The reference type (void).
Definition: output.hpp:245
The identifier, usually a string.
Provides traits for seqan3::type_list.
alignment_file_output(stream_type &&stream, ref_ids_type_ &&ref_ids, ref_lengths_type &&ref_lengths, 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:435
alignment_file_output(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:336
alignment_file_output & operator=(rng_t &&range)
Write a range of records (or tuples) to the file.
Definition: output.hpp:637
The main SeqAn3 namespace.
The "sequence", usually a range of nucleotides or amino acids.
The alignment flag (bit information), uint16_t value.
The optional tags in the SAM format, stored in a dictionary.
Provides seqan3::alignment_file_output_options.
The qualities, usually in phred-score notation.
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem...
Definition: exception.hpp:39
A class template that holds a choice of seqan3::field.
Definition: record.hpp:165
A class for writing alignment files, e.g. SAM, BAL, BLAST, ...
Definition: output.hpp:186
Whether a type behaves like a tuple.
void const_reference
The const reference type (void).
Definition: output.hpp:247
Provides seqan3::tuple_like.
Provides the seqan3::record template and the seqan3::field enum.
Adaptations of concepts from the Ranges TS.
None of the flags below are set.
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition: output.hpp:610
constexpr bool contains
Whether a type occurs in a pack or not.
Definition: traits.hpp:193
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: output.hpp:486
std::ranges::default_sentinel_t sentinel
The type returned by end().
Definition: output.hpp:257
auto & header()
Access the file's header.
Definition: output.hpp:719
alignment_file_output_options options
The options are public and its members can be set directly.
Definition: output.hpp:698
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:116
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format...
The options type defines various option members that influence the behavior of all or some formats...
Definition: output_options.hpp:22
void push_back(tuple_t &&t)
Write a record in form of a std::tuple to the file.
Definition: output.hpp:559
Sequence (SEQ) relative start position (0-based), unsigned value.
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
Provides helper data structures for the seqan3::alignment_file_output.
The e-value (length normalized bit score), double value.
void const_iterator
The const iterator type is void, because files are not const-iterable.
Definition: output.hpp:255
The (pairwise) alignment stored in an seqan3::alignment object.
Provides the seqan3::detail::out_file_iterator class template.
The bit score (statistical significance indicator), unsigned value.
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition: output.hpp:510
friend alignment_file_output operator|(rng_t &&range, alignment_file_output &&f)
Definition: output.hpp:687
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
Type tag which indicates that no reference information has been passed to the alignment file on const...
Definition: misc.hpp:22
alignment_file_output(std::filesystem::path const &filename, ref_ids_type_ &&ref_ids, ref_lengths_type &&ref_lengths, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: output.hpp:397
field
An enumerator for the fields used in file formats.Some of the fields are shared between formats...
Definition: record.hpp:64
typename reference< t >::type reference_t
Shortcut for seqan3::reference (transformation_trait shortcut).
Definition: pre.hpp:77
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type...
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition: output.hpp:467
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
The identifier of the (reference) sequence that SEQ was aligned to.
alignment_file_output(stream_type &&stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
Definition: output.hpp:352
A pointer to the seqan3::alignment_file_header object storing header information. ...
alignment_file_output & operator=(alignment_file_output const &)=delete
Copy assignment is explicitly deleted, because you can't have multiple access to the same file...
friend alignment_file_output & operator|(rng_t &&range, alignment_file_output &f)
Write a range of records (or tuples) to the file.
Definition: output.hpp:676
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:324
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...
void size_type
The size type (void).
Definition: output.hpp:249