SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
debug_stream_alignment.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 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>
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{
104template <typename char_t, typename alignment_t>
105 requires (detail::debug_streamable_tuple<alignment_t>
106 && detail::all_model_aligned_seq<detail::tuple_type_list_t<std::remove_cvref_t<alignment_t>>>)
107inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_t && alignment)
108{
109 constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<alignment_t>>;
110
111 static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");
112
114 return stream;
115}
116
117} // 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:75
T for_each(T... args)
void stream_alignment(debug_stream_type< char_t > &stream, alignment_t const &align, std::index_sequence< idx... > const &)
Create the formatted alignment output and add it to the provided debug_stream.
Definition debug_stream_alignment.hpp:33
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:60
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:175
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 internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T setw(T... args)
Provides seqan3::views::slice.
Provides seqan3::views::to_char.
Provides seqan3::debug_stream and related types.
Provides seqan3::tuple_like.
Provides seqan3::views::zip.
Hide me