SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
debug_stream_alignment.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <iomanip>
16#include <tuple>
17
24
25namespace seqan3::detail
26{
27
35template <typename char_t, tuple_like alignment_t, size_t ...idx>
36void stream_alignment(debug_stream_type<char_t> & stream, alignment_t const & align, std::index_sequence<idx...> const & )
37{
38 using std::get;
39 size_t const alignment_size = get<0>(align).size();
40
41 // split alignment into blocks of length 50 and loop over parts
42 for (size_t begin_pos = 0; begin_pos < alignment_size; begin_pos += 50)
43 {
44 size_t const end_pos = std::min(begin_pos + 50, alignment_size);
45
46 // write header line
47 if (begin_pos != 0)
48 stream << '\n';
49
50 stream << std::setw(7) << begin_pos << ' ';
51 for (size_t pos = begin_pos + 1; pos <= end_pos; ++pos)
52 {
53 if (pos % 10 == 0)
54 stream << ':';
55 else if (pos % 5 == 0)
56 stream << '.';
57 else
58 stream << ' ';
59 }
60
61 // write first sequence
62 stream << '\n' << std::setw(8) << "";
63 std::ranges::for_each(get<0>(align) | views::slice(begin_pos, end_pos) | views::to_char,
64 [&stream] (char ch) { stream << ch; });
65
66 auto stream_f = [&] (auto const & previous_seq, auto const & aligned_seq)
67 {
68 // write alignment bars
69 stream << '\n' << std::setw(8) << "";
70 std::ranges::for_each(views::zip(previous_seq, aligned_seq) | views::slice(begin_pos, end_pos),
71 [&stream] (auto && ch) { stream << (get<0>(ch) == get<1>(ch) ? '|' : ' '); });
72
73 // write next sequence
74 stream << '\n' << std::setw(8) << "";
75 std::ranges::for_each(aligned_seq | views::slice(begin_pos, end_pos) | views::to_char,
76 [&stream] (char ch) { stream << ch; });
77 };
78 (stream_f(get<idx>(align), get<idx + 1>(align)), ...);
79 stream << '\n';
80 }
81}
82} // namespace seqan3::detail
83
84namespace seqan3
85{
96template <typename char_t, typename alignment_t>
98 requires (detail::debug_streamable_tuple<alignment_t> &&
99 detail::all_model_aligned_seq<detail::tuple_type_list_t<std::remove_cvref_t<alignment_t>>>)
101inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_t && alignment)
102{
103 constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<alignment_t>>;
104
105 static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");
106
107 detail::stream_alignment(stream, alignment, std::make_index_sequence<sequence_count - 1>{});
108 return stream;
109}
110
111} // namespace seqan
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:78
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition: to_char.hpp:63
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:183
constexpr auto zip
A zip view.
Definition: zip.hpp:29
Whether a type behaves like a tuple.
T min(T... args)
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: configuration.hpp:429
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.