129 template <
typename stream_type,
130 typename seq_legal_alph_type,
131 typename stream_pos_type,
137 stream_pos_type & position_buffer,
140 qual_type & qualities);
142 template <
typename stream_type,
150 qual_type && qualities);
152 template <
typename stream_type,
153 typename seq_legal_alph_type,
154 typename ref_seqs_type,
155 typename ref_ids_type,
156 typename stream_pos_type,
159 typename ref_seq_type,
160 typename ref_id_type,
161 typename ref_offset_type,
167 typename tag_dict_type,
168 typename e_value_type,
169 typename bit_score_type>
172 ref_seqs_type & ref_seqs,
174 stream_pos_type & position_buffer,
178 ref_seq_type & SEQAN3_DOXYGEN_ONLY(ref_seq),
179 ref_id_type & ref_id,
180 ref_offset_type & ref_offset,
181 cigar_type & cigar_vector,
185 tag_dict_type & tag_dict,
186 e_value_type & SEQAN3_DOXYGEN_ONLY(e_value),
187 bit_score_type & SEQAN3_DOXYGEN_ONLY(bit_score));
189 template <
typename stream_type,
190 typename header_type,
193 typename ref_seq_type,
194 typename ref_id_type,
197 typename tag_dict_type,
198 typename e_value_type,
199 typename bit_score_type>
202 header_type && header,
206 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
207 ref_id_type && ref_id,
213 tag_dict_type && tag_dict,
214 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
215 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score));
237 template <
typename t>
240 return std::forward<t>(v);
243 template <
typename stream_view_type, arithmetic value_type>
247 template <
typename stream_view_type>
250 template <
typename stream_view_type>
253 template <
typename stream_it_t, std::ranges::forward_range field_type>
256 template <
typename stream_it_t>
259 template <
typename stream_it_t>
264template <
typename stream_type,
265 typename seq_legal_alph_type,
266 typename stream_pos_type,
272 stream_pos_type & position_buffer,
275 qual_type & qualities)
300 if constexpr (!detail::decays_to_ignore_v<seq_type>)
301 if (std::ranges::distance(
sequence) == 0)
302 throw parse_error{
"The sequence information must not be empty."};
303 if constexpr (!detail::decays_to_ignore_v<id_type>)
304 if (std::ranges::distance(
id) == 0)
305 throw parse_error{
"The id information must not be empty."};
312template <
typename stream_type,
320 qual_type && qualities)
345template <
typename stream_type,
346 typename seq_legal_alph_type,
347 typename ref_seqs_type,
348 typename ref_ids_type,
349 typename stream_pos_type,
352 typename ref_seq_type,
353 typename ref_id_type,
354 typename ref_offset_type,
360 typename tag_dict_type,
361 typename e_value_type,
362 typename bit_score_type>
366 ref_seqs_type & ref_seqs,
368 stream_pos_type & position_buffer,
372 ref_seq_type & SEQAN3_DOXYGEN_ONLY(ref_seq),
373 ref_id_type & ref_id,
374 ref_offset_type & ref_offset,
375 cigar_type & cigar_vector,
379 tag_dict_type & tag_dict,
380 e_value_type & SEQAN3_DOXYGEN_ONLY(e_value),
381 bit_score_type & SEQAN3_DOXYGEN_ONLY(bit_score))
383 static_assert(detail::decays_to_ignore_v<ref_offset_type>
384 || detail::is_type_specialisation_of_v<ref_offset_type, std::optional>,
385 "The ref_offset must be a specialisation of std::optional.");
390 int32_t ref_offset_tmp{};
391 std::ranges::range_value_t<
decltype(header.
ref_ids())> ref_id_tmp{};
404 position_buffer = stream.tellg();
408 if constexpr (!detail::decays_to_ignore_v<id_type>)
413 uint16_t flag_integral{};
423 if (ref_offset_tmp == -1)
425 else if (ref_offset_tmp > -1)
427 else if (ref_offset_tmp < -1)
428 throw format_error{
"No negative values are allowed for field::ref_offset."};
430 if constexpr (!detail::decays_to_ignore_v<mapq_type>)
437 if constexpr (!detail::decays_to_ignore_v<cigar_type>)
441 int32_t ref_length{}, seq_length{};
456 if constexpr (!detail::decays_to_ignore_v<mate_type>)
458 std::ranges::range_value_t<
decltype(header.
ref_ids())> tmp_mate_ref_id{};
461 if (tmp_mate_ref_id ==
"=")
463 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
477 get<1>(
mate) = --tmp_pnext;
478 else if (tmp_pnext < 0)
479 throw format_error{
"No negative values are allowed at the mate mapping position."};
486 for (
size_t i = 0; i < 3u; ++i)
496 constexpr auto is_legal_alph = char_is_valid_for<seq_legal_alph_type>;
500 [is_legal_alph](
char const c)
502 if (!is_legal_alph(c))
504 + detail::type_name_as_string<seq_legal_alph_type>
509 if constexpr (detail::decays_to_ignore_v<seq_type>)
525 auto const tab_or_end = is_char<'\t'> || is_char<'\r'> || is_char<'\n'>;
527 if constexpr (!detail::decays_to_ignore_v<qual_type>)
532 if constexpr (!detail::decays_to_ignore_v<seq_type> && !detail::decays_to_ignore_v<qual_type>)
534 if (std::ranges::distance(
seq) != 0 && std::ranges::distance(
qual) != 0
535 && std::ranges::distance(
seq) != std::ranges::distance(
qual))
538 std::ranges::distance(
seq),
539 ") and quality length (",
540 std::ranges::distance(
qual),
541 ") must be the same.")};
551 if constexpr (!detail::decays_to_ignore_v<tag_dict_type>)
561template <
typename stream_type,
562 typename header_type,
565 typename ref_seq_type,
566 typename ref_id_type,
569 typename tag_dict_type,
570 typename e_value_type,
571 typename bit_score_type>
574 header_type && header,
578 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
579 ref_id_type && ref_id,
585 tag_dict_type && tag_dict,
586 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
587 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score))
606 "The seq object must be a std::ranges::forward_range over "
607 "letters that model seqan3::alphabet.");
610 "The id object must be a std::ranges::forward_range over "
611 "letters that model seqan3::alphabet.");
613 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
615 static_assert((std::ranges::forward_range<ref_id_type> || std::integral<std::remove_reference_t<ref_id_type>>
616 || detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>),
617 "The ref_id object must be a std::ranges::forward_range "
618 "over letters that model seqan3::alphabet.");
620 if constexpr (std::integral<std::remove_cvref_t<ref_id_type>>
621 || detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>)
622 static_assert(!detail::decays_to_ignore_v<header_type>,
623 "If you give indices as reference id information the header must also be present.");
627 "The qual object must be a std::ranges::forward_range "
628 "over letters that model seqan3::alphabet.");
631 "The mate object must be a std::tuple of size 3 with "
632 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
633 "2) a std::integral or std::optional<std::integral>, and "
634 "3) a std::integral.");
637 ((std::ranges::forward_range<decltype(std::get<0>(
mate))>
639 || detail::is_type_specialisation_of_v<
641 std::optional>)&&(std::integral<std::remove_cvref_t<decltype(std::get<1>(
mate))>>
642 || detail::is_type_specialisation_of_v<
644 std::optional>)&&std::integral<std::remove_cvref_t<decltype(std::get<2>(
mate))>>),
645 "The mate object must be a std::tuple of size 3 with "
646 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
647 "2) a std::integral or std::optional<std::integral>, and "
648 "3) a std::integral.");
650 if constexpr (std::integral<std::remove_cvref_t<decltype(std::get<0>(
mate))>>
653 static_assert(!detail::decays_to_ignore_v<header_type>,
654 "If you give indices as mate reference id information the header must also be present.");
657 "The tag_dict object must be of type seqan3::sam_tag_dictionary.");
662 if constexpr (!detail::decays_to_ignore_v<header_type> && !detail::decays_to_ignore_v<ref_id_type>
663 && !std::integral<std::remove_reference_t<ref_id_type>>
664 && !detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
671 if constexpr (std::ranges::contiguous_range<
decltype(
ref_id)> && std::ranges::sized_range<
decltype(
ref_id)>
672 && std::ranges::borrowed_range<
decltype(
ref_id)>)
681 "The ref_id type is not convertible to the reference id information stored in the "
682 "reference dictionary of the header object.");
690 "' was not in the list of references:",
696 throw format_error{
"The ref_offset object must be a std::integral >= 0."};
701 if constexpr (!detail::decays_to_ignore_v<header_type>)
715 constexpr char separator{
'\t'};
718 *stream_it = separator;
720 stream_it.write_number(
static_cast<uint16_t
>(
flag));
721 *stream_it = separator;
723 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
725 if constexpr (std::integral<std::remove_reference_t<ref_id_type>>)
729 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
746 *stream_it = separator;
749 stream_it.write_number(
ref_offset.value_or(-1) + 1);
750 *stream_it = separator;
752 stream_it.write_number(
static_cast<unsigned>(
mapq));
753 *stream_it = separator;
755 if (!std::ranges::empty(cigar_vector))
757 for (
auto & c : cigar_vector)
758 stream_it.write_range(c.to_string());
765 *stream_it = separator;
767 if constexpr (std::integral<std::remove_reference_t<decltype(get<0>(
mate))>>)
771 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<decltype(get<0>(
mate))>,
774 if (get<0>(
mate).has_value())
784 *stream_it = separator;
786 if constexpr (detail::is_type_specialisation_of_v<std::remove_cvref_t<decltype(get<1>(
mate))>,
std::optional>)
789 stream_it.write_number(get<1>(
mate).value_or(-1) + 1);
790 *stream_it = separator;
794 stream_it.write_number(get<1>(
mate));
795 *stream_it = separator;
798 stream_it.write_number(get<2>(
mate));
799 *stream_it = separator;
802 *stream_it = separator;
828template <
typename stream_view_type, arithmetic value_type>
830 stream_view_type && stream_view,
842 variant = std::move(tmp_vector);
858template <
typename stream_view_type>
872 throw format_error{
"Hexadecimal tag has an uneven number of digits!"};
878 variant = std::move(tmp_vector);
898template <
typename stream_view_type>
939 target[tag] = stream_view | ranges::to<std::string>();
953 switch (array_value_type_id)
978 +
"id of a SAM tag must be one of [cCsSiIf] but '" + array_value_type_id
985 "SAM tag must be one of [A,i,Z,H,B,f] but '")
986 + type_id +
"' was given."};
997template <
typename stream_it_t, std::ranges::forward_range field_type>
1000 if (std::ranges::empty(field_value))
1006 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<field_type>>,
char>)
1007 stream_it.write_range(field_value);
1019template <
typename stream_it_t>
1032template <
typename stream_it_t>
1036 auto const stream_variant_fn = [&stream_it](
auto && arg)
1040 if constexpr (std::ranges::input_range<T>)
1042 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
char>)
1044 stream_it.write_range(arg);
1046 else if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
std::byte>)
1048 if (!std::ranges::empty(arg))
1055 stream_it.write_number(std::to_integer<uint8_t>(elem));
1061 if (!std::ranges::empty(arg))
1068 stream_it.write_number(elem);
1073 else if constexpr (std::same_as<std::remove_cvref_t<T>,
char>)
1079 stream_it.write_number(arg);
1083 for (
auto & [tag, variant] : tag_dict)
1085 *stream_it = separator;
1087 char const char0 = tag / 256;
1088 char const char1 = tag % 256;
Core alphabet concept and free function/type trait wrappers.
Functionally the same as std::ostreambuf_iterator, but offers writing a range more efficiently.
Definition: fast_ostreambuf_iterator.hpp:40
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:343
Provides seqan3::detail::fast_ostreambuf_iterator.
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition: to_char.hpp:63
constexpr void consume(rng_t &&rng)
Iterate over a range (consumes single-pass input ranges).
Definition: core/range/detail/misc.hpp:28
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: sam_flag.hpp:76
constexpr std::tuple< std::vector< cigar >, int32_t, int32_t > parse_cigar(cigar_input_type &&cigar_input)
Parses a cigar string into a vector of operation-count pairs (e.g. (M, 3)).
Definition: io/sam_file/detail/cigar.hpp:94
constexpr char sam_tag_type_char_extra[12]
Each types SAM tag type extra char id. Index corresponds to the seqan3::detail::sam_tag_variant types...
Definition: sam_tag_dictionary.hpp:45
constexpr char sam_tag_type_char[12]
Each SAM tag type char identifier. Index corresponds to the seqan3::detail::sam_tag_variant types.
Definition: sam_tag_dictionary.hpp:42
@ none
None of the flags below are set.
constexpr auto take_until
A view adaptor that returns elements from the underlying range until the functor evaluates to true (o...
Definition: take_until_view.hpp:560
constexpr auto take_exactly_or_throw
A view adaptor that returns the first size elements from the underlying range and also exposes size i...
Definition: take_exactly_view.hpp:590
constexpr auto take_until_or_throw_and_consume
A view adaptor that returns elements from the underlying range until the functor evaluates to true (t...
Definition: take_until_view.hpp:602
constexpr auto take_until_and_consume
A view adaptor that returns elements from the underlying range until the functor evaluates to true (o...
Definition: take_until_view.hpp:588
constexpr auto take_until_or_throw
A view adaptor that returns elements from the underlying range until the functor evaluates to true (t...
Definition: take_until_view.hpp:574
constexpr auto istreambuf
A view factory that returns a view over the stream buffer of an input stream.
Definition: istreambuf_view.hpp:107
@ flag
The alignment flag (bit information), uint16_t value.
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
@ mate
The mate pair information given as a std::tuple of reference name, offset and template length.
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
@ seq
The "sequence", usually a range of nucleotides or amino acids.
@ qual
The qualities, usually in Phred score notation.
std::string make_printable(char const c)
Returns a printable value for the given character c.
Definition: pretty_print.hpp:48
constexpr auto is_space
Checks whether c is a space character.
Definition: predicate.hpp:125
typename decltype(detail::split_after< i >(list_t{}))::second_type drop
Return a seqan3::type_list of the types in the input type list, except the first n.
Definition: type_list/traits.hpp:395
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: type_list/traits.hpp:470
constexpr size_t size
The size of a type pack.
Definition: type_pack/traits.hpp:146
The generic alphabet concept that covers most data types used in ranges.
Checks whether from can be implicityly converted to to.
The generic concept for a (biological) sequence.
Whether a type behaves like a tuple.
Auxiliary functions for the SAM IO.
Provides seqan3::detail::istreambuf.
std::string to_string(value_type &&... values)
Streams all parameters via the seqan3::debug_stream and returns a concatenated string.
Definition: to_string.hpp:29
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides seqan3::sam_file_output_options.
Provides helper data structures for the seqan3::sam_file_output.
Provides the seqan3::sam_tag_dictionary class and auxiliaries.
Provides seqan3::sequence_file_output_options.
Provides seqan3::views::slice.
Thrown if there is a parse error, such as reading an unexpected character from an input stream.
Definition: io/exception.hpp:48
The options type defines various option members that influence the behavior of all or some formats.
Definition: sam_file/output_options.hpp:26
bool add_carriage_return
The default plain text line-ending is "\n", but on Windows an additional carriage return is recommend...
Definition: sam_file/output_options.hpp:30
bool sam_require_header
Whether to require a header for SAM files.
Definition: sam_file/output_options.hpp:44
The options type defines various option members that influence the behaviour of all or some formats.
Definition: sequence_file/output_options.hpp:26
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Provides seqan3::ranges::to.
Provides seqan3::views::to_char.
Provides traits to inspect some information of a type, for example its name.
Provides seqan3::tuple_like.