26namespace seqan3::detail
60template <matrix matrix_t,
typename first_sequence_t = std::nullopt_t,
typename second_sequence_t = std::nullopt_t>
65 static constexpr bool has_first_sequence = !std::is_same_v<std::decay_t<first_sequence_t>,
std::nullopt_t>;
67 static constexpr bool has_second_sequence = !std::is_same_v<std::decay_t<second_sequence_t>,
std::nullopt_t>;
71 static constexpr bool is_traceback_matrix = std::is_same_v<std::decay_t<entry_t>, trace_directions>;
74 static constexpr bool is_optional_score = is_type_specialisation_of_v<entry_t, std::optional>;
83 using reference = value_type;
85 using const_reference = reference;
93 debug_matrix() =
default;
94 debug_matrix(debug_matrix
const &) =
default;
95 debug_matrix(debug_matrix &&) =
default;
96 debug_matrix & operator=(debug_matrix
const &) =
default;
97 debug_matrix & operator=(debug_matrix &&) =
default;
98 ~debug_matrix() =
default;
103 debug_matrix(matrix_t matrix) : debug_matrix(
std::
forward<matrix_t>(matrix),
std::nullopt,
std::nullopt)
111 debug_matrix(matrix_t matrix, first_sequence_t first_sequence, second_sequence_t second_sequence) :
113 _first_sequence{
std::
forward<first_sequence_t>(first_sequence)},
114 _second_sequence{
std::
forward<second_sequence_t>(second_sequence)}
116 if constexpr (has_first_sequence)
118 assert(_matrix.cols() <= _first_sequence.size() + 1u);
121 if constexpr (has_second_sequence)
123 assert(_matrix.rows() <= _second_sequence.size() + 1u);
129 size_t rows() const noexcept
132 return _rows.value_or(_matrix.rows());
134 return _cols.value_or(_matrix.cols());
138 size_t cols() const noexcept
141 return _cols.value_or(_matrix.cols());
143 return _rows.value_or(_matrix.rows());
147 first_sequence_t
const & first_sequence() const noexcept
150 return _first_sequence;
152 return _second_sequence;
156 second_sequence_t
const & second_sequence() const noexcept
159 return _second_sequence;
161 return _first_sequence;
165 const_reference
at(matrix_coordinate
const & coordinate)
const noexcept
167 size_t row = coordinate.row;
168 size_t col = coordinate.col;
170 assert(row < rows() && col < cols());
172 row_index_type
const _row{!_transpose ? row : col};
173 column_index_type
const _col{!_transpose ? col : row};
174 row_index_type
const _mask_row{_transpose == _transpose_mask ? row : col};
175 column_index_type
const _mask_col{_transpose == _transpose_mask ? col : row};
177 if (!_masking_matrix.has_value() || _masking_matrix.value().at({_mask_row, _mask_col}))
179 entry_t
const & entry = _matrix.at({_row, _col});
181 if (!is_traceback_matrix || !_transpose)
184 if constexpr (is_traceback_matrix)
187 if ((entry & trace_directions::left) == trace_directions::left)
188 reverse |= trace_directions::up;
189 if ((entry & trace_directions::up) == trace_directions::up)
190 reverse |= trace_directions::left;
191 if ((entry & trace_directions::diagonal) == trace_directions::diagonal)
192 reverse |= trace_directions::diagonal;
197 if constexpr (is_traceback_matrix)
198 return trace_directions::none;
209 debug_matrix & mask_matrix(row_wise_matrix<bool> masking_matrix)
noexcept
211 assert(masking_matrix.rows() == rows());
212 assert(masking_matrix.cols() == cols());
213 _transpose_mask = _transpose;
214 _masking_matrix = std::move(masking_matrix);
224 return mask_matrix(row_wise_matrix<bool>{number_rows{rows()}, number_cols{cols()}, std::move(masking_vector)});
232 debug_matrix & sub_matrix(
size_t const new_rows,
size_t const new_cols)
noexcept
234 assert(new_rows <= rows());
235 assert(new_cols <= cols());
252 debug_matrix & transpose_matrix() noexcept
254 _transpose = !_transpose;
273 template <
typename ostream_t>
274 void stream_matrix(ostream_t & cout,
fmtflags2 const flags)
const noexcept
277 size_t const column_width =
278 this->column_width.has_value() ? this->column_width.value() : auto_column_width(flags);
280 auto char_first_sequence = [&]([[maybe_unused]]
size_t const i) ->
std::string
282 if constexpr (!has_first_sequence)
285 return as_string(first_sequence()[i], flags);
288 auto char_second_sequence = [&]([[maybe_unused]]
size_t const i) ->
std::string
290 if constexpr (!has_second_sequence)
293 return as_string(second_sequence()[i], flags);
299 size_t const length_bytes = symbol.size();
300 size_t const length = unicode_str_length(symbol);
301 size_t const offset = length_bytes - length;
306 auto print_first_cell = [&](
std::string const & symbol)
308 cout << symbol << symbols.col_sep;
312 auto print_first_row = [&]
314 print_first_cell(
" ");
315 print_cell(symbols.epsilon);
317 for (
size_t col = 0; col < cols() - 1; ++col)
318 print_cell(char_first_sequence(col));
324 auto print_divider = [&]
326 cout <<
" " << symbols.row_col_sep;
327 for (
size_t col = 0; col < cols(); ++col)
329 for (
size_t i = 0; i < column_width; ++i)
330 cout << symbols.row_sep;
332 cout << symbols.row_col_sep;
338 for (
size_t row = 0; row < rows(); ++row)
340 if (symbols.row_sep[0] !=
'\0')
345 print_first_cell(symbols.epsilon);
347 print_first_cell(char_second_sequence(row - 1));
349 for (
size_t col = 0; col < cols(); ++col)
350 print_cell(entry_at({row_index_type{row}, column_index_type{col}}, flags));
357 size_t auto_column_width(
fmtflags2 const flags)
const noexcept
359 size_t col_width = 1;
360 for (
size_t row = 0; row < rows(); ++row)
361 for (
size_t col = 0; col < cols(); ++col)
364 unicode_str_length(entry_at({row_index_type{row}, column_index_type{col}}, flags)));
375 value_type
const & entry =
at(coordinate);
376 if (!is_traceback_matrix && entry == matrix_inf<value_type>)
379 return as_string(entry, flags);
383 template <
typename value_type>
387 debug_stream_type stream{strstream};
388 stream << flags << entry;
389 return strstream.
str();
394 static size_t unicode_str_length(
std::string const & str)
noexcept
397 for (
auto it = str.cbegin(); it < str.cend(); ++it, ++length)
400 if ((v & 0b11100000) == 0b11000000)
402 else if ((v & 0b11110000) == 0b11100000)
404 else if ((v & 0b11111000) == 0b11110000)
414 char const * epsilon{};
416 char const * col_sep{};
418 char const * row_sep{};
420 char const * row_col_sep{};
426 static constexpr format_type csv{
" ",
";",
"",
"",
""};
428 static constexpr format_type unicode{
"ε",
"║",
"═",
"╬",
"∞"};
438 first_sequence_t _first_sequence;
440 second_sequence_t _second_sequence;
450 bool _transpose_mask{};
458template <matrix matrix_t>
459debug_matrix(matrix_t &&) -> debug_matrix<matrix_t>;
463template <matrix matrix_t,
typename first_sequence_t,
typename second_sequence_t>
464debug_matrix(matrix_t &&, first_sequence_t &&, second_sequence_t &&)
465 -> debug_matrix<matrix_t, first_sequence_t, second_sequence_t>;
482template <
typename char_t, detail::matrix alignment_matrix_t>
483inline debug_stream_type<char_t> &
operator<<(debug_stream_type<char_t> & s, alignment_matrix_t && matrix)
485 detail::debug_matrix debug{std::forward<alignment_matrix_t>(matrix)};
488 debug.stream_matrix(sstream, s.flags2());
494template <
typename char_t, std::ranges::input_range alignment_matrix_t>
495 requires detail::debug_stream_range_guard<alignment_matrix_t> && detail::matrix<alignment_matrix_t>
496inline debug_stream_type<char_t> &
operator<<(debug_stream_type<char_t> & s, alignment_matrix_t && matrix)
498 return s << detail::debug_matrix{std::forward<alignment_matrix_t>(matrix)};
Provides seqan3::debug_stream and related types.
Provides seqan3::debug_stream and related types.
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:110
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition: debug_stream_type.hpp:31
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition: debug_stream_type.hpp:33
@ 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: traits.hpp:279
Provides seqan3::detail::matrix.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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.
Provides type traits for working with templates.
Provides the declaration of seqan3::detail::trace_directions.