24namespace seqan3::detail
58template <matrix matrix_t,
typename first_sequence_t = std::nullopt_t,
typename second_sequence_t = std::nullopt_t>
63 static constexpr bool has_first_sequence = !std::is_same_v<std::decay_t<first_sequence_t>,
std::nullopt_t>;
65 static constexpr bool has_second_sequence = !std::is_same_v<std::decay_t<second_sequence_t>,
std::nullopt_t>;
69 static constexpr bool is_traceback_matrix = std::is_same_v<std::decay_t<entry_t>, trace_directions>;
72 static constexpr bool is_optional_score = is_type_specialisation_of_v<entry_t, std::optional>;
81 using reference = value_type;
83 using const_reference = reference;
91 debug_matrix() =
default;
92 debug_matrix(debug_matrix
const &) =
default;
93 debug_matrix(debug_matrix &&) =
default;
94 debug_matrix & operator=(debug_matrix
const &) =
default;
95 debug_matrix & operator=(debug_matrix &&) =
default;
96 ~debug_matrix() =
default;
101 debug_matrix(matrix_t matrix) : debug_matrix(
std::
forward<matrix_t>(matrix),
std::nullopt,
std::nullopt)
109 debug_matrix(matrix_t matrix, first_sequence_t first_sequence, second_sequence_t second_sequence) :
111 _first_sequence{
std::
forward<first_sequence_t>(first_sequence)},
112 _second_sequence{
std::
forward<second_sequence_t>(second_sequence)}
114 if constexpr (has_first_sequence)
116 assert(_matrix.cols() <= _first_sequence.size() + 1u);
119 if constexpr (has_second_sequence)
121 assert(_matrix.rows() <= _second_sequence.size() + 1u);
127 size_t rows() const noexcept
130 return _rows.value_or(_matrix.rows());
132 return _cols.value_or(_matrix.cols());
136 size_t cols() const noexcept
139 return _cols.value_or(_matrix.cols());
141 return _rows.value_or(_matrix.rows());
145 first_sequence_t
const & first_sequence() const noexcept
148 return _first_sequence;
150 return _second_sequence;
154 second_sequence_t
const & second_sequence() const noexcept
157 return _second_sequence;
159 return _first_sequence;
163 const_reference
at(matrix_coordinate
const & coordinate)
const noexcept
165 size_t row = coordinate.row;
166 size_t col = coordinate.col;
168 assert(row < rows() && col < cols());
170 row_index_type
const _row{!_transpose ? row : col};
171 column_index_type
const _col{!_transpose ? col : row};
172 row_index_type
const _mask_row{_transpose == _transpose_mask ? row : col};
173 column_index_type
const _mask_col{_transpose == _transpose_mask ? col : row};
175 if (!_masking_matrix.has_value() || _masking_matrix.value().at({_mask_row, _mask_col}))
177 entry_t
const & entry = _matrix.at({_row, _col});
179 if (!is_traceback_matrix || !_transpose)
182 if constexpr (is_traceback_matrix)
185 if ((entry & trace_directions::left) == trace_directions::left)
186 reverse |= trace_directions::up;
187 if ((entry & trace_directions::up) == trace_directions::up)
188 reverse |= trace_directions::left;
189 if ((entry & trace_directions::diagonal) == trace_directions::diagonal)
190 reverse |= trace_directions::diagonal;
195 if constexpr (is_traceback_matrix)
196 return trace_directions::none;
207 debug_matrix & mask_matrix(row_wise_matrix<bool> masking_matrix)
noexcept
209 assert(masking_matrix.rows() == rows());
210 assert(masking_matrix.cols() == cols());
211 _transpose_mask = _transpose;
212 _masking_matrix = std::move(masking_matrix);
222 return mask_matrix(row_wise_matrix<bool>{number_rows{rows()}, number_cols{cols()}, std::move(masking_vector)});
230 debug_matrix & sub_matrix(
size_t const new_rows,
size_t const new_cols)
noexcept
232 assert(new_rows <= rows());
233 assert(new_cols <= cols());
250 debug_matrix & transpose_matrix() noexcept
252 _transpose = !_transpose;
271 template <
typename ostream_t>
272 void stream_matrix(ostream_t & cout,
fmtflags2 const flags)
const noexcept
275 size_t const column_width =
276 this->column_width.has_value() ? this->column_width.value() : auto_column_width(flags);
278 auto char_first_sequence = [&]([[maybe_unused]]
size_t const i) ->
std::string
280 if constexpr (!has_first_sequence)
283 return as_string(first_sequence()[i], flags);
286 auto char_second_sequence = [&]([[maybe_unused]]
size_t const i) ->
std::string
288 if constexpr (!has_second_sequence)
291 return as_string(second_sequence()[i], flags);
297 size_t const length_bytes = symbol.size();
298 size_t const length = unicode_str_length(symbol);
299 size_t const offset = length_bytes - length;
304 auto print_first_cell = [&](
std::string const & symbol)
306 cout << symbol << symbols.col_sep;
310 auto print_first_row = [&]
312 print_first_cell(
" ");
313 print_cell(symbols.epsilon);
315 for (
size_t col = 0; col < cols() - 1; ++col)
316 print_cell(char_first_sequence(col));
322 auto print_divider = [&]
324 cout <<
" " << symbols.row_col_sep;
325 for (
size_t col = 0; col < cols(); ++col)
327 for (
size_t i = 0; i < column_width; ++i)
328 cout << symbols.row_sep;
330 cout << symbols.row_col_sep;
336 for (
size_t row = 0; row < rows(); ++row)
338 if (symbols.row_sep[0] !=
'\0')
343 print_first_cell(symbols.epsilon);
345 print_first_cell(char_second_sequence(row - 1));
347 for (
size_t col = 0; col < cols(); ++col)
348 print_cell(entry_at({row_index_type{row}, column_index_type{col}}, flags));
355 size_t auto_column_width(
fmtflags2 const flags)
const noexcept
357 size_t col_width = 1;
358 for (
size_t row = 0; row < rows(); ++row)
359 for (
size_t col = 0; col < cols(); ++col)
362 unicode_str_length(entry_at({row_index_type{row}, column_index_type{col}}, flags)));
373 value_type
const & entry =
at(coordinate);
374 if (!is_traceback_matrix && entry == matrix_inf<value_type>)
377 return as_string(entry, flags);
381 template <
typename value_type>
385 debug_stream_type stream{strstream};
386 stream << flags << entry;
387 return strstream.
str();
392 static size_t unicode_str_length(
std::string const & str)
noexcept
395 for (
auto it = str.cbegin(); it < str.cend(); ++it, ++length)
398 if ((v & 0b1110'0000) == 0b1100'0000)
400 else if ((v & 0b1111'0000) == 0b1110'0000)
402 else if ((v & 0b1111'1000) == 0b1111'0000)
412 char const * epsilon{};
414 char const * col_sep{};
416 char const * row_sep{};
418 char const * row_col_sep{};
424 static constexpr format_type csv{
" ",
";",
"",
"",
""};
426 static constexpr format_type unicode{
"ε",
"║",
"═",
"╬",
"∞"};
436 first_sequence_t _first_sequence;
438 second_sequence_t _second_sequence;
448 bool _transpose_mask{};
456template <matrix matrix_t>
457debug_matrix(matrix_t &&) -> debug_matrix<matrix_t>;
461template <matrix matrix_t,
typename first_sequence_t,
typename second_sequence_t>
462debug_matrix(matrix_t &&,
464 second_sequence_t &&) -> debug_matrix<matrix_t, first_sequence_t, second_sequence_t>;
479template <detail::matrix alignment_matrix_t>
494 template <
typename stream_t,
typename arg_t>
495 requires detail::is_type_specialisation_of_v<stream_t, debug_stream_type>
496 constexpr void operator()(stream_t & stream, arg_t && arg)
const
498 print_impl(stream.get_underlying_stream(), stream.flags2(), std::forward<arg_t>(arg));
496 constexpr void operator()(stream_t & stream, arg_t && arg)
const {
…}
511 template <
typename stream_t,
typename arg_t>
512 constexpr void operator()(stream_t & stream, arg_t && arg)
const
512 constexpr void operator()(stream_t & stream, arg_t && arg)
const {
…}
525 template <
typename stream_t,
typename arg_t>
526 void print_impl(stream_t & stream,
fmtflags2 const flags, arg_t && arg)
const
528 detail::debug_matrix debug{std::forward<arg_t>(arg)};
530 debug.stream_matrix(stream, flags);
Provides seqan3::debug_stream and related types.
Provides seqan3::debug_stream and related types.
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition debug_stream_type.hpp:32
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition type_list/traits.hpp:276
Provides seqan3::detail::matrix.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Provides seqan3::debug_stream and related types.
Provides seqan3::debug_stream and related types.
Provides seqan3::detail::row_wise_matrix.
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the alignment matrix into the given stream using ascii formatting.
Definition debug_matrix.hpp:512
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the alignment matrix into the given stream using formatting specified by seqan3::fmtflags2.
Definition debug_matrix.hpp:496
Definition default_printer.hpp:28
Provides type traits for working with templates.
Provides the declaration of seqan3::detail::trace_directions.