30namespace seqan3::detail
34struct view_equality_fn
37 template <std::ranges::forward_range rng1_type, std::ranges::forward_range rng2_type>
38 constexpr bool operator()(rng1_type && rng1, rng2_type && rng2)
const
83template <
typename reference_
char_type,
typename query_
char_type>
84[[nodiscard]]
constexpr cigar::operation map_aligned_values_to_cigar_op(reference_char_type
const reference_char,
85 query_char_type
const query_char,
86 bool const extended_cigar)
87 requires seqan3::detail::weakly_equality_comparable_with<reference_char_type, gap>
88 && seqan3::detail::weakly_equality_comparable_with<query_char_type, gap>
91 uint8_t key = (
static_cast<uint8_t
>(reference_char == gap{}) << 1) |
static_cast<uint8_t
>(query_char == gap{});
92 if (extended_cigar && (key == 0))
93 key |= ((1 << 2) |
static_cast<uint8_t
>(query_char == reference_char));
105inline void update_alignment_lengths(int32_t & ref_length,
106 int32_t & seq_length,
107 char const cigar_operation,
108 uint32_t
const cigar_count)
110 switch (cigar_operation)
115 ref_length += cigar_count, seq_length += cigar_count;
119 ref_length += cigar_count;
122 seq_length += cigar_count;
129 throw format_error{
"Illegal cigar operation: " +
std::string{cigar_operation}};
147template <
typename cigar_input_type>
152 char cigar_operation{};
153 uint32_t cigar_count{};
154 int32_t ref_length{}, seq_length{};
168 throw format_error{
"Corrupted cigar string encountered"};
170 update_alignment_lengths(ref_length, seq_length, cigar_operation, cigar_count);
174 return {operations, ref_length, seq_length};
214template <seqan3::detail::pairwise_alignment alignment_type>
216 uint32_t
const query_start_pos = 0,
217 uint32_t
const query_end_pos = 0,
218 bool const extended_cigar =
false)
222 auto &
ref_seq = get<0>(alignment);
223 auto & query_seq = get<1>(alignment);
225 if (
ref_seq.size() != query_seq.size())
235 result.
emplace_back(query_start_pos,
'S'_cigar_operation);
240 cigar::operation operation{map_aligned_values_to_cigar_op(ref_seq[0], query_seq[0], extended_cigar)};
244 for (
auto column :
views::zip(ref_seq, query_seq))
247 map_aligned_values_to_cigar_op(std::get<0>(column), std::get<1>(column), extended_cigar);
249 if (operation == next_op)
255 result.emplace_back(
count, operation);
262 result.emplace_back(
count, operation);
266 result.emplace_back(query_end_pos,
'S'_cigar_operation);
280 [&result](
auto & cig)
320template <seqan3::detail::pairwise_alignment alignment_type>
321[[nodiscard]]
inline std::string get_cigar_string(alignment_type && alignment,
322 uint32_t
const query_start_pos = 0,
323 uint32_t
const query_end_pos = 0,
324 bool const extended_cigar =
false)
326 return get_cigar_string(get_cigar_vector(alignment, query_start_pos, query_end_pos, extended_cigar));
362template <seqan3::aligned_sequence ref_seq_type, seqan3::aligned_sequence query_seq_type>
363[[nodiscard]]
inline std::string get_cigar_string(ref_seq_type && ref_seq,
364 query_seq_type && query_seq,
365 uint32_t
const query_start_pos = 0,
366 uint32_t
const query_end_pos = 0,
367 bool const extended_cigar =
false)
369 return get_cigar_string(
std::tie(ref_seq, query_seq), query_start_pos, query_end_pos, extended_cigar);
394template <seqan3::detail::writable_pairwise_alignment alignment_type>
395inline void alignment_from_cigar(alignment_type & alignment,
std::vector<cigar> const & cigar_vector)
401 for (
auto [cigar_count, cigar_operation] : cigar_vector)
404 if ((
'S'_cigar_operation == cigar_operation) || (
'H'_cigar_operation == cigar_operation))
407 assert((
'M'_cigar_operation == cigar_operation) || (
'='_cigar_operation == cigar_operation)
408 || (
'X'_cigar_operation == cigar_operation) || (
'D'_cigar_operation == cigar_operation)
409 || (
'N'_cigar_operation == cigar_operation) || (
'I'_cigar_operation == cigar_operation)
410 || (
'P'_cigar_operation == cigar_operation));
412 if ((
'M'_cigar_operation == cigar_operation) || (
'='_cigar_operation == cigar_operation)
413 || (
'X'_cigar_operation == cigar_operation))
415 std::ranges::advance(current_ref_pos, cigar_count);
416 std::ranges::advance(current_read_pos, cigar_count);
418 else if ((
'D'_cigar_operation == cigar_operation) || (
'N'_cigar_operation == cigar_operation))
422 assert(
std::distance(current_read_pos, std::ranges::end(get<1>(alignment))) >= 0);
423 current_read_pos = insert_gap(get<1>(alignment), current_read_pos, cigar_count);
425 std::ranges::advance(current_ref_pos, cigar_count);
427 else if ((
'I'_cigar_operation == cigar_operation))
429 assert(std::ranges::distance(current_ref_pos, std::ranges::end(get<0>(alignment))) >= 0);
430 current_ref_pos = insert_gap(get<0>(alignment), current_ref_pos, cigar_count);
432 std::ranges::advance(current_read_pos, cigar_count);
434 else if ((
'P'_cigar_operation == cigar_operation))
436 current_ref_pos = insert_gap(get<0>(alignment), current_ref_pos, cigar_count);
439 current_read_pos = insert_gap(get<1>(alignment), current_read_pos, cigar_count);
447struct access_restrictor_fn
450 template <
typename chr_t>
451 [[noreturn]] chr_t operator()(chr_t)
const
453 throw std::logic_error{
"Access is not allowed because there is no sequence information."};
Provides the seqan3::cigar alphabet.
The <charconv> header from C++17's standard library.
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:163
exposition_only::cigar_operation operation
The (extended) cigar operation alphabet of M,D,I,H,N,P,S,X,=.
Definition: cigar.hpp:98
T emplace_back(T... args)
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:524
@ ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
constexpr auto is_digit
Checks whether c is a digital character.
Definition: predicate.hpp:262
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition: traits.hpp:164
constexpr auto single_pass_input
A view adapter that decays most of the range properties and adds single pass behavior.
Definition: single_pass_input.hpp:348
constexpr auto zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition: zip.hpp:573
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: configuration.hpp:415
Provides seqan3::detail::pairwise_alignment and seqan3::detail::writable_pairwise_alignment.
Provides character predicates for tokenisation.
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
Auxiliary for pretty printing of exception messages.
Provides seqan3::tuple_like.
Provides seqan3::views::zip.