26 namespace seqan3::detail
36 template <
typename trace_matrix_t>
38 requires matrix<remove_cvref_t<trace_matrix_t>> &&
41 inline alignment_coordinate alignment_front_coordinate(trace_matrix_t && matrix,
42 alignment_coordinate
const back_coordinate)
44 constexpr
auto D = trace_directions::diagonal;
45 constexpr
auto L = trace_directions::left;
46 constexpr
auto U = trace_directions::up;
48 matrix_coordinate coordinate{row_index_type{back_coordinate.
second}, column_index_type{back_coordinate.first}};
50 assert(coordinate.row < matrix.rows());
51 assert(coordinate.col < matrix.cols());
55 trace_directions dir = matrix.at(coordinate);
58 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
60 else if ((dir & U) == U)
62 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
64 else if ((dir & D) == D)
66 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
67 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
72 if (!(coordinate.row == 0 || coordinate.col == 0))
73 throw std::logic_error{
"Unknown seqan3::trace_direction in an inner cell of the trace matrix."};
79 return {column_index_type{coordinate.col}, row_index_type{coordinate.row}};
99 typename trace_matrix_t>
101 requires matrix<remove_cvref_t<trace_matrix_t>> &&
103 detail::all_satisfy_aligned_seq<detail::tuple_type_list_t<alignment_t>>
105 inline alignment_t alignment_trace(database_t && database,
107 trace_matrix_t && matrix,
108 alignment_coordinate
const back_coordinate,
109 alignment_coordinate
const front_coordinate)
111 constexpr
auto N = trace_directions::none;
112 constexpr
auto D = trace_directions::diagonal;
113 constexpr
auto L = trace_directions::left;
114 constexpr
auto U = trace_directions::up;
116 matrix_coordinate coordinate{row_index_type{back_coordinate.second}, column_index_type{back_coordinate.first}};
118 assert(coordinate.row <= query.size());
119 assert(coordinate.col <= database.size());
120 assert(coordinate.row < matrix.rows());
121 assert(coordinate.col < matrix.cols());
123 alignment_t aligned_seq{};
126 auto end_aligned_db = std::ranges::cend(std::get<0>(aligned_seq));
127 auto end_aligned_qy = std::ranges::cend(std::get<1>(aligned_seq));
129 if (matrix.at({row_index_type{0u}, column_index_type{0u}}) != N)
134 trace_directions dir = matrix.at(coordinate);
137 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
139 end_aligned_qy =
insert_gap(std::get<1>(aligned_seq), end_aligned_qy);
141 else if ((dir & U) == U)
143 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
144 end_aligned_db =
insert_gap(std::get<0>(aligned_seq), end_aligned_db);
147 else if ((dir & D) == D)
149 coordinate.row = std::max<size_t>(coordinate.row, 1) - 1;
150 coordinate.col = std::max<size_t>(coordinate.col, 1) - 1;
157 if (!(coordinate.row == 0 || coordinate.col == 0))
158 throw std::logic_error{
"Unknown seqan3::trace_direction in an inner cell of the trace matrix."};