134 template <
typename stream_type,
135 typename seq_legal_alph_type,
136 typename stream_pos_type,
142 stream_pos_type & position_buffer,
145 qual_type & qualities);
147 template <
typename stream_type,
155 qual_type && qualities);
157 template <
typename stream_type,
158 typename seq_legal_alph_type,
159 typename ref_seqs_type,
160 typename ref_ids_type,
161 typename stream_pos_type,
164 typename offset_type,
165 typename ref_seq_type,
166 typename ref_id_type,
167 typename ref_offset_type,
173 typename tag_dict_type,
174 typename e_value_type,
175 typename bit_score_type>
178 ref_seqs_type & ref_seqs,
180 stream_pos_type & position_buffer,
184 offset_type & offset,
185 ref_seq_type & SEQAN3_DOXYGEN_ONLY(ref_seq),
186 ref_id_type & ref_id,
187 ref_offset_type & ref_offset,
188 cigar_type & cigar_vector,
192 tag_dict_type & tag_dict,
193 e_value_type & SEQAN3_DOXYGEN_ONLY(e_value),
194 bit_score_type & SEQAN3_DOXYGEN_ONLY(bit_score));
196 template <
typename stream_type,
197 typename header_type,
200 typename ref_seq_type,
201 typename ref_id_type,
204 typename tag_dict_type,
205 typename e_value_type,
206 typename bit_score_type>
209 header_type && header,
213 int32_t
const offset,
214 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
215 ref_id_type && ref_id,
221 tag_dict_type && tag_dict,
222 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
223 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score));
245 template <
typename t>
248 return std::forward<t>(v);
251 template <
typename stream_view_type, arithmetic value_type>
255 template <
typename stream_view_type>
258 template <
typename stream_view_type>
261 template <
typename stream_it_t, std::ranges::forward_range field_type>
264 template <
typename stream_it_t>
267 template <
typename stream_it_t>
272template <
typename stream_type,
273 typename seq_legal_alph_type,
274 typename stream_pos_type,
280 stream_pos_type & position_buffer,
283 qual_type & qualities)
309 if constexpr (!detail::decays_to_ignore_v<seq_type>)
310 if (std::ranges::distance(
sequence) == 0)
311 throw parse_error{
"The sequence information must not be empty."};
312 if constexpr (!detail::decays_to_ignore_v<id_type>)
313 if (std::ranges::distance(
id) == 0)
314 throw parse_error{
"The id information must not be empty."};
321template <
typename stream_type,
329 qual_type && qualities)
355template <
typename stream_type,
356 typename seq_legal_alph_type,
357 typename ref_seqs_type,
358 typename ref_ids_type,
359 typename stream_pos_type,
362 typename offset_type,
363 typename ref_seq_type,
364 typename ref_id_type,
365 typename ref_offset_type,
371 typename tag_dict_type,
372 typename e_value_type,
373 typename bit_score_type>
377 ref_seqs_type & ref_seqs,
379 stream_pos_type & position_buffer,
383 offset_type & offset,
384 ref_seq_type & SEQAN3_DOXYGEN_ONLY(ref_seq),
385 ref_id_type & ref_id,
386 ref_offset_type & ref_offset,
387 cigar_type & cigar_vector,
391 tag_dict_type & tag_dict,
392 e_value_type & SEQAN3_DOXYGEN_ONLY(e_value),
393 bit_score_type & SEQAN3_DOXYGEN_ONLY(bit_score))
395 static_assert(detail::decays_to_ignore_v<ref_offset_type>
396 || detail::is_type_specialisation_of_v<ref_offset_type, std::optional>,
397 "The ref_offset must be a specialisation of std::optional.");
402 int32_t ref_offset_tmp{};
403 std::ranges::range_value_t<
decltype(header.
ref_ids())> ref_id_tmp{};
416 position_buffer = stream.tellg();
420 if constexpr (!detail::decays_to_ignore_v<id_type>)
425 uint16_t flag_integral{};
435 if (ref_offset_tmp == -1)
437 else if (ref_offset_tmp > -1)
439 else if (ref_offset_tmp < -1)
440 throw format_error{
"No negative values are allowed for field::ref_offset."};
442 if constexpr (!detail::decays_to_ignore_v<mapq_type>)
449 if constexpr (!detail::decays_to_ignore_v<cigar_type>)
453 int32_t ref_length{0}, seq_length{0};
455 int32_t soft_clipping_end{};
456 int32_t offset_tmp{};
472 if constexpr (!detail::decays_to_ignore_v<mate_type>)
474 std::ranges::range_value_t<
decltype(header.
ref_ids())> tmp_mate_ref_id{};
477 if (tmp_mate_ref_id ==
"=")
479 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
493 get<1>(
mate) = --tmp_pnext;
494 else if (tmp_pnext < 0)
495 throw format_error{
"No negative values are allowed at the mate mapping position."};
502 for (
size_t i = 0; i < 3u; ++i)
512 constexpr auto is_legal_alph = char_is_valid_for<seq_legal_alph_type>;
516 [is_legal_alph](
char const c)
518 if (!is_legal_alph(c))
520 + detail::type_name_as_string<seq_legal_alph_type>
525 if constexpr (detail::decays_to_ignore_v<seq_type>)
541 auto const tab_or_end = is_char<'\t'> || is_char<'\r'> || is_char<'\n'>;
543 if constexpr (!detail::decays_to_ignore_v<qual_type>)
548 if constexpr (!detail::decays_to_ignore_v<seq_type> && !detail::decays_to_ignore_v<qual_type>)
550 if (std::ranges::distance(
seq) != 0 && std::ranges::distance(
qual) != 0
551 && std::ranges::distance(
seq) != std::ranges::distance(
qual))
554 std::ranges::distance(
seq),
555 ") and quality length (",
556 std::ranges::distance(
qual),
557 ") must be the same.")};
567 if constexpr (!detail::decays_to_ignore_v<tag_dict_type>)
577template <
typename stream_type,
578 typename header_type,
581 typename ref_seq_type,
582 typename ref_id_type,
585 typename tag_dict_type,
586 typename e_value_type,
587 typename bit_score_type>
590 header_type && header,
594 int32_t
const offset,
595 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
596 ref_id_type && ref_id,
602 tag_dict_type && tag_dict,
603 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
604 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score))
623 "The seq object must be a std::ranges::forward_range over "
624 "letters that model seqan3::alphabet.");
627 "The id object must be a std::ranges::forward_range over "
628 "letters that model seqan3::alphabet.");
630 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
632 static_assert((std::ranges::forward_range<ref_id_type> || std::integral<std::remove_reference_t<ref_id_type>>
633 || detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>),
634 "The ref_id object must be a std::ranges::forward_range "
635 "over letters that model seqan3::alphabet.");
637 if constexpr (std::integral<std::remove_cvref_t<ref_id_type>>
638 || detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>)
639 static_assert(!detail::decays_to_ignore_v<header_type>,
640 "If you give indices as reference id information the header must also be present.");
644 "The qual object must be a std::ranges::forward_range "
645 "over letters that model seqan3::alphabet.");
648 "The mate object must be a std::tuple of size 3 with "
649 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
650 "2) a std::integral or std::optional<std::integral>, and "
651 "3) a std::integral.");
654 ((std::ranges::forward_range<decltype(std::get<0>(
mate))>
656 || detail::is_type_specialisation_of_v<
658 std::optional>)&&(std::integral<std::remove_cvref_t<decltype(std::get<1>(
mate))>>
659 || detail::is_type_specialisation_of_v<
661 std::optional>)&&std::integral<std::remove_cvref_t<decltype(std::get<2>(
mate))>>),
662 "The mate object must be a std::tuple of size 3 with "
663 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
664 "2) a std::integral or std::optional<std::integral>, and "
665 "3) a std::integral.");
667 if constexpr (std::integral<std::remove_cvref_t<decltype(std::get<0>(
mate))>>
670 static_assert(!detail::decays_to_ignore_v<header_type>,
671 "If you give indices as mate reference id information the header must also be present.");
674 "The tag_dict object must be of type seqan3::sam_tag_dictionary.");
679 if constexpr (!detail::decays_to_ignore_v<header_type> && !detail::decays_to_ignore_v<ref_id_type>
680 && !std::integral<std::remove_reference_t<ref_id_type>>
681 && !detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
688 if constexpr (std::ranges::contiguous_range<
decltype(
ref_id)> && std::ranges::sized_range<
decltype(
ref_id)>
689 && std::ranges::borrowed_range<
decltype(
ref_id)>)
698 "The ref_id type is not convertible to the reference id information stored in the "
699 "reference dictionary of the header object.");
707 "' was not in the list of references:",
713 throw format_error{
"The ref_offset object must be a std::integral >= 0."};
718 if constexpr (!detail::decays_to_ignore_v<header_type>)
732 constexpr char separator{
'\t'};
735 *stream_it = separator;
737 stream_it.write_number(
static_cast<uint16_t
>(
flag));
738 *stream_it = separator;
740 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
742 if constexpr (std::integral<std::remove_reference_t<ref_id_type>>)
746 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
763 *stream_it = separator;
766 stream_it.write_number(
ref_offset.value_or(-1) + 1);
767 *stream_it = separator;
769 stream_it.write_number(
static_cast<unsigned>(
mapq));
770 *stream_it = separator;
772 if (!std::ranges::empty(cigar_vector))
774 for (
auto & c : cigar_vector)
775 stream_it.write_range(c.to_string());
782 *stream_it = separator;
784 if constexpr (std::integral<std::remove_reference_t<decltype(get<0>(
mate))>>)
788 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<decltype(get<0>(
mate))>,
791 if (get<0>(
mate).has_value())
801 *stream_it = separator;
803 if constexpr (detail::is_type_specialisation_of_v<std::remove_cvref_t<decltype(get<1>(
mate))>,
std::optional>)
806 stream_it.write_number(get<1>(
mate).value_or(-1) + 1);
807 *stream_it = separator;
811 stream_it.write_number(get<1>(
mate));
812 *stream_it = separator;
815 stream_it.write_number(get<2>(
mate));
816 *stream_it = separator;
819 *stream_it = separator;
845template <
typename stream_view_type, arithmetic value_type>
847 stream_view_type && stream_view,
859 variant = std::move(tmp_vector);
875template <
typename stream_view_type>
889 throw format_error{
"Hexadecimal tag has an uneven number of digits!"};
895 variant = std::move(tmp_vector);
915template <
typename stream_view_type>
956 target[tag] = stream_view | ranges::to<std::string>();
970 switch (array_value_type_id)
995 +
"id of a SAM tag must be one of [cCsSiIf] but '" + array_value_type_id
1002 "SAM tag must be one of [A,i,Z,H,B,f] but '")
1003 + type_id +
"' was given."};
1014template <
typename stream_it_t, std::ranges::forward_range field_type>
1017 if (std::ranges::empty(field_value))
1023 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<field_type>>,
char>)
1024 stream_it.write_range(field_value);
1036template <
typename stream_it_t>
1049template <
typename stream_it_t>
1053 auto const stream_variant_fn = [&stream_it](
auto && arg)
1057 if constexpr (std::ranges::input_range<T>)
1059 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
char>)
1061 stream_it.write_range(arg);
1063 else if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
std::byte>)
1065 if (!std::ranges::empty(arg))
1072 stream_it.write_number(std::to_integer<uint8_t>(elem));
1078 if (!std::ranges::empty(arg))
1085 stream_it.write_number(elem);
1090 else if constexpr (std::same_as<std::remove_cvref_t<T>,
char>)
1096 stream_it.write_number(arg);
1100 for (
auto & [tag, variant] : tag_dict)
1102 *stream_it = separator;
1104 char const char0 = tag / 256;
1105 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
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:148
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: sam_flag.hpp:76
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.
@ 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.
@ 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 alignment 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.