SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t > Class Template Reference

A debug matrix to wrap alignment matrices and sequences and make them printable together. More...

#include <seqan3/alignment/matrix/detail/debug_matrix.hpp>

+ Inheritance diagram for seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >:

Classes

struct  format_type
 Format used by seqan3::detail::debug_matrix. More...
 

Public Types

Associated types
using value_type = std::conditional_t< is_traceback_matrix||is_optional_score, entry_t, std::optional< entry_t > >
 The type of an entry in the matrix.
 
using reference = value_type
 The type of a reference to an entry in the matrix.
 
using const_reference = reference
 The const reference type.
 
using size_type = typename std::remove_reference_t< matrix_t >::size_type
 The size type.
 

Public Member Functions

const_reference at (matrix_coordinate const &coordinate) const noexcept
 A reference to the entry of the matrix at the given coordinate.
 
size_t auto_column_width (fmtflags2 const flags) const noexcept
 Determines the largest width of all entries in the matrix, e.g. -152 has width 4.
 
size_t cols () const noexcept
 The number of columns in the matrix.
 
first_sequence_t const & first_sequence () const noexcept
 The first sequence of the sequence alignment.
 
debug_matrixmask_matrix (row_wise_matrix< bool > masking_matrix) noexcept
 Masks entries out of the current matrix. This operations changes the way this.at(i, j) will operate. If masking_matrix.at(i,j) returns true this.at(i, j) will operate as usual. But, if false this.at(i, j) will return std::nullopt.
 
debug_matrixmask_matrix (std::vector< bool > masking_vector) noexcept
 Creates the masking_matrix out of the given masking_vector and calls mask_matrix(row_wise_matrix<bool>)
 
size_t rows () const noexcept
 The number of rows in the matrix.
 
second_sequence_t const & second_sequence () const noexcept
 The second sequence of the sequence alignment.
 
template<typename ostream_t >
void stream_matrix (ostream_t &cout, fmtflags2 const flags) const noexcept
 Prints this matrix into the given stream.
 
debug_matrixsub_matrix (size_t const new_rows, size_t const new_cols) noexcept
 Limits the view port of the current matrix.
 
debug_matrixtranspose_matrix () noexcept
 Transposes the current matrix.
 
Constructors, destructor and assignment
 debug_matrix ()=default
 Defaulted.
 
 debug_matrix (debug_matrix const &)=default
 Defaulted.
 
 debug_matrix (debug_matrix &&)=default
 Defaulted.
 
debug_matrixoperator= (debug_matrix const &)=default
 Defaulted.
 
debug_matrixoperator= (debug_matrix &&)=default
 Defaulted.
 
 ~debug_matrix ()=default
 Defaulted.
 
 debug_matrix (matrix_t matrix)
 Construct the matrix out of an existing matrix.
 
 debug_matrix (matrix_t matrix, first_sequence_t first_sequence, second_sequence_t second_sequence)
 Construct the matrix out of an existing matrix and two sequences.
 

Public Attributes

std::optional< size_t > column_width {std::nullopt}
 What is the width (number of chars) of an entry. Defaults to auto_column_width.
 

Protected Types

using entry_t = typename std::remove_reference_t< matrix_t >::value_type
 The entry type.
 

Protected Member Functions

std::string entry_at (matrix_coordinate const coordinate, fmtflags2 flags) const noexcept
 Same as at(coordinate), but as string.
 

Static Protected Member Functions

template<typename value_type >
static std::string as_string (value_type &&entry, fmtflags2 const flags) noexcept
 Convert a value into a std::string.
 
static size_t unicode_str_length (std::string const &str) noexcept
 The length of the str (traceback symbols are unicode aware).
 

Protected Attributes

std::optional< size_t > _cols {}
 The number of columns the debug matrix should have. Must be at most the size of the original matrix.
 
first_sequence_t _first_sequence
 The first sequence of the sequence alignment.
 
std::optional< row_wise_matrix< bool > > _masking_matrix {}
 The masking matrix.
 
matrix_t _matrix
 The matrix.
 
std::optional< size_t > _rows {}
 The number of rows the debug matrix should have. Must be at most the size of the original matrix.
 
second_sequence_t _second_sequence
 The second sequence of the sequence alignment.
 
bool _transpose {}
 Whether the current matrix should be transposed.
 
bool _transpose_mask {}
 Whether the masking matrix should be transposed.
 

Static Protected Attributes

static constexpr format_type csv {" ", ";", "", "", ""}
 The format when printing to a ascii stream.
 
static constexpr bool has_first_sequence = !std::is_same_v<std::decay_t<first_sequence_t>, std::nullopt_t>
 Whether the current debug_matrix was given a first_sequence.
 
static constexpr bool has_second_sequence = !std::is_same_v<std::decay_t<second_sequence_t>, std::nullopt_t>
 Whether the current debug_matrix was given a second_sequence.
 
static constexpr bool is_optional_score = is_type_specialisation_of_v<entry_t, std::optional>
 Whether a score matrix already returns std::optional scores. (Where std::nullopt means unset/invalid/infinite score)
 
static constexpr bool is_traceback_matrix = std::is_same_v<std::decay_t<entry_t>, trace_directions>
 Whether the value_type is trace_directions.
 
static constexpr format_type unicode {"ε", "║", "═", "╬", "∞"}
 The format when printing to a unicode stream.
 

Related Symbols

(Note that these are not member symbols.)

Type deduction guides
template<matrix matrix_t>
 debug_matrix (matrix_t &&) -> debug_matrix< matrix_t >
 The type deduction guide for the constructor seqan3::detail::debug_matrix(matrix_t)
 
template<matrix matrix_t, typename first_sequence_t , typename second_sequence_t >
 debug_matrix (matrix_t &&, first_sequence_t &&, second_sequence_t &&) -> debug_matrix< matrix_t, first_sequence_t, second_sequence_t >
 The type deduction guide for the constructor seqan3::detail::debug_matrix(matrix_t, first_sequence_t, second_sequence_t)
 

Detailed Description

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
class seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >

A debug matrix to wrap alignment matrices and sequences and make them printable together.

Template Parameters
matrix_tAn alignment matrix; Must model seqan3::detail::matrix.
first_sequence_tThe type of the first sequence; If no sequences are given this is std::nullopt_t.
second_sequence_tThe type of the second sequence; If no sequences are given this is std::nullopt_t.

This debug matrix allows you to print an alignment matrix (e.g. score or trace matrix) combined with two sequences.

This type is used internally

Score matrix example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <iostream>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> database = "AACCGGTT"_dna4;
std::vector<seqan3::dna4> query = "ACGT"_dna4;
std::vector{-0, -1, -2, -3, -4, -5, -6, -7, -8, -1, -0, -1, -2, -3, -4, -5, -6, -7, -2, -1, -1, -1, -2,
-3, -4, -5, -6, -3, -2, -2, -2, -2, -2, -3, -4, -5, -4, -3, -3, -3, -3, -3, -3, -3, -4}};
seqan3::debug_stream << "database:\t" << database << '\n';
seqan3::debug_stream << "query:\t\t" << query << '\n';
seqan3::debug_stream << "score_matrix: " << score_matrix.cols() << " columns and " << score_matrix.rows()
<< " rows\n";
// Prints out the matrix in a convenient way
seqan3::debug_stream << score_matrix << '\n'; // without sequences
seqan3::debug_stream << debug_matrix{score_matrix, database, query} << '\n'; // with sequences
seqan3::debug_stream << seqan3::fmtflags2::utf8 << debug_matrix{score_matrix, database, query}; // as utf8
return 0;
}
A debug matrix to wrap alignment matrices and sequences and make them printable together.
Definition debug_matrix.hpp:59
debug_matrix()=default
Defaulted.
A two dimensional matrix used inside of alignment algorithms.
Definition two_dimensional_matrix.hpp:62
Provides the declaration of seqan3::detail::debug_matrix.
Provides seqan3::debug_stream and related types.
Provides seqan3::dna4, container aliases and string literals.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition debug_stream_type.hpp:30
The SeqAn namespace for literals.
Strong type for setting the column dimension of a matrix.
Definition two_dimensional_matrix.hpp:29
Strong type for setting the row dimension of a matrix.
Definition two_dimensional_matrix.hpp:37

Output

database: AACCGGTT
query: ACGT
score_matrix: 9 columns and 5 rows
; ; ; ; ; ; ; ; ; ;
;0 ;-1;-2;-3;-4;-5;-6;-7;-8;
;-1;0 ;-1;-2;-3;-4;-5;-6;-7;
;-2;-1;-1;-1;-2;-3;-4;-5;-6;
;-3;-2;-2;-2;-2;-2;-3;-4;-5;
;-4;-3;-3;-3;-3;-3;-3;-3;-4;
; ;A ;A ;C ;C ;G ;G ;T ;T ;
;0 ;-1;-2;-3;-4;-5;-6;-7;-8;
A;-1;0 ;-1;-2;-3;-4;-5;-6;-7;
C;-2;-1;-1;-1;-2;-3;-4;-5;-6;
G;-3;-2;-2;-2;-2;-2;-3;-4;-5;
T;-4;-3;-3;-3;-3;-3;-3;-3;-4;
║ε ║A ║A ║C ║C ║G ║G ║T ║T ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
ε║0 ║-1║-2║-3║-4║-5║-6║-7║-8║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
A║-1║0 ║-1║-2║-3║-4║-5║-6║-7║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
C║-2║-1║-1║-1║-2║-3║-4║-5║-6║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
G║-3║-2║-2║-2║-2║-2║-3║-4║-5║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
T║-4║-3║-3║-3║-3║-3║-3║-3║-4║

Trace matrix example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <iostream>
int main()
{
using namespace seqan3::literals;
using seqan3::operator|;
std::vector<seqan3::dna4> database = "AACCGGTT"_dna4;
std::vector<seqan3::dna4> query = "ACGT"_dna4;
std::vector{N, L, L, L, L, L, L, L, L, U, D, D | L, L, L, L,
L, L, L, U, U, D, D, D | L, L, L, L, L, U, U, D | U,
D | U, D, D, D | L, L, L, U, U, D | U, D | U, D | U, D | U, D, D, D | L}};
seqan3::debug_stream << "database:\t" << database << '\n';
seqan3::debug_stream << "query:\t\t" << query << '\n';
seqan3::debug_stream << "trace_matrix: " << trace_matrix.cols() << " columns and " << trace_matrix.rows()
<< " rows\n";
// Prints out the matrix in a convenient way
seqan3::debug_stream << trace_matrix << '\n'; // without sequences
seqan3::debug_stream << debug_matrix{trace_matrix, database, query} << '\n'; // with sequences
seqan3::debug_stream << seqan3::fmtflags2::utf8 << debug_matrix{trace_matrix, database, query}; // as utf8
return 0;
}
@ up
Trace comes from the above entry.
@ left
Trace comes from the left entry.
@ diagonal
Trace comes from the diagonal entry.
Provides seqan3::views::to_char.

Output

database: AACCGGTT
query: ACGT
trace_matrix: 9 columns and 5 rows
; ; ; ; ; ; ; ; ; ;
;N ;l ;l ;l ;l ;l ;l ;l ;l ;
;u ;D ;Dl;l ;l ;l ;l ;l ;l ;
;u ;u ;D ;D ;Dl;l ;l ;l ;l ;
;u ;u ;Du;Du;D ;D ;Dl;l ;l ;
;u ;u ;Du;Du;Du;Du;D ;D ;Dl;
; ;A ;A ;C ;C ;G ;G ;T ;T ;
;N ;l ;l ;l ;l ;l ;l ;l ;l ;
A;u ;D ;Dl;l ;l ;l ;l ;l ;l ;
C;u ;u ;D ;D ;Dl;l ;l ;l ;l ;
G;u ;u ;Du;Du;D ;D ;Dl;l ;l ;
T;u ;u ;Du;Du;Du;Du;D ;D ;Dl;
║ε ║A ║A ║C ║C ║G ║G ║T ║T ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
ε║↺ ║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
A║⇡ ║↖ ║↖⇠║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║⇠ ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
C║⇡ ║⇡ ║↖ ║↖ ║↖⇠║⇠ ║⇠ ║⇠ ║⇠ ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
G║⇡ ║⇡ ║↖⇡║↖⇡║↖ ║↖ ║↖⇠║⇠ ║⇠ ║
╬══╬══╬══╬══╬══╬══╬══╬══╬══╬
T║⇡ ║⇡ ║↖⇡║↖⇡║↖⇡║↖⇡║↖ ║↖ ║↖⇠║

Member Typedef Documentation

◆ reference

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
using seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::reference = value_type

The type of a reference to an entry in the matrix.

◆ value_type

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
using seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::value_type = std::conditional_t<is_traceback_matrix || is_optional_score, entry_t, std::optional<entry_t> >

The type of an entry in the matrix.

Constructor & Destructor Documentation

◆ debug_matrix() [1/2]

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::debug_matrix ( matrix_t  matrix)
inline

Construct the matrix out of an existing matrix.

Parameters
matrixAn alignment matrix; Must model seqan3::detail::matrix.

◆ debug_matrix() [2/2]

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::debug_matrix ( matrix_t  matrix,
first_sequence_t  first_sequence,
second_sequence_t  second_sequence 
)
inline

Construct the matrix out of an existing matrix and two sequences.

Parameters
matrixAn alignment matrix; Must model seqan3::detail::matrix.
first_sequenceThe first sequence of the sequence alignment.
second_sequenceThe second sequence of the sequence alignment.

Member Function Documentation

◆ at()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
const_reference seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::at ( matrix_coordinate const &  coordinate) const
inlinenoexcept

A reference to the entry of the matrix at the given coordinate.

◆ cols()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
size_t seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::cols ( ) const
inlinenoexcept

The number of columns in the matrix.

Implements seqan3::detail::matrix< matrix_t >.

◆ first_sequence()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
first_sequence_t const & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::first_sequence ( ) const
inlinenoexcept

The first sequence of the sequence alignment.

◆ mask_matrix() [1/2]

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
debug_matrix & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::mask_matrix ( row_wise_matrix< bool >  masking_matrix)
inlinenoexcept

Masks entries out of the current matrix. This operations changes the way this.at(i, j) will operate. If masking_matrix.at(i,j) returns true this.at(i, j) will operate as usual. But, if false this.at(i, j) will return std::nullopt.

Parameters
masking_matrixThe masking matrix.
Returns
*this

◆ mask_matrix() [2/2]

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
debug_matrix & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::mask_matrix ( std::vector< bool >  masking_vector)
inlinenoexcept

Creates the masking_matrix out of the given masking_vector and calls mask_matrix(row_wise_matrix<bool>)

Parameters
masking_vectorThe masking vector to construct the masking_matrix.
Returns
*this

◆ rows()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
size_t seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::rows ( ) const
inlinenoexcept

The number of rows in the matrix.

Implements seqan3::detail::matrix< matrix_t >.

◆ second_sequence()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
second_sequence_t const & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::second_sequence ( ) const
inlinenoexcept

The second sequence of the sequence alignment.

◆ stream_matrix()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
template<typename ostream_t >
void seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::stream_matrix ( ostream_t &  cout,
fmtflags2 const  flags 
) const
inlinenoexcept

Prints this matrix into the given stream.

Parameters
coutThe stream to print to.
flagsModify the way the matrix is printed.

The matrix will be printed with unicode characters if seqan3::fmtflags2::utf8 is set in the flags. Ascii otherwise.

◆ sub_matrix()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
debug_matrix & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::sub_matrix ( size_t const  new_rows,
size_t const  new_cols 
)
inlinenoexcept

Limits the view port of the current matrix.

Parameters
new_rowsThe number of rows the debug matrix should have. Must be at most the size of the original matrix.
new_colsThe number of columns the debug matrix should have. Must be at most the size of the original matrix.
Returns
*this

◆ transpose_matrix()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
debug_matrix & seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::transpose_matrix ( )
inlinenoexcept

Transposes the current matrix.

Returns
*this

◆ unicode_str_length()

template<matrix matrix_t, typename first_sequence_t = std::nullopt_t, typename second_sequence_t = std::nullopt_t>
static size_t seqan3::detail::debug_matrix< matrix_t, first_sequence_t, second_sequence_t >::unicode_str_length ( std::string const &  str)
inlinestaticprotectednoexcept

The length of the str (traceback symbols are unicode aware).

See also
https://en.wikipedia.org/wiki/UTF-8 for encoding details

The documentation for this class was generated from the following file:
Hide me