60template <detail::fields_specialisation selected_field_ids_ = fields<
field::seq,
72 detail::type_list_of_sam_file_output_formats valid_formats_ = type_list<format_sam, format_bam>,
73 typename ref_ids_type = ref_info_not_given>
105 for (
field f : selected_field_ids::as_array)
110 "You selected a field that is not valid for SAM files, "
111 "please refer to the documentation of "
112 "seqan3::sam_file_output::field_ids for the accepted values.");
184 ->open(filename, std::ios_base::out | std::ios::binary);
188 throw file_open_error{
"Could not open file " + filename.
string() +
" for writing."};
213 template <output_stream stream_type, sam_file_output_format file_format>
214 requires std::same_as<typename std::remove_reference_t<stream_type>::char_type,
stream_char_type>
216 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
220 format{detail::sam_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.");
227 template <output_stream stream_type, sam_file_output_format file_format>
228 requires std::same_as<typename std::remove_reference_t<stream_type>::char_type,
stream_char_type>
230 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
234 format{detail::sam_file_output_format_exposer<file_format>{}}
236 static_assert(list_traits::contains<file_format, valid_formats>,
237 "You selected a format that is not in the valid_formats of this file.");
270 template <
typename ref_
ids_type_, std::ranges::forward_range ref_lengths_type>
271 requires std::same_as<std::remove_reference_t<ref_ids_type_>, ref_ids_type>
273 ref_ids_type_ && ref_ids,
274 ref_lengths_type && ref_lengths,
303 template <output_stream stream_type,
304 sam_file_output_format file_format,
305 typename ref_ids_type_,
306 std::ranges::forward_range ref_lengths_type>
307 requires std::same_as<std::remove_reference_t<ref_ids_type_>, ref_ids_type>
309 ref_ids_type_ && ref_ids,
310 ref_lengths_type && ref_lengths,
311 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
382 template <
typename record_t>
384 requires detail::record_like<record_t>
389 write_record(detail::get_or<field::header_ptr>(r,
nullptr),
393 detail::get_or<field::offset>(r, 0u),
395 detail::get_or<field::ref_id>(r, std::ignore),
399 detail::get_or<field::mapq>(r, 0u),
400 detail::get_or<field::mate>(r, default_mate_t{}),
402 detail::get_or<field::evalue>(r, 0u),
403 detail::get_or<field::bit_score>(r, 0u));
427 template <
typename tuple_t>
475 template <
typename arg_t,
typename... arg_types>
503 template <
typename rng_t>
507 for (
auto &&
record : range)
540 template <
typename rng_t>
549 template <
typename rng_t>
582 if constexpr (std::same_as<ref_ids_type, ref_info_not_given>)
583 throw std::logic_error{
"Please construct your file with reference id and length information in order "
584 "to properly initialise the header before accessing it."};
629 template <
typename ref_
ids_type_,
typename ref_lengths_type>
634 header_ptr = std::make_unique<sam_file_header<ref_ids_type>>(std::forward<ref_ids_type_>(ref_ids));
636 for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
638 header_ptr->ref_id_info.emplace_back(ref_lengths[idx],
"");
640 if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<ref_ids_type_>>
641 && std::ranges::sized_range<std::ranges::range_reference_t<ref_ids_type_>>
642 && std::ranges::borrowed_range<std::ranges::range_reference_t<ref_ids_type_>>)
655 template <
typename record_header_ptr_t,
typename... pack_type>
656 void write_record(record_header_ptr_t && record_header_ptr, pack_type &&... remainder)
658 static_assert((
sizeof...(pack_type) == 14),
"Wrong parameter list passed to write_record.");
660 assert(!
format.valueless_by_exception());
666 if constexpr (!std::same_as<record_header_ptr_t, std::nullptr_t>)
671 std::forward<pack_type>(remainder)...);
673 else if constexpr (std::same_as<ref_ids_type, ref_info_not_given>)
678 std::forward<pack_type>(remainder)...);
685 std::forward<pack_type>(remainder)...);
703template <detail::fields_specialisation selected_field_
ids>
710template <output_stream stream_type,
719template <output_stream stream_type,
728template <output_stream stream_type, sam_file_output_format file_format>
735template <output_stream stream_type, sam_file_output_format file_format>
741 std::ranges::forward_range ref_ids_type,
742 std::ranges::forward_range ref_lengths_type>
749template <std::ranges::forward_range ref_
ids_type, std::ranges::forward_range ref_lengths_type>
756template <output_stream stream_type,
757 std::ranges::forward_range ref_ids_type,
758 std::ranges::forward_range ref_lengths_type,
765template <output_stream stream_type,
766 std::ranges::forward_range ref_ids_type,
767 std::ranges::forward_range ref_lengths_type,
774template <output_stream stream_type,
775 std::ranges::forward_range ref_ids_type,
776 std::ranges::forward_range ref_lengths_type,
778sam_file_output(stream_type &&, ref_ids_type &&, ref_lengths_type &&, file_format
const &)
784template <output_stream stream_type,
785 std::ranges::forward_range ref_ids_type,
786 std::ranges::forward_range ref_lengths_type,
788sam_file_output(stream_type &, ref_ids_type &&, ref_lengths_type &&, file_format
const &)
Output iterator necessary for providing a range-like interface in output file.
Definition: out_file_iterator.hpp:47
A class for writing SAM files, both SAM and its binary representation BAM are supported.
Definition: io/sam_file/output.hpp:75
sam_file_output(stream_type &, ref_ids_type &&, ref_lengths_type &&, file_format const &) -> sam_file_output< typename sam_file_output<>::selected_field_ids, type_list< file_format >, std::remove_reference_t< ref_ids_type > >
Deduces the valid format, and the ref_ids_type from input. selected_field_ids set to the default.
void const_reference
The const reference type (void).
Definition: io/sam_file/output.hpp:124
void initialise_header_information(ref_ids_type_ &&ref_ids, ref_lengths_type &&ref_lengths)
Fill the header reference dictionary, with the given info.
Definition: io/sam_file/output.hpp:630
friend sam_file_output operator|(rng_t &&range, sam_file_output &&f)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: io/sam_file/output.hpp:550
sam_file_output(stream_type &, ref_ids_type &&, ref_lengths_type &&, file_format const &, selected_field_ids const &) -> sam_file_output< selected_field_ids, type_list< file_format >, std::remove_reference_t< ref_ids_type > >
Deduces selected_field_ids, the valid format, and the ref_ids_type from input.
sam_file_output(std::filesystem::path const &, ref_ids_type &&, ref_lengths_type &&) -> sam_file_output< typename sam_file_output<>::selected_field_ids, typename sam_file_output<>::valid_formats, std::remove_reference_t< ref_ids_type > >
Deduces ref_ids_type from input. Valid formats, and selected_field_ids are set to the default.
void size_type
The size type (void).
Definition: io/sam_file/output.hpp:126
std::vector< char > stream_buffer
A larger (compared to stl default) stream buffer to use when reading from a file.
Definition: io/sam_file/output.hpp:592
sam_file_output & operator=(rng_t &&range)
Write a range of records (or tuples) to the file.
Definition: io/sam_file/output.hpp:504
friend iterator
Befriend iterator so it can access the buffers.
Definition: io/sam_file/output.hpp:692
sam_file_output(sam_file_output const &)=delete
Copy construction is explicitly deleted, because you can't have multiple access to the same file.
sam_file_output()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
static void stream_deleter_noop(std::basic_ostream< stream_char_type > *)
Stream deleter that does nothing (no ownership assumed).
Definition: io/sam_file/output.hpp:601
friend sam_file_output & operator|(rng_t &&range, sam_file_output &f)
Write a range of records (or tuples) to the file.
Definition: io/sam_file/output.hpp:541
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition: io/sam_file/output.hpp:477
format_type format
The actual std::variant holding a pointer to the detected/selected format.
Definition: io/sam_file/output.hpp:618
std::default_sentinel_t sentinel
The type returned by end().
Definition: io/sam_file/output.hpp:134
char stream_char_type
Character type of the stream(s).
Definition: io/sam_file/output.hpp:86
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition: io/sam_file/output.hpp:340
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: io/sam_file/output.hpp:359
sam_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: io/sam_file/output.hpp:272
sam_file_output(std::filesystem::path, selected_field_ids const &) -> sam_file_output< selected_field_ids, typename sam_file_output<>::valid_formats, ref_info_not_given >
Deduces selected_field_ids from input and sets sam_file_output::ref_ids_type to seqan3::detail::ref_i...
sam_file_output(stream_type &&, ref_ids_type &&, ref_lengths_type &&, file_format const &) -> sam_file_output< typename sam_file_output<>::selected_field_ids, type_list< file_format >, std::remove_reference_t< ref_ids_type > >
Deduces the valid format, and the ref_ids_type from input. selected_field_ids set to the default.
sam_file_output & operator=(sam_file_output &&)=default
Move assignment is defaulted.
std::unique_ptr< header_type > header_ptr
The file header object (will be set on construction).
Definition: io/sam_file/output.hpp:626
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: io/sam_file/output.hpp:82
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: io/sam_file/output.hpp:84
std::basic_ostream< stream_char_type > & get_stream()
Expose a reference to the secondary stream. [public, but not documented as part of the API].
Definition: io/sam_file/output.hpp:564
sam_file_output & operator=(sam_file_output const &)=delete
Copy assignment is explicitly deleted, because you can't have multiple access to the same file.
sam_file_output(stream_type &&, ref_ids_type &&, ref_lengths_type &&, file_format const &, selected_field_ids const &) -> sam_file_output< selected_field_ids, type_list< file_format >, std::remove_reference_t< ref_ids_type > >
Deduces selected_field_ids, the valid format, and the ref_ids_type from input.
void reference
The reference type (void).
Definition: io/sam_file/output.hpp:122
void write_record(record_header_ptr_t &&record_header_ptr, pack_type &&... remainder)
Write record to format.
Definition: io/sam_file/output.hpp:656
sam_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: io/sam_file/output.hpp:215
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition: io/sam_file/output.hpp:383
sam_file_output(stream_type &&, file_format const &) -> sam_file_output< typename sam_file_output<>::selected_field_ids, type_list< file_format >, ref_info_not_given >
Deduces the valid format from input and sets sam_file_output::ref_ids_type to seqan3::detail::ref_inf...
sam_file_output(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: io/sam_file/output.hpp:178
static void stream_deleter_default(std::basic_ostream< stream_char_type > *ptr)
Stream deleter with default behaviour (ownership assumed).
Definition: io/sam_file/output.hpp:604
stream_ptr_t secondary_stream
The secondary stream is a compression layer on the primary or just points to the primary (no compress...
Definition: io/sam_file/output.hpp:612
sam_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: io/sam_file/output.hpp:308
void value_type
The value type (void).
Definition: io/sam_file/output.hpp:120
~sam_file_output()=default
Destructor is defaulted.
sam_file_output_options options
The options are public and its members can be set directly.
Definition: io/sam_file/output.hpp:559
sam_file_output(sam_file_output &&)=default
Move construction is defaulted.
sam_file_output(stream_type &&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: io/sam_file/output.hpp:229
sam_file_output(stream_type &, file_format const &, selected_field_ids const &) -> sam_file_output< selected_field_ids, type_list< file_format >, ref_info_not_given >
Deduces selected_field_ids, and the valid format from input and sets sam_file_output::ref_ids_type to...
sam_file_output(stream_type &&, file_format const &, selected_field_ids const &) -> sam_file_output< selected_field_ids, type_list< file_format >, ref_info_not_given >
Deduces selected_field_ids, and the valid format from input and sets sam_file_output::ref_ids_type to...
void push_back(tuple_t &&t)
Write a record in form of a std::tuple to the file.
Definition: io/sam_file/output.hpp:428
stream_ptr_t primary_stream
The primary stream is the user provided stream or the file stream if constructed from filename.
Definition: io/sam_file/output.hpp:610
auto & header()
Access the file's header.
Definition: io/sam_file/output.hpp:580
sam_file_output(std::filesystem::path const &, ref_ids_type &&, ref_lengths_type &&, selected_field_ids const &) -> sam_file_output< selected_field_ids, typename sam_file_output<>::valid_formats, std::remove_reference_t< ref_ids_type > >
Deduces selected_field_ids and ref_ids_type from input. valid_formats is set to the default.
typename detail::variant_from_tags< valid_formats, detail::sam_file_output_format_exposer >::type format_type
Type of the format, a std::variant over the valid_formats.
Definition: io/sam_file/output.hpp:615
void const_iterator
The const iterator type is void, because files are not const-iterable.
Definition: io/sam_file/output.hpp:132
sam_file_output(stream_type &, file_format const &) -> sam_file_output< typename sam_file_output<>::selected_field_ids, type_list< file_format >, ref_info_not_given >
Deduces the valid format from input and sets sam_file_output::ref_ids_type to seqan3::detail::ref_inf...
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:343
Auxiliary concept that checks whether a type is a specialisation of seqan3::fields.
Definition: detail/record.hpp:35
Provides auxiliary data structures and functions for seqan3::record and seqan3::fields.
@ none
None of the flags below are set.
field
An enumerator for the fields used in file formats.
Definition: record.hpp:63
void set_format(format_variant_type &format, std::filesystem::path const &file_name)
Sets the file format according to the file name extension.
Definition: io/detail/misc.hpp:68
auto make_secondary_ostream(std::basic_ostream< char_t > &primary_stream, std::filesystem::path &filename) -> std::unique_ptr< std::basic_ostream< char_t >, std::function< void(std::basic_ostream< char_t > *)> >
Depending on the given filename/extension, create a compression stream or just forward the primary st...
Definition: misc_output.hpp:43
decltype(auto) get_or(record< field_types, field_ids > &r, or_type &&or_value)
Access an element in a std::tuple or seqan3::record; return or_value if not contained.
Definition: detail/record.hpp:158
@ flag
The alignment flag (bit information), uint16_t value.
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
@ ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
@ bit_score
The bit score (statistical significance indicator), unsigned value.
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
@ mate
The mate pair information given as a std::tuple of reference name, offset and template length.
@ header_ptr
A pointer to the seqan3::sam_file_header object storing header information.
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
@ evalue
The e-value (length normalized bit score), double value.
@ id
The identifier, usually a string.
@ tags
The optional tags in the SAM format, stored in a dictionary.
@ seq
The "sequence", usually a range of nucleotides or amino acids.
@ qual
The qualities, usually in Phred score notation.
constexpr size_t size
The size of a type pack.
Definition: type_pack/traits.hpp:146
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: aligned_sequence_concept.hpp:29
Provides the seqan3::detail::out_file_iterator class template.
Provides the seqan3::record template and the seqan3::field enum.
Provides seqan3::detail::record_like.
Provides seqan3::sam_file_output_options.
Provides helper data structures for the seqan3::sam_file_output.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:128
static constexpr bool contains(field f)
Whether a field is contained in the parameter pack.
Definition: record.hpp:149
The class template that file records are based on; behaves like a std::tuple.
Definition: record.hpp:192
Type tag which indicates that no reference information has been passed to the alignment file on const...
Definition: sam_flag.hpp:24
The options type defines various option members that influence the behavior of all or some formats.
Definition: sam_file/output_options.hpp:26
Type that contains multiple types.
Definition: type_list.hpp:29
Provides traits for seqan3::type_list.
Provides seqan3::tuple_like.