27 namespace seqan3::detail
37 template <
typename trace_matrix_t>
39 requires matrix<std::remove_cvref_t<trace_matrix_t>> &&
40 std::same_as<typename std::remove_cvref_t<trace_matrix_t>::value_type, trace_directions>
42 inline alignment_coordinate alignment_begin_positions(trace_matrix_t && matrix,
43 alignment_coordinate
const end_positions)
45 constexpr
auto D = trace_directions::diagonal;
46 constexpr
auto L = trace_directions::left;
47 constexpr
auto U = trace_directions::up;
49 matrix_coordinate coordinate{row_index_type{end_positions.
second}, column_index_type{end_positions.first}};
51 assert(coordinate.row < matrix.rows());
52 assert(coordinate.col < matrix.cols());
56 trace_directions dir = matrix.at(coordinate);
59 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
61 else if ((dir & U) == U)
63 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
65 else if ((dir & D) == D)
67 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
68 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
73 if (!(coordinate.row == 0 || coordinate.col == 0))
74 throw std::logic_error{
"Unknown seqan3::trace_direction in an inner cell of the trace matrix."};
80 return {column_index_type{coordinate.col}, row_index_type{coordinate.row}};
100 typename trace_matrix_t>
102 requires matrix<std::remove_cvref_t<trace_matrix_t>> &&
103 std::same_as<typename std::remove_cvref_t<trace_matrix_t>::value_type, trace_directions> &&
104 detail::all_model_writable_aligned_seq<detail::tuple_type_list_t<alignment_t>>
106 inline alignment_t alignment_trace(database_t && database,
108 trace_matrix_t && matrix,
109 alignment_coordinate
const end_positions,
110 alignment_coordinate
const begin_positions)
112 constexpr
auto N = trace_directions::none;
113 constexpr
auto D = trace_directions::diagonal;
114 constexpr
auto L = trace_directions::left;
115 constexpr
auto U = trace_directions::up;
117 matrix_coordinate coordinate{row_index_type{end_positions.second}, column_index_type{end_positions.first}};
119 assert(coordinate.row <= query.size());
120 assert(coordinate.col <= database.size());
121 assert(coordinate.row < matrix.rows());
122 assert(coordinate.col < matrix.cols());
124 alignment_t aligned_seq{};
128 |
views::slice(begin_positions.second, coordinate.row));
129 auto end_aligned_db = std::ranges::cend(std::get<0>(aligned_seq));
130 auto end_aligned_qy = std::ranges::cend(std::get<1>(aligned_seq));
132 if (matrix.at({row_index_type{0u}, column_index_type{0u}}) != N)
137 trace_directions dir = matrix.at(coordinate);
140 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
142 end_aligned_qy = insert_gap(std::get<1>(aligned_seq), end_aligned_qy);
144 else if ((dir & U) == U)
146 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
147 end_aligned_db = insert_gap(std::get<0>(aligned_seq), end_aligned_db);
150 else if ((dir & D) == D)
152 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
153 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
160 if (!(coordinate.row == 0 || coordinate.col == 0))
161 throw std::logic_error{
"Unknown seqan3::trace_direction in an inner cell of the trace matrix."};