17 #include <range/v3/view/iota.hpp> 18 #include <range/v3/view/reverse.hpp> 19 #include <range/v3/view/zip.hpp> 52 template <
typename derived_t,
typename score_allocator_t,
typename trace_allocator_t>
53 class unbanded_score_trace_dp_matrix_policy :
54 public unbanded_score_dp_matrix_policy<unbanded_score_trace_dp_matrix_policy<derived_t,
62 using base_t = unbanded_score_dp_matrix_policy<unbanded_score_trace_dp_matrix_policy<derived_t,
70 using base_t::dimension_first_range;
72 using base_t::dimension_second_range;
74 using base_t::score_matrix;
76 using base_t::current_column_index;
81 using cell_type =
typename score_allocator_t::value_type;
85 using trace_type =
typename trace_allocator_t::value_type;
95 constexpr unbanded_score_trace_dp_matrix_policy() =
default;
96 constexpr unbanded_score_trace_dp_matrix_policy(unbanded_score_trace_dp_matrix_policy
const &) =
default;
98 constexpr unbanded_score_trace_dp_matrix_policy(unbanded_score_trace_dp_matrix_policy &&) =
default;
99 constexpr unbanded_score_trace_dp_matrix_policy & operator=(unbanded_score_trace_dp_matrix_policy
const &) =
default;
102 constexpr unbanded_score_trace_dp_matrix_policy & operator=(unbanded_score_trace_dp_matrix_policy &&) =
default;
103 ~unbanded_score_trace_dp_matrix_policy() =
default;
112 template <
typename first_range_t,
typename second_range_t>
113 constexpr
void allocate_matrix(first_range_t & first_range, second_range_t & second_range)
115 base_t::allocate_matrix(first_range, second_range);
118 trace_matrix.resize(dimension_first_range * dimension_second_range);
119 trace_matrix_iter = trace_matrix.begin();
123 constexpr
auto current_column()
125 advanceable_alignment_coordinate<advanceable_alignment_coordinate_state::row>
126 col_begin{column_index_type{current_column_index}, row_index_type{0u}};
127 advanceable_alignment_coordinate<advanceable_alignment_coordinate_state::row>
128 col_end{column_index_type{current_column_index}, row_index_type{dimension_second_range}};
132 std::span{
std::addressof(*trace_matrix_iter), dimension_second_range});
136 constexpr
void go_next_column() noexcept
138 base_t::go_next_column();
139 trace_matrix_iter += dimension_second_range;
148 constexpr
auto parse_traceback(alignment_coordinate
const & back_coordinate)
157 back_coordinate.first * dimension_second_range + back_coordinate.second);
160 while (*direction_iter != trace_directions::none)
163 while (static_cast<bool>(*direction_iter & trace_directions::diagonal))
169 if (static_cast<bool>(*direction_iter & trace_directions::up) ||
170 static_cast<bool>(*direction_iter & trace_directions::up_open))
174 dimension_second_range;
175 gap_segment gap{pos, 0u};
178 while (!static_cast<bool>(*direction_iter & trace_directions::up_open))
187 first_segments.push_front(std::move(gap));
191 if (static_cast<bool>(*direction_iter & trace_directions::left) ||
192 static_cast<bool>(*direction_iter & trace_directions::left_open))
196 dimension_second_range;
197 gap_segment gap{pos, 0u};
200 while (!static_cast<bool>(*direction_iter & trace_directions::left_open))
208 second_segments.push_front(std::move(gap));
214 dimension_second_range};
216 dimension_second_range};
218 return std::tuple{alignment_coordinate{column_index_type{std::move(c)}, row_index_type{std::move(r)}},
224 void print_trace_matrix()
226 auto printable = [](trace_directions dir)
229 if (dir == trace_directions::none)
231 if ((dir & trace_directions::diagonal) == trace_directions::diagonal)
233 if ((dir & trace_directions::up) == trace_directions::up)
235 if ((dir & trace_directions::up_open) == trace_directions::up_open)
237 if ((dir & trace_directions::left) == trace_directions::left)
239 if ((dir & trace_directions::left_open) == trace_directions::left_open)
244 for (
size_t row = 0; row < dimension_second_range; ++row)
246 for (
size_t col = 0; col < dimension_first_range; ++col)
248 debug_stream << printable(trace_matrix[col * dimension_second_range + row]) <<
" ";
255 trace_matrix_type trace_matrix{};
::ranges::distance distance
Alias for ranges::distance. Returns the number of hops from first to last.
Definition: iterator:321
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
constexpr auto zip
A range adaptor that transforms a tuple of range into a range of tuples.
Definition: ranges:948
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
Provides seqan3::detail::unbanded_score_dp_matrix_policy.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:249
::ranges::iterator_t iterator_t
Alias for ranges::iterator_t. Obtains the iterator type of a range.
Definition: ranges:204
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
::ranges::advance advance
Alias for ranges::advance. Advances the iterator by the given distance.
Definition: iterator:316
Provides std::span from the C++20 standard library.
constexpr auto iota
Generates a sequence of elements by repeatedly incrementing an initial value.
Definition: ranges:647
Provides the declaration of seqan3::detail::trace_directions.
Definition: aligned_sequence_concept.hpp:35
Provides seqan3::view::persist.
Provides seqan3::detail::alignment_coordinate.