Loading...
Searching...
No Matches
combined_score_and_trace_matrix.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 <ranges>
#include <seqan3/alignment/matrix/detail/affine_cell_proxy.hpp>
#include <seqan3/alignment/matrix/detail/matrix_coordinate.hpp>
#include <seqan3/core/range/type_traits.hpp>
#include <seqan3/utility/concept.hpp>
#include <seqan3/utility/views/zip.hpp>
namespace seqan3::detail
{
template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
&& std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
class combined_score_and_trace_matrix
{
private:
using score_type = std::remove_cvref_t<std::tuple_element_t<0, range_innermost_value_t<score_matrix_t>>>;
class iterator;
class sentinel;
score_matrix_t score_matrix{};
trace_matrix_t trace_matrix{};
public:
combined_score_and_trace_matrix() = default;
combined_score_and_trace_matrix(combined_score_and_trace_matrix const &) = default;
combined_score_and_trace_matrix(combined_score_and_trace_matrix &&) = default;
combined_score_and_trace_matrix & operator=(combined_score_and_trace_matrix const &) = default;
combined_score_and_trace_matrix & operator=(combined_score_and_trace_matrix &&) = default;
~combined_score_and_trace_matrix() = default;
template <std::integral column_index_t, std::integral row_index_t>
void resize(column_index_type<column_index_t> const column_count,
row_index_type<row_index_t> const row_count,
score_type const initial_score = score_type{})
{
score_matrix_t tmp_score_matrix{};
tmp_score_matrix.resize(column_count, row_count, initial_score);
trace_matrix_t tmp_trace_matrix{};
tmp_trace_matrix.resize(column_count, row_count);
score_matrix = std::move(tmp_score_matrix);
trace_matrix = std::move(tmp_trace_matrix);
}
iterator begin()
{
return iterator{score_matrix.begin(), trace_matrix.begin()};
}
iterator begin() const = delete;
sentinel end()
{
return sentinel{score_matrix.end()};
}
sentinel end() const = delete;
auto trace_path(matrix_coordinate const & from_coordinate) const
{
return trace_matrix.trace_path(from_coordinate);
}
};
template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
&& std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
class combined_score_and_trace_matrix<score_matrix_t, trace_matrix_t>::iterator
{
private:
using score_matrix_reference_type = std::ranges::range_reference_t<score_matrix_t>;
using trace_matrix_reference_type = std::ranges::range_reference_t<trace_matrix_t>;
static_assert(std::ranges::viewable_range<score_matrix_reference_type>);
static_assert(std::ranges::viewable_range<trace_matrix_reference_type>);
using combined_column_type =
decltype(views::zip(std::declval<score_matrix_reference_type>(), std::declval<trace_matrix_reference_type>()));
using score_matrix_iter_type = std::ranges::iterator_t<score_matrix_t>;
using trace_matrix_iter_type = std::ranges::iterator_t<trace_matrix_t>;
// Befriend the base class.
template <std::ranges::input_range other_score_matrix_t, std::ranges::input_range other_trace_matrix_t>
requires (std::ranges::input_range<std::ranges::range_reference_t<other_score_matrix_t>>
&& std::ranges::input_range<std::ranges::range_reference_t<other_trace_matrix_t>>)
friend class combined_score_and_trace_matrix;
static constexpr auto transform_to_combined_matrix_cell = std::views::transform(
[](auto && tpl) -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
{
using fwd_tuple_t = decltype(tpl);
return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
});
score_matrix_iter_type score_matrix_it;
trace_matrix_iter_type trace_matrix_it;
public:
using value_type = decltype(std::declval<combined_column_type>() | transform_to_combined_matrix_cell);
using reference = value_type;
using pointer = void;
using difference_type = std::ptrdiff_t;
using iterator_concept = std::input_iterator_tag;
iterator() = default;
iterator(iterator const &) = default;
iterator(iterator &&) = default;
iterator & operator=(iterator const &) = default;
iterator & operator=(iterator &&) = default;
~iterator() = default;
explicit iterator(score_matrix_iter_type score_matrix_it, trace_matrix_iter_type trace_matrix_it) noexcept :
score_matrix_it{std::move(score_matrix_it)},
trace_matrix_it{std::move(trace_matrix_it)}
{}
reference operator*() const
{
return views::zip(*score_matrix_it, *trace_matrix_it) | transform_to_combined_matrix_cell;
}
iterator & operator++()
{
++score_matrix_it;
++trace_matrix_it;
return *this;
}
void operator++(int)
{
++(*this);
}
};
template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
&& std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
class combined_score_and_trace_matrix<score_matrix_t, trace_matrix_t>::sentinel
{
private:
using score_matrix_sentinel_type = std::ranges::sentinel_t<score_matrix_t>;
score_matrix_sentinel_type score_matrix_sentinel{};
public:
sentinel() = default;
sentinel(sentinel const &) = default;
sentinel(sentinel &&) = default;
sentinel & operator=(sentinel const &) = default;
sentinel & operator=(sentinel &&) = default;
~sentinel() = default;
explicit sentinel(score_matrix_sentinel_type score_matrix_sentinel) noexcept :
score_matrix_sentinel{std::move(score_matrix_sentinel)}
{}
friend bool operator==(iterator const & lhs, sentinel const & rhs) noexcept
{
return rhs.equal(lhs);
}
friend bool operator==(sentinel const & lhs, iterator const & rhs) noexcept
{
return rhs == lhs;
}
friend bool operator!=(iterator const & lhs, sentinel const & rhs) noexcept
{
return !(lhs == rhs);
}
friend bool operator!=(sentinel const & lhs, iterator const & rhs) noexcept
{
return !(lhs == rhs);
}
private:
constexpr bool equal(iterator const & iter) const noexcept
{
return iter.score_matrix_it == score_matrix_sentinel;
}
};
} // namespace seqan3::detail
affine_cell_proxy.hpp
Provides seqan3::detail::affine_cell_proxy.
std::begin
T begin(T... args)
type_traits.hpp
Provides various transformation traits used by the range module.
std::declval
T declval(T... args)
std::end
T end(T... args)
std::equal
T equal(T... args)
std::forward
T forward(T... args)
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
matrix_coordinate.hpp
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
concept.hpp
Provides concepts that do not have equivalents in C++20.
zip.hpp
Provides seqan3::views::zip.
Hide me