137 template <
typename stream_type,
138 typename seq_legal_alph_type,
146 qual_type & qualities);
148 template <
typename stream_type,
156 qual_type && qualities);
158 template <
typename stream_type,
159 typename seq_legal_alph_type,
160 typename ref_seqs_type,
161 typename ref_ids_type,
164 typename offset_type,
165 typename ref_seq_type,
166 typename ref_id_type,
167 typename ref_offset_type,
174 typename tag_dict_type,
175 typename e_value_type,
176 typename bit_score_type>
179 ref_seqs_type & ref_seqs,
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,
189 cigar_type & cigar_vector,
193 tag_dict_type & tag_dict,
194 e_value_type & SEQAN3_DOXYGEN_ONLY(e_value),
195 bit_score_type & SEQAN3_DOXYGEN_ONLY(bit_score));
197 template <
typename stream_type,
198 typename header_type,
201 typename ref_seq_type,
202 typename ref_id_type,
206 typename tag_dict_type,
207 typename e_value_type,
208 typename bit_score_type>
211 header_type && header,
215 int32_t
const offset,
216 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
217 ref_id_type && ref_id,
224 tag_dict_type && tag_dict,
225 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
226 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score));
248 template <
typename t>
251 return std::forward<t>(v);
254 template <
typename stream_view_type, arithmetic value_type>
256 stream_view_type && stream_view,
259 template <
typename stream_view_type>
261 stream_view_type && stream_view);
263 template <
typename stream_view_type>
266 template <
typename stream_it_t, std::ranges::forward_range field_type>
269 template <
typename stream_it_t>
272 template <
typename stream_it_t>
277template <
typename stream_type,
278 typename seq_legal_alph_type,
286 qual_type & qualities)
292 std::ignore, std::ignore, std::ignore, std::ignore, std::ignore, std::ignore,
293 std::ignore, std::ignore, std::ignore, std::ignore, std::ignore, std::ignore);
296 if constexpr (!detail::decays_to_ignore_v<seq_type>)
297 if (std::ranges::distance(
sequence) == 0)
298 throw parse_error{
"The sequence information must not be empty."};
299 if constexpr (!detail::decays_to_ignore_v<id_type>)
300 if (std::ranges::distance(
id) == 0)
301 throw parse_error{
"The id information must not be empty."};
308template <
typename stream_type,
316 qual_type && qualities)
344template <
typename stream_type,
345 typename seq_legal_alph_type,
346 typename ref_seqs_type,
347 typename ref_ids_type,
350 typename offset_type,
351 typename ref_seq_type,
352 typename ref_id_type,
353 typename ref_offset_type,
360 typename tag_dict_type,
361 typename e_value_type,
362 typename bit_score_type>
365 ref_seqs_type & ref_seqs,
370 offset_type & offset,
371 ref_seq_type & SEQAN3_DOXYGEN_ONLY(ref_seq),
372 ref_id_type & ref_id,
373 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.");
391 int32_t ref_offset_tmp{};
392 std::ranges::range_value_t<
decltype(header.
ref_ids())> ref_id_tmp{};
393 [[maybe_unused]] int32_t offset_tmp{};
394 [[maybe_unused]] int32_t soft_clipping_end{};
396 [[maybe_unused]] int32_t ref_length{0}, seq_length{0};
400 if (is_char<'@'>(*std::ranges::begin(stream_view)))
404 if (std::ranges::begin(stream_view) == std::ranges::end(stream_view))
410 if constexpr (!detail::decays_to_ignore_v<id_type>)
415 uint16_t flag_integral{};
425 if (ref_offset_tmp == -1)
427 else if (ref_offset_tmp > -1)
429 else if (ref_offset_tmp < -1)
430 throw format_error{
"No negative values are allowed for field::ref_offset."};
432 if constexpr (!detail::decays_to_ignore_v<mapq_type>)
439 if constexpr (!detail::decays_to_ignore_v<align_type> || !detail::decays_to_ignore_v<cigar_type>)
441 if (!is_char<'*'>(*std::ranges::begin(stream_view)))
449 std::ranges::next(std::ranges::begin(field_view));
461 if constexpr (!detail::decays_to_ignore_v<mate_type>)
463 std::ranges::range_value_t<
decltype(header.
ref_ids())> tmp_mate_ref_id{};
466 if (tmp_mate_ref_id ==
"=")
468 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
482 get<1>(
mate) = --tmp_pnext;
483 else if (tmp_pnext < 0)
484 throw format_error{
"No negative values are allowed at the mate mapping position."};
491 for (
size_t i = 0; i < 3u; ++i)
499 if (!is_char<'*'>(*std::ranges::begin(stream_view)))
501 auto constexpr is_legal_alph = char_is_valid_for<seq_legal_alph_type>;
504 if (!is_legal_alph(c))
506 "char_is_valid_for<" +
507 detail::type_name_as_string<seq_legal_alph_type> +
508 "> evaluated to false on " +
513 if constexpr (detail::decays_to_ignore_v<seq_type>)
515 if constexpr (!detail::decays_to_ignore_v<align_type>)
518 "If you want to read ALIGNMENT but not SEQ, the alignment"
519 " object must store a sequence container at the second (query) position.");
521 if (!tmp_cigar_vector.empty())
524 auto tmp_iter = std::ranges::begin(seq_stream);
525 std::ranges::advance(tmp_iter, offset_tmp);
527 for (; seq_length > 0; --seq_length)
529 get<1>(align).push_back(std::ranges::range_value_t<
decltype(get<1>(align))>{}.assign_char(*tmp_iter));
533 std::ranges::advance(tmp_iter, soft_clipping_end);
549 if constexpr (!detail::decays_to_ignore_v<align_type>)
551 if (!tmp_cigar_vector.empty())
553 assign_unaligned(get<1>(align),
562 std::ranges::next(std::ranges::begin(field_view));
567 auto const tab_or_end = is_char<'\t'> || is_char<'\r'> || is_char<'\n'>;
569 if constexpr (!detail::decays_to_ignore_v<qual_type>)
574 if constexpr (!detail::decays_to_ignore_v<seq_type> && !detail::decays_to_ignore_v<qual_type>)
576 if (std::ranges::distance(
seq) != 0 && std::ranges::distance(
qual) != 0 &&
577 std::ranges::distance(
seq) != std::ranges::distance(
qual))
580 ") and quality length (", std::ranges::distance(
qual),
581 ") must be the same.")};
587 while (is_char<'\t'>(*std::ranges::begin(stream_view)))
589 std::ranges::next(std::ranges::begin(stream_view));
591 if constexpr (!detail::decays_to_ignore_v<tag_dict_type>)
603 if constexpr (!detail::decays_to_ignore_v<align_type>)
605 int32_t ref_idx{(ref_id_tmp.empty()) ? -1 : 0};
607 if constexpr (!detail::decays_to_ignore_v<ref_seqs_type>)
609 if (!ref_id_tmp.empty())
611 assert(header.
ref_dict.count(ref_id_tmp) != 0);
612 ref_idx = header.
ref_dict[ref_id_tmp];
616 construct_alignment(align, tmp_cigar_vector, ref_idx, ref_seqs, ref_offset_tmp, ref_length);
619 if constexpr (!detail::decays_to_ignore_v<cigar_type>)
620 std::swap(cigar_vector, tmp_cigar_vector);
624template <
typename stream_type,
625 typename header_type,
628 typename ref_seq_type,
629 typename ref_id_type,
633 typename tag_dict_type,
634 typename e_value_type,
635 typename bit_score_type>
638 header_type && header,
642 int32_t
const offset,
643 ref_seq_type && SEQAN3_DOXYGEN_ONLY(ref_seq),
644 ref_id_type && ref_id,
651 tag_dict_type && tag_dict,
652 e_value_type && SEQAN3_DOXYGEN_ONLY(e_value),
653 bit_score_type && SEQAN3_DOXYGEN_ONLY(bit_score))
671 static_assert((std::ranges::forward_range<seq_type> &&
673 "The seq object must be a std::ranges::forward_range over "
674 "letters that model seqan3::alphabet.");
676 static_assert((std::ranges::forward_range<id_type> &&
678 "The id object must be a std::ranges::forward_range over "
679 "letters that model seqan3::alphabet.");
681 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
683 static_assert((std::ranges::forward_range<ref_id_type> ||
684 std::integral<std::remove_reference_t<ref_id_type>> ||
685 detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>),
686 "The ref_id object must be a std::ranges::forward_range "
687 "over letters that model seqan3::alphabet.");
689 if constexpr (std::integral<std::remove_cvref_t<ref_id_type>> ||
690 detail::is_type_specialisation_of_v<std::remove_cvref_t<ref_id_type>,
std::optional>)
691 static_assert(!detail::decays_to_ignore_v<header_type>,
692 "If you give indices as reference id information the header must also be present.");
696 "The align object must be a std::pair of two ranges whose "
697 "value_type is comparable to seqan3::gap");
699 static_assert((std::tuple_size_v<std::remove_cvref_t<align_type>> == 2 &&
700 std::equality_comparable_with<gap, std::ranges::range_reference_t<decltype(std::get<0>(align))>> &&
701 std::equality_comparable_with<
gap, std::ranges::range_reference_t<
decltype(std::get<1>(align))>>),
702 "The align object must be a std::pair of two ranges whose "
703 "value_type is comparable to seqan3::gap");
705 static_assert((std::ranges::forward_range<qual_type> &&
707 "The qual object must be a std::ranges::forward_range "
708 "over letters that model seqan3::alphabet.");
711 "The mate object must be a std::tuple of size 3 with "
712 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
713 "2) a std::integral or std::optional<std::integral>, and "
714 "3) a std::integral.");
716 static_assert(((std::ranges::forward_range<decltype(std::get<0>(
mate))> ||
719 (std::integral<std::remove_cvref_t<decltype(std::get<1>(
mate))>> ||
721 std::integral<std::remove_cvref_t<decltype(std::get<2>(
mate))>>),
722 "The mate object must be a std::tuple of size 3 with "
723 "1) a std::ranges::forward_range with a value_type modelling seqan3::alphabet, "
724 "2) a std::integral or std::optional<std::integral>, and "
725 "3) a std::integral.");
727 if constexpr (std::integral<std::remove_cvref_t<decltype(std::get<0>(
mate))>> ||
729 static_assert(!detail::decays_to_ignore_v<header_type>,
730 "If you give indices as mate reference id information the header must also be present.");
733 "The tag_dict object must be of type seqan3::sam_tag_dictionary.");
738 if constexpr (!detail::decays_to_ignore_v<header_type> &&
739 !detail::decays_to_ignore_v<ref_id_type> &&
740 !std::integral<std::remove_reference_t<ref_id_type>> &&
741 !detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
748 if constexpr (std::ranges::contiguous_range<
decltype(
ref_id)> &&
749 std::ranges::sized_range<
decltype(
ref_id)> &&
750 std::ranges::borrowed_range<
decltype(
ref_id)>)
759 "The ref_id type is not convertible to the reference id information stored in the "
760 "reference dictionary of the header object.");
772 throw format_error{
"The ref_offset object must be an std::integral >= 0."};
777 if constexpr (!detail::decays_to_ignore_v<header_type>)
791 constexpr char separator{
'\t'};
794 *stream_it = separator;
796 stream_it.write_number(
static_cast<uint16_t
>(
flag));
797 *stream_it = separator;
799 if constexpr (!detail::decays_to_ignore_v<ref_id_type>)
801 if constexpr (std::integral<std::remove_reference_t<ref_id_type>>)
805 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<ref_id_type>,
std::optional>)
822 *stream_it = separator;
825 stream_it.write_number(
ref_offset.value_or(-1) + 1);
826 *stream_it = separator;
828 stream_it.write_number(
static_cast<unsigned>(
mapq));
829 *stream_it = separator;
831 if (!std::ranges::empty(cigar_vector))
833 for (
auto & c : cigar_vector)
834 stream_it.write_range(c.to_string());
836 else if (!std::ranges::empty(get<0>(align)) && !std::ranges::empty(get<1>(align)))
843 for (
auto chr : get<1>(align))
858 *stream_it = separator;
860 if constexpr (std::integral<std::remove_reference_t<decltype(get<0>(
mate))>>)
864 else if constexpr (detail::is_type_specialisation_of_v<std::remove_reference_t<decltype(get<0>(
mate))>,
std::optional>)
866 if (get<0>(
mate).has_value())
878 *stream_it = separator;
880 if constexpr (detail::is_type_specialisation_of_v<std::remove_cvref_t<decltype(get<1>(
mate))>,
std::optional>)
883 stream_it.write_number(get<1>(
mate).value_or(-1) + 1);
884 *stream_it = separator;
888 stream_it.write_number(get<1>(
mate));
889 *stream_it = separator;
892 stream_it.write_number(get<2>(
mate));
893 *stream_it = separator;
896 *stream_it = separator;
923template <
typename stream_view_type, arithmetic value_type>
925 stream_view_type && stream_view,
929 while (std::ranges::begin(stream_view) != ranges::end(stream_view))
934 if (is_char<','>(*std::ranges::begin(stream_view)))
935 std::ranges::next(std::ranges::begin(stream_view));
937 variant = std::move(tmp_vector);
953template <
typename stream_view_type>
955 stream_view_type && stream_view)
960 while (std::ranges::begin(stream_view) != ranges::end(stream_view))
968 throw format_error{
"Hexadecimal tag has an uneven number of digits!"};
974 variant = std::move(tmp_vector);
994template <
typename stream_view_type>
1002 uint16_t tag =
static_cast<uint16_t
>(*std::ranges::begin(stream_view)) << 8;
1003 std::ranges::next(std::ranges::begin(stream_view));
1004 tag +=
static_cast<uint16_t
>(*std::ranges::begin(stream_view));
1005 std::ranges::next(std::ranges::begin(stream_view));
1006 std::ranges::next(std::ranges::begin(stream_view));
1007 char type_id = *std::ranges::begin(stream_view);
1008 std::ranges::next(std::ranges::begin(stream_view));
1009 std::ranges::next(std::ranges::begin(stream_view));
1015 target[tag] =
static_cast<char>(*std::ranges::begin(stream_view));
1016 std::ranges::next(std::ranges::begin(stream_view));
1035 target[tag] = stream_view | views::to<std::string>;
1045 char array_value_type_id = *std::ranges::begin(stream_view);
1046 std::ranges::next(std::ranges::begin(stream_view));
1047 std::ranges::next(std::ranges::begin(stream_view));
1049 switch (array_value_type_id)
1074 "id of a SAM tag must be one of [cCsSiIf] but '" + array_value_type_id +
1081 "SAM tag must be one of [A,i,Z,H,B,f] but '") + type_id +
"' was given."};
1092template <
typename stream_it_t, std::ranges::forward_range field_type>
1095 if (std::ranges::empty(field_value))
1101 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<field_type>>,
char>)
1102 stream_it.write_range(field_value);
1114template <
typename stream_it_t>
1127template <
typename stream_it_t>
1130 auto const stream_variant_fn = [&stream_it] (
auto && arg)
1134 if constexpr (std::ranges::input_range<T>)
1136 if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
char>)
1138 stream_it.write_range(arg);
1140 else if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<T>>,
std::byte>)
1142 if (!std::ranges::empty(arg))
1144 stream_it.write_number(std::to_integer<uint8_t>(*std::ranges::begin(arg)));
1149 stream_it.write_number(std::to_integer<uint8_t>(elem));
1155 if (!std::ranges::empty(arg))
1157 stream_it.write_number(*std::ranges::begin(arg));
1162 stream_it.write_number(elem);
1167 else if constexpr (std::same_as<std::remove_cvref_t<T>,
char>)
1173 stream_it.write_number(arg);
1177 for (
auto & [tag, variant] : tag_dict)
1179 *stream_it = separator;
1181 char const char0 = tag / 256;
1182 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:39
The alphabet of a gap character '-'.
Definition: gap.hpp:39
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:334
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: 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: cigar.hpp:137
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: sam_flag.hpp:74
std::string get_cigar_string(std::vector< cigar > const &cigar_vector)
Transforms a vector of cigar elements into a string representation.
Definition: cigar.hpp:266
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:40
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:37
@ 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:578
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:608
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:620
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:606
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:592
constexpr auto istreambuf
A view factory that returns a view over the stream buffer of an input stream.
Definition: istreambuf_view.hpp:110
@ 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:128
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: traits.hpp:388
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: traits.hpp:471
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:151
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:183
The generic alphabet concept that covers most data types used in ranges.
Resolves to std::ranges::implicitly_convertible_to<type1, type2>(). <dl class="no-api">This entity i...
A more refined container concept than seqan3::container.
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: cigar_operation_table.hpp:2
Adaptations of concepts from the Ranges TS.
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: exception.hpp:48
The options type defines various option members that influence the behavior of all or some formats.
Definition: output_options.hpp:23
bool add_carriage_return
The default plain text line-ending is "\n", but on Windows an additional carriage return is recommend...
Definition: output_options.hpp:27
bool sam_require_header
Whether to require a header for SAM files.
Definition: output_options.hpp:41
The options type defines various option members that influence the behaviour of all or some formats.
Definition: output_options.hpp:23
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Provides seqan3::views::to.
Provides seqan3::views::to_char.
Provides traits to inspect some information of a type, for example its name.
Provides seqan3::tuple_like.