33 #include <seqan3/io/detail/record.hpp> 169 template <detail::Fields selected_field_ids_ =
185 detail::TypeListOfAlignmentFileOutputFormats valid_formats_ = type_list<format_sam, format_bam>,
186 Char stream_char_type_ = char,
187 typename ref_ids_type = ref_info_not_given>
220 static_assert([] () constexpr
222 for (
field f : selected_field_ids::as_array)
223 if (!field_ids::contains(f))
227 "You selected a field that is not valid for alignment files, " 228 "please refer to the documentation of " 229 "seqan3::alignment_file_output::field_ids for the accepted values.");
247 using iterator = detail::out_file_iterator<alignment_file_output>;
297 primary_stream{
new std::ofstream{filename, std::ios_base::out | std::ios::binary}, stream_deleter_default}
300 if (!primary_stream->good())
301 throw file_open_error{
"Could not open file " + filename.
string() +
" for writing."};
304 secondary_stream = detail::make_secondary_ostream(*primary_stream, filename);
307 detail::set_format(format, filename);
326 template <OStream2 stream_type, AlignmentFileOutputFormat file_format>
328 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
330 primary_stream{&stream, stream_deleter_noop},
331 secondary_stream{&stream, stream_deleter_noop},
332 format{detail::alignment_file_output_format<file_format>{}}
334 static_assert(meta::in<valid_formats, file_format>::value,
335 "You selected a format that is not in the valid_formats of this file.");
339 template <OStream2 stream_type, AlignmentFileOutputFormat file_format>
341 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
343 primary_stream{
new stream_type{std::move(stream)}, stream_deleter_default},
344 secondary_stream{&*primary_stream, stream_deleter_noop},
345 format{detail::alignment_file_output_format<file_format>{}}
347 static_assert(meta::in<valid_formats, file_format>::value,
348 "You selected a format that is not in the valid_formats of this file.");
381 template <
typename ref_
ids_type_, std::ranges::ForwardRange ref_lengths_type>
386 ref_ids_type_ && ref_ids,
387 ref_lengths_type && ref_lengths,
394 header_ptr = std::make_unique<alignment_file_header<ref_ids_type>>(std::forward<ref_ids_type_>(ref_ids));
399 header_ptr->ref_id_info.push_back({ref_lengths[idx],
""});
400 header_ptr->ref_dict[(header_ptr->ref_ids()[idx])] = idx;
425 template <OStream2 stream_type,
426 AlignmentFileOutputFormat file_format,
427 typename ref_ids_type_,
433 ref_ids_type_ && ref_ids,
434 ref_lengths_type && ref_lengths,
435 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
441 header_ptr = std::make_unique<alignment_file_header<ref_ids_type>>(std::forward<ref_ids_type_>(ref_ids));
446 header_ptr->ref_id_info.emplace_back(ref_lengths[idx],
"");
447 header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
515 template <
typename record_t>
519 requires { requires detail::is_type_specialisation_of_v<remove_cvref_t<record_t>,
record>; }
525 write_record(detail::get_or<field::HEADER_PTR>(r,
nullptr),
529 detail::get_or<field::OFFSET>(r, 0u),
531 detail::get_or<field::REF_ID>(r, std::ignore),
533 detail::get_or<field::ALIGNMENT>(r, default_align_t{}),
534 detail::get_or<field::FLAG>(r, 0u),
535 detail::get_or<field::MAPQ>(r, 0u),
536 detail::get_or<field::MATE>(r, default_mate_t{}),
537 detail::get_or<field::TAGS>(r, sam_tag_dictionary{}),
538 detail::get_or<field::EVALUE>(r, 0u),
539 detail::get_or<field::BIT_SCORE>(r, 0u));
563 template <
typename tuple_t>
573 write_record(detail::get_or<selected_field_ids::index_of(
field::HEADER_PTR)>(t,
nullptr),
577 detail::get_or<selected_field_ids::index_of(
field::OFFSET)>(t, 0u),
579 detail::get_or<selected_field_ids::index_of(
field::REF_ID)>(t, std::ignore),
581 detail::get_or<selected_field_ids::index_of(
field::ALIGNMENT)>(t, default_align_t{}),
582 detail::get_or<selected_field_ids::index_of(
field::FLAG)>(t, 0u),
583 detail::get_or<selected_field_ids::index_of(
field::MAPQ)>(t, 0u),
584 detail::get_or<selected_field_ids::index_of(
field::MATE)>(t, default_mate_t{}),
586 detail::get_or<selected_field_ids::index_of(
field::EVALUE)>(t, 0u),
613 template <
typename arg_t,
typename ... arg_types>
640 template <
typename rng_t>
646 for (
auto &&
record : range)
679 template <
typename rng_t>
690 template <
typename rng_t>
709 return *secondary_stream;
726 throw std::logic_error{
"Please construct your file with reference id and length information in order " 727 "to properly initialise the header before accessing it."};
747 stream_ptr_t primary_stream{
nullptr, stream_deleter_noop};
749 stream_ptr_t secondary_stream{
nullptr, stream_deleter_noop};
752 using format_type =
typename detail::variant_from_tags<valid_formats, detail::alignment_file_output_format>::type;
759 using header_type = alignment_file_header<std::conditional_t<std::Same<ref_ids_type, ref_info_not_given>,
767 template <
typename record_header_ptr_t,
typename ...pack_type>
768 void write_record(record_header_ptr_t && record_header_ptr, pack_type && ...remainder)
770 static_assert((
sizeof...(pack_type) == 14),
"Wrong parameter list passed to write_record.");
772 assert(!format.valueless_by_exception());
778 f.write(*secondary_stream,
options, *record_header_ptr, std::forward<pack_type>(remainder)...);
780 f.write(*secondary_stream,
options, std::ignore, std::forward<pack_type>(remainder)...);
782 f.write(*secondary_stream,
options, *header_ptr, std::forward<pack_type>(remainder)...);
798 template <detail::Fields selected_field_
ids>
800 -> alignment_file_output<selected_field_ids,
808 template <OStream2 stream_type,
809 AlignmentFileOutputFormat file_format,
810 detail::Fields selected_field_ids>
811 alignment_file_output(stream_type &&, file_format
const &, selected_field_ids
const &)
812 -> alignment_file_output<selected_field_ids,
813 type_list<file_format>,
820 template <OStream2 stream_type,
821 AlignmentFileOutputFormat file_format,
822 detail::Fields selected_field_ids>
823 alignment_file_output(stream_type &, file_format
const &, selected_field_ids
const &)
824 -> alignment_file_output<selected_field_ids,
825 type_list<file_format>,
832 template <OStream2 stream_type,
833 AlignmentFileOutputFormat file_format>
834 alignment_file_output(stream_type &&, file_format
const &)
836 type_list<file_format>,
843 template <OStream2 stream_type,
844 AlignmentFileOutputFormat file_format>
845 alignment_file_output(stream_type &, file_format
const &)
847 type_list<file_format>,
852 template <detail::Fields selected_field_ids,
858 selected_field_ids
const &)
859 -> alignment_file_output<selected_field_ids,
876 template <OStream2 stream_type,
879 AlignmentFileOutputFormat file_format,
880 detail::Fields selected_field_ids>
881 alignment_file_output(stream_type &&,
885 selected_field_ids
const &)
886 -> alignment_file_output<selected_field_ids,
887 type_list<file_format>,
892 template <OStream2 stream_type,
895 AlignmentFileOutputFormat file_format,
896 detail::Fields selected_field_ids>
897 alignment_file_output(stream_type &,
901 selected_field_ids
const &)
902 -> alignment_file_output<selected_field_ids,
903 type_list<file_format>,
908 template <OStream2 stream_type,
911 AlignmentFileOutputFormat file_format>
912 alignment_file_output(stream_type &&,
917 type_list<file_format>,
922 template <OStream2 stream_type,
925 AlignmentFileOutputFormat file_format>
926 alignment_file_output(stream_type &,
931 type_list<file_format>,
detail::out_file_iterator< alignment_file_output > iterator
The iterator type of this view (an output iterator).
Definition: output.hpp:247
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
The "sequence", usually a range of nucleotides or amino acids.
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition: output.hpp:614
~alignment_file_output()=default
Destructor is defaulted.
Provides exceptions used in the I/O module.
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...
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: output.hpp:198
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:327
The (pairwise) alignment stored in an seqan3::alignment object.
The alignment flag (bit information), uint16_t value.
auto & header()
Access the file's header.
Definition: output.hpp:723
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:187
Provides various utility functions required only for output.
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:385
Provides seqan3::type_list and auxiliary type traits.
void const_reference
The const reference type (void).
Definition: output.hpp:241
alignment_file_output(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: output.hpp:295
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: output.hpp:492
alignment_file_output(stream_type &&stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
Definition: output.hpp:340
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
The qualities, usually in phred-score notation.
The e-value (length normalized bit score), double value.
Provides seqan3::alignment_file_output_options.
Sequence (REF_SEQ) relative start position (0-based), unsigned value.
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: output.hpp:196
A class template that holds a choice of seqan3::field.
Definition: record.hpp:127
A class for writing alignment files, e.g. SAM, BAL, BLAST, ...
Definition: output.hpp:188
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition: output.hpp:473
Provides seqan3::TupleLike.
std::ranges::default_sentinel_t sentinel
The type returned by end().
Definition: output.hpp:251
alignment_file_output & operator=(rng_t &&range)
Write a range of records (or tuples) to the file.
Definition: output.hpp:641
Provides the seqan3::record template and the seqan3::field enum.
Sequence (SEQ) relative start position (0-based), unsigned value.
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition: output.hpp:516
The identifier, usually a string.
void size_type
The size type (void).
Definition: output.hpp:243
Adaptations of concepts from the Ranges TS.
The mate pair information given as a std::tuple of reference name, offset and template length...
The identifier of the (reference) sequence that SEQ was aligned to.
The options type defines various option members that influence the behavior of all or some formats...
Definition: output_options.hpp:22
A pointer to the seqan3::alignment_file_header object storing header information. ...
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:432
void push_back(tuple_t &&t)
Write a record in form of a std::tuple to the file.
Definition: output.hpp:564
Provides helper data structures for the seqan3::alignment_file_output.
alignment_file_output_options options
The options are public and its members can be set directly.
Definition: output.hpp:702
Provides various type traits on generic types.
Provides the seqan3::detail::out_file_iterator class template.
void reference
The reference type (void).
Definition: output.hpp:239
friend alignment_file_output operator|(rng_t &&range, alignment_file_output &&f)
Definition: output.hpp:691
void const_iterator
The const iterator type is void, because files are not const-iterable.
Definition: output.hpp:249
::ranges::default_sentinel_t default_sentinel_t
Alias for ranges::default_sentinel_t. Type of ranges::default_sentinel.
Definition: iterator:351
field
An enumerator for the fields used in file formats.Some of the fields are shared between formats...
Definition: record.hpp:63
The optional tags in the SAM format, stored in a dictionary.
alignment_file_output()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
Specifies requirements of a Range type for which begin returns a type that models std::ForwardIterato...
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
Exposes the value_type of another type.
Definition: pre.hpp:41
The bit score (statistical significance indicator), unsigned value.
stream_char_type_ stream_char_type
Character type of the stream(s), usually char.
Definition: output.hpp:200
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
Whether a type behaves like a tuple.
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:680
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...