Loading...
Searching...
No Matches
debug_stream_alignment.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <iomanip>
#include <tuple>
#include <seqan3/alignment/aligned_sequence/aligned_sequence_concept.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream/tuple.hpp>
#include <seqan3/utility/tuple/concept.hpp>
#include <seqan3/utility/views/slice.hpp>
#include <seqan3/utility/views/zip.hpp>
namespace seqan3::detail
{
template <typename char_t, tuple_like alignment_t, size_t... idx>
void stream_alignment(debug_stream_type<char_t> & stream,
alignment_t const & align,
std::index_sequence<idx...> const & /**/)
{
using std::get;
size_t const alignment_size = get<0>(align).size();
// split alignment into blocks of length 50 and loop over parts
for (size_t begin_pos = 0; begin_pos < alignment_size; begin_pos += 50)
{
size_t const end_pos = std::min(begin_pos + 50, alignment_size);
// write header line
if (begin_pos != 0)
stream << '\n';
stream << std::setw(7) << begin_pos << ' ';
for (size_t pos = begin_pos + 1; pos <= end_pos; ++pos)
{
if (pos % 10 == 0)
stream << ':';
else if (pos % 5 == 0)
stream << '.';
else
stream << ' ';
}
// write first sequence
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(get<0>(align) | views::slice(begin_pos, end_pos) | views::to_char,
[&stream](char ch)
{
stream << ch;
});
auto stream_f = [&](auto const & previous_seq, auto const & aligned_seq)
{
// write alignment bars
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(views::zip(previous_seq, aligned_seq) | views::slice(begin_pos, end_pos),
[&stream](auto && ch)
{
stream << (get<0>(ch) == get<1>(ch) ? '|' : ' ');
});
// write next sequence
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(aligned_seq | views::slice(begin_pos, end_pos) | views::to_char,
[&stream](char ch)
{
stream << ch;
});
};
(stream_f(get<idx>(align), get<idx + 1>(align)), ...);
stream << '\n';
}
}
} // namespace seqan3::detail
namespace seqan3
{
template <typename alignment_t>
requires tuple_like<alignment_t> && detail::all_model_aligned_seq<detail::tuple_type_list_t<alignment_t>>
struct alignment_printer<alignment_t>
{
template <typename stream_t, typename arg_t>
constexpr void operator()(stream_t & stream, arg_t && arg) const
{
constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<arg_t>>;
static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");
detail::stream_alignment(stream, std::forward<arg_t>(arg), std::make_index_sequence<sequence_count - 1>{});
}
};
} // namespace seqan3
aligned_sequence_concept.hpp
Includes the aligned_sequence and the related insert_gap and erase_gap functions to enable stl contai...
std::forward
T forward(T... args)
seqan3::views::to_char
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:60
seqan3::views::zip
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
seqan3::views::slice
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:137
std::make_index_sequence
iomanip
std::min
T min(T... args)
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
seqan3::get
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:412
std::setw
T setw(T... args)
slice.hpp
Provides seqan3::views::slice.
seqan3::alignment_printer< alignment_t >::operator()
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
seqan3::alignment_printer
Definition default_printer.hpp:29
to_char.hpp
Provides seqan3::views::to_char.
tuple.hpp
Provides seqan3::debug_stream and related types.
tuple
std::tuple_size_v
T tuple_size_v
concept.hpp
Provides seqan3::tuple_like.
zip.hpp
Provides seqan3::views::zip.
Hide me