seqan / seqan3

The modern C++ library for sequence analysis. Contains version 3 of the library and API docs.
https://www.seqan.de
Other
413 stars 82 forks source link

Alignment pretty printing issues #3309

Open feldroop opened 4 days ago

feldroop commented 4 days ago

Does this problem persist on the current main?

Is there an existing issue for this?

Current Behavior

Printing the alignment of the alignment result from the align_pairwise function using the debug_stream seems to be broken. Maybe the issue is using the uint8_t alphabet. Here is the code:

#include <seqan3/alignment/cigar_conversion/cigar_from_alignment.hpp>
#include <seqan3/alignment/configuration/align_config_edit.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/adaptation/uint.hpp>
#include <seqan3/core/debug_stream.hpp>

int main() {
    std::vector<uint8_t> seq1 {
        0,0,0,0,0,0,0,0,0,0,
        1,1,1,1,1,1,1,1,1,1,
        0,0,0,0,0,0,0,0,0,0
    };
    std::vector<uint8_t> seq2 {
        1,1,1,1,1
    };

    auto config = seqan3::align_cfg::method_global{
        seqan3::align_cfg::free_end_gaps_sequence1_leading{true},
        seqan3::align_cfg::free_end_gaps_sequence2_leading{false},
        seqan3::align_cfg::free_end_gaps_sequence1_trailing{true},
        seqan3::align_cfg::free_end_gaps_sequence2_trailing{false}
    }
    | seqan3::align_cfg::edit_scheme
    | seqan3::align_cfg::output_score{}
    | seqan3::align_cfg::output_begin_position{}
    | seqan3::align_cfg::output_alignment{};

    auto alignment_results = seqan3::align_pairwise(std::tie(seq1, seq2), config);
    auto alignment = *alignment_results.begin();

    seqan3::debug_stream << alignment << '\n';
    seqan3::debug_stream << alignment.alignment() << '\n';
    seqan3::debug_stream << seqan3::cigar_from_alignment(alignment.alignment(), {}, true) << '\n';

    return 0;
}

It prints:

{score: 0, begin: (15,0), 
alignment:
(,)}
(,)
[5=]

The CIGAR string is as expected, but just printing the alignment shows as (,), which seem to be not intended.

Expected Behavior

I would expect it to either not compile, because the uint8_t alphabet wrapper does not support this kind of pretty printing or to print a useful debug representation of the alignment (5 matches) and not just the symbols (,).

Steps To Reproduce

See above

Environment

- Operating system: Ubuntu 20.04
- SeqAn version: newest commit on main right now
- Compiler: gcc 12.3

Anything else?

No response

eseiler commented 4 days ago

Hey Felix,

you'll need to additionally include

#include <seqan3/alignment/aligned_sequence/debug_stream_alignment.hpp>

We redesigned the debug_stream (https://github.com/seqan/seqan3/pull/3259). It also ahs the side effect that <iostream> and seqan3's debug_stream are not auto-included, unless you actually want them.

With the include, the output is

{score: 0, begin: (15,0), 
alignment:
      0     .
        
        |||||
        
}
      0     .
        
        |||||
        

[5=]

Which I guess is OK, because uint8_t 0 isn't a printable character.

Without the include, it would use the next best fitting available printer, which would be the tuple printer, which does not convert the input sequences to char.

eseiler commented 3 days ago

I'm changing this issue from bug to documentation.

https://docs.seqan.de/seqan3/main_user/group__core__debug__stream.html

Could at least use a list of printers and the corresponding types it prints. Some printers are missing in the auto generated list of printers, because they are documented in another group (for example, the alignment printer)

feldroop commented 3 days ago

Maybe it would also be good to add it to the tutorial page of the pairwaise alignment? I looked for in in the Solution of assignment 4 and I didn't find it. link