SeqAn3 3.4.0-rc.4
The Modern C++ library for sequence analysis.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
debug_stream_alignment.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <iomanip>
13#include <tuple>
14
21
22namespace seqan3::detail
23{
24
32template <typename char_t, tuple_like alignment_t, size_t... idx>
33void stream_alignment(debug_stream_type<char_t> & stream,
34 alignment_t const & align,
36{
37 using std::get;
38 size_t const alignment_size = get<0>(align).size();
39
40 // split alignment into blocks of length 50 and loop over parts
41 for (size_t begin_pos = 0; begin_pos < alignment_size; begin_pos += 50)
42 {
43 size_t const end_pos = std::min(begin_pos + 50, alignment_size);
44
45 // write header line
46 if (begin_pos != 0)
47 stream << '\n';
48
49 stream << std::setw(7) << begin_pos << ' ';
50 for (size_t pos = begin_pos + 1; pos <= end_pos; ++pos)
51 {
52 if (pos % 10 == 0)
53 stream << ':';
54 else if (pos % 5 == 0)
55 stream << '.';
56 else
57 stream << ' ';
58 }
59
60 // write first sequence
61 stream << '\n' << std::setw(8) << "";
62 std::ranges::for_each(get<0>(align) | views::slice(begin_pos, end_pos) | views::to_char,
63 [&stream](char ch)
64 {
65 stream << ch;
66 });
67
68 auto stream_f = [&](auto const & previous_seq, auto const & aligned_seq)
69 {
70 // write alignment bars
71 stream << '\n' << std::setw(8) << "";
72 std::ranges::for_each(views::zip(previous_seq, aligned_seq) | views::slice(begin_pos, end_pos),
73 [&stream](auto && ch)
74 {
75 stream << (get<0>(ch) == get<1>(ch) ? '|' : ' ');
76 });
77
78 // write next sequence
79 stream << '\n' << std::setw(8) << "";
80 std::ranges::for_each(aligned_seq | views::slice(begin_pos, end_pos) | views::to_char,
81 [&stream](char ch)
82 {
83 stream << ch;
84 });
85 };
86 (stream_f(get<idx>(align), get<idx + 1>(align)), ...);
87 stream << '\n';
88 }
89}
90} // namespace seqan3::detail
91
92namespace seqan3
93{
94
100template <typename alignment_t>
101 requires tuple_like<alignment_t> && detail::all_model_aligned_seq<detail::tuple_type_list_t<alignment_t>>
102struct alignment_printer<alignment_t>
103{
110 template <typename stream_t, typename arg_t>
111 constexpr void operator()(stream_t & stream, arg_t && arg) const
112 {
113 constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<arg_t>>;
114
115 static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");
116
117 detail::stream_alignment(stream, std::forward<arg_t>(arg), std::make_index_sequence<sequence_count - 1>{});
118 }
119};
120
121} // namespace seqan3
Includes the aligned_sequence and the related insert_gap and erase_gap functions to enable stl contai...
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
T for_each(T... args)
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:60
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:137
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
Whether a type behaves like a tuple.
T min(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T setw(T... args)
Provides seqan3::views::slice.
constexpr void operator()(stream_t &stream, arg_t &&arg) const
The function call operator that pretty prints the alignment to the stream.
Definition debug_stream_alignment.hpp:111
Definition default_printer.hpp:29
Provides seqan3::views::to_char.
Provides seqan3::debug_stream and related types.
Provides seqan3::tuple_like.
Provides seqan3::views::zip.
Hide me