110template <
typename alignment_type>
113 bool const extended_cigar =
false)
116 && std::tuple_size_v<std::remove_cvref_t<alignment_type>> == 2),
117 "The alignment must be a std::pair or std::tuple of size 2.");
120 (std::equality_comparable_with<gap, std::ranges::range_reference_t<decltype(std::get<0>(
alignment))>>
121 && std::equality_comparable_with<gap, std::ranges::range_reference_t<
decltype(std::get<1>(
alignment))>>),
122 "The alignment must contain two ranges whose value_type is comparable to seqan3::gap.");
158 auto to_cigar_op = [extended_cigar](
auto const reference_char,
auto const query_char)
170 uint8_t key = (
static_cast<uint8_t
>(reference_char == gap{}) << 1) |
static_cast<uint8_t
>(query_char == gap{});
174 if (extended_cigar && (key == 0))
175 key |= ((1 << 2) |
static_cast<uint8_t
>(query_char == reference_char));
185 if (
ref_seq.size() != query_seq.size())
186 throw std::logic_error{
"The aligned sequences (including gaps) must have the same length."};
188 if (std::ranges::empty(
ref_seq))
194 if (clipped_bases.hard_front)
195 result.
emplace_back(clipped_bases.hard_front,
'H'_cigar_operation);
198 if (clipped_bases.soft_front)
199 result.emplace_back(clipped_bases.soft_front,
'S'_cigar_operation);
208 for (
auto && [reference_char, query_char] : views::
zip(
ref_seq, query_seq))
212 if (operation == next_op)
218 result.emplace_back(count, operation);
225 result.emplace_back(count, operation);
228 if (clipped_bases.soft_back)
229 result.emplace_back(clipped_bases.soft_back,
'S'_cigar_operation);
232 if (clipped_bases.hard_back)
233 result.emplace_back(clipped_bases.hard_back,
'H'_cigar_operation);
Provides the seqan3::cigar alphabet.
exposition_only::cigar_operation operation
The (extended) cigar operation alphabet of M,D,I,H,N,P,S,X,=.
Definition alphabet/cigar/cigar.hpp:93
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
T emplace_back(T... args)
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
auto cigar_from_alignment(alignment_type const &alignment, cigar_clipped_bases const &clipped_bases={}, bool const extended_cigar=false)
Creates a CIGAR string (SAM format) given a seqan3::detail::pairwise_alignment represented by two seq...
Definition cigar_from_alignment.hpp:111
@ ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition type_pack/traits.hpp:161
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
Whether a type behaves like a tuple.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Helper struct to specialise soft and hard clipping when using seqan3::cigar_from_alignment.
Definition cigar_from_alignment.hpp:27
uint32_t hard_front
The number of hard clipped bases at the front of the CIGAR string.
Definition cigar_from_alignment.hpp:28
uint32_t soft_back
The number of soft clipped bases at the back of the CIGAR string.
Definition cigar_from_alignment.hpp:31
uint32_t hard_back
The number of hard clipped bases at the back of the CIGAR string.
Definition cigar_from_alignment.hpp:29
uint32_t soft_front
The number of soft clipped bases at the front of the CIGAR string.
Definition cigar_from_alignment.hpp:30
Provides seqan3::views::zip.