72 struct alignment_matrix_format
75 char const * epsilon{};
77 char const * col_sep{};
79 char const * row_sep{};
81 char const * row_col_sep{};
101 char const * trace_dir[8]{};
113 static const alignment_matrix_format csv;
125 static const alignment_matrix_format ascii;
137 static const alignment_matrix_format unicode_block;
149 static const alignment_matrix_format unicode_braille;
161 static const alignment_matrix_format unicode_arrows;
164 constexpr alignment_matrix_format alignment_matrix_format::csv
167 {
"N",
"D",
"U",
"DU",
"L",
"DL",
"UL",
"DUL"}
170 constexpr alignment_matrix_format alignment_matrix_format::ascii
173 {
" ",
"D",
"U",
"DU",
"L",
"DL",
"UL",
"DUL"}
176 constexpr alignment_matrix_format alignment_matrix_format::unicode_block
178 u8
"ε", u8
"║", u8
"═", u8
"╬",
179 {u8
"█",u8
"▘",u8
"▝",u8
"▀",u8
"▖",u8
"▌",u8
"▞",u8
"▛"}
182 constexpr alignment_matrix_format alignment_matrix_format::unicode_braille
184 u8
"ε", u8
"║", u8
"═", u8
"╬",
185 {u8
"⠀",u8
"⠁",u8
"⠈",u8
"⠉",u8
"⠄",u8
"⠅",u8
"⠌",u8
"⠍"}
188 constexpr alignment_matrix_format alignment_matrix_format::unicode_arrows
190 u8
"ε", u8
"║", u8
"═", u8
"╬",
191 {u8
"↺",u8
"↖",u8
"↑",u8
"↖↑",u8
"←",u8
"↖←",u8
"↑←",u8
"↖↑←"}
208 template <matrix_concept alignment_matrix_t>
209 class alignment_matrix_formatter
213 using alignment_matrix_type = alignment_matrix_t;
217 alignment_matrix_type
const & matrix;
221 alignment_matrix_format symbols;
228 alignment_matrix_formatter() =
delete;
229 alignment_matrix_formatter(alignment_matrix_formatter
const &) =
default;
230 alignment_matrix_formatter(alignment_matrix_formatter &&) =
default;
231 alignment_matrix_formatter & operator=(alignment_matrix_formatter
const &) =
default;
232 alignment_matrix_formatter & operator=(alignment_matrix_formatter &&) =
default;
238 alignment_matrix_formatter(alignment_matrix_type
const & _matrix, alignment_matrix_format _symbols = alignment_matrix_format::unicode_arrows)
239 : matrix{_matrix}, symbols{_symbols}
244 using entry_type =
typename alignment_matrix_type::entry_type;
247 static constexpr
bool is_traceback_matrix = std::is_same_v<entry_type, trace_directions>;
251 size_t auto_width() const noexcept
253 size_t col_width = 1;
254 for (
size_t row = 0; row < matrix.rows(); ++row)
255 for (
size_t col = 0; col < matrix.cols(); ++col)
256 col_width = std::max(col_width, unicode_str_length(entry_at(row, col)));
264 template <
typename database_t,
typename query_t>
265 void format(database_t && database, query_t && query, std::optional<size_t> column_width = std::nullopt)
const noexcept
267 format(std::forward<database_t>(database), std::forward<query_t>(query), std::cout, column_width);
278 template <
typename database_t,
typename query_t,
typename char_t,
typename traits_t>
279 void format(database_t && database, query_t && query, std::basic_ostream<char_t, traits_t> & cout, std::optional<size_t>
const column_width)
const noexcept
281 size_t const _column_width = column_width.has_value() ? column_width.value() : auto_width();
283 auto print_cell = [&](std::string
const & symbol)
286 size_t const length_bytes = unicode_str_length_bytes(symbol);
287 size_t const length = unicode_str_length(symbol);
288 size_t const offset = length_bytes - length;
291 << std::setw(_column_width + offset)
296 auto print_first_cell = [&](std::string
const & symbol)
298 cout << symbol << symbols.col_sep;
302 auto print_first_row = [&]
304 print_first_cell(
" ");
305 print_cell(symbols.epsilon);
307 for (
size_t col = 0; col < matrix.cols() - 1; ++col)
308 print_cell(as_string(database[col]));
313 auto print_divider = [&]
315 cout <<
" " << symbols.row_col_sep;
316 for (
size_t col = 0; col < matrix.cols(); ++col)
318 for (
size_t i = 0; i < _column_width; ++i)
319 cout << symbols.row_sep;
320 cout << symbols.row_col_sep;
326 for (
size_t row = 0; row < matrix.rows(); ++row)
328 if (symbols.row_sep[0] !=
'\0')
333 print_first_cell(symbols.epsilon);
335 print_first_cell(as_string(query[row - 1]));
336 for (
size_t col = 0; col < matrix.cols(); ++col)
337 print_cell(entry_at(row, col));
346 std::string entry_at(
size_t const row,
size_t const col)
const noexcept
348 if constexpr(is_traceback_matrix)
350 trace_directions direction = matrix.at(row, col);
351 return symbols.trace_dir[(size_t)(direction) % 8u];
355 entry_type entry = matrix.at(row, col);
356 return as_string(entry);
361 template <
typename entry_type>
362 static std::string as_string(entry_type && entry) noexcept
364 std::stringstream strstream;
365 debug_stream_type stream{strstream};
367 return strstream.str();
372 static size_t unicode_str_length(std::string
const & str) noexcept
375 for (
auto it = str.cbegin(), it_end = str.cend(); it < it_end; ++it, ++length)
378 if ((v & 0b11100000) == 0b11000000)
380 else if ((v & 0b11110000) == 0b11100000)
382 else if ((v & 0b11111000) == 0b11110000)
389 static size_t unicode_str_length_bytes(std::string
const & str) noexcept
395 friend struct matrix_formatter_test;
402 template<
typename alignment_matrix_t>
403 alignment_matrix_formatter(alignment_matrix_t
const &) -> alignment_matrix_formatter<alignment_matrix_t>;
405 template<
typename alignment_matrix_t>
406 alignment_matrix_formatter(alignment_matrix_t
const &, alignment_matrix_format) -> alignment_matrix_formatter<alignment_matrix_t>;
Contains the declaration of seqan3::detail::alignment_trace_matrix.
Definition: aligned_sequence_concept.hpp:288
Contains seqan3::detail::matrix_concept.
Provides seqan3::debug_stream and related types.