Loading...
Searching...
No Matches
alignment_score_matrix_one_column_banded.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 <cassert>
#include <iterator>
#include <ranges>
#include <span>
#include <seqan3/alignment/configuration/align_config_band.hpp>
#include <seqan3/alignment/matrix/detail/alignment_matrix_column_major_range_base.hpp>
#include <seqan3/alignment/matrix/detail/alignment_score_matrix_one_column_base.hpp>
#include <seqan3/alignment/matrix/detail/alignment_score_matrix_proxy.hpp>
namespace seqan3::detail
{
template <typename score_t>
class alignment_score_matrix_one_column_banded :
protected alignment_score_matrix_one_column_base<score_t>,
public alignment_matrix_column_major_range_base<alignment_score_matrix_one_column_banded<score_t>>
{
private:
using matrix_base_t = alignment_score_matrix_one_column_base<score_t>;
using range_base_t = alignment_matrix_column_major_range_base<alignment_score_matrix_one_column_banded<score_t>>;
friend range_base_t;
protected:
using typename matrix_base_t::element_type;
using typename range_base_t::alignment_column_type;
using column_data_view_type = std::span<element_type>;
public:
using matrix_base_t::num_cols;
using matrix_base_t::num_rows;
using value_type = alignment_score_matrix_proxy<score_t>;
using reference = value_type;
using iterator = typename range_base_t::iterator;
using sentinel = typename range_base_t::sentinel;
using typename matrix_base_t::size_type;
using typename matrix_base_t::underlying_type;
constexpr alignment_score_matrix_one_column_banded() = default;
constexpr alignment_score_matrix_one_column_banded(alignment_score_matrix_one_column_banded const &) = default;
constexpr alignment_score_matrix_one_column_banded(alignment_score_matrix_one_column_banded &&) = default;
constexpr alignment_score_matrix_one_column_banded &
operator=(alignment_score_matrix_one_column_banded const &) = default;
constexpr alignment_score_matrix_one_column_banded &
operator=(alignment_score_matrix_one_column_banded &&) = default;
~alignment_score_matrix_one_column_banded() = default;
template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
constexpr alignment_score_matrix_one_column_banded(first_sequence_t && first,
second_sequence_t && second,
align_cfg::band_fixed_size const & band,
score_t const initial_value = score_t{})
{
matrix_base_t::num_cols = static_cast<size_type>(std::ranges::distance(first) + 1);
matrix_base_t::num_rows = static_cast<size_type>(std::ranges::distance(second) + 1);
band_col_index = std::min<int32_t>(std::max<int32_t>(band.upper_diagonal, 0), matrix_base_t::num_cols - 1);
band_row_index =
std::min<int32_t>(std::abs(std::min<int32_t>(band.lower_diagonal, 0)), matrix_base_t::num_rows - 1);
band_size = band_col_index + band_row_index + 1;
// Reserve one more cell to deal with last cell in the banded column which needs only the diagonal and up cell.
matrix_base_t::pool.resize(band_size + 1, element_type{initial_value, initial_value});
}
int32_t band_col_index{};
int32_t band_row_index{};
int32_t band_size{};
private:
constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
{
int32_t slice_begin = std::max<int32_t>(0, band_col_index - column_index);
int32_t row_end_index = column_index - band_col_index + band_size;
int32_t slice_end = band_size - std::max<int32_t>(row_end_index - matrix_base_t::num_rows, 0);
assert(row_end_index >= 0);
assert(slice_begin >= 0);
assert(slice_end > 0);
assert(slice_begin < slice_end);
return alignment_column_type{*this,
column_data_view_type{std::addressof(matrix_base_t::pool[slice_begin]),
std::addressof(matrix_base_t::pool[slice_end])}};
}
template <std::random_access_iterator iter_t>
constexpr value_type make_proxy(iter_t host_iter) noexcept
{
return {std::get<0>(*host_iter), // current
std::get<0>(matrix_base_t::cache), // last diagonal
std::get<1>(*(host_iter + 1)), // last left (read)
std::get<1>(*(host_iter)), // next left (write)
std::get<1>(matrix_base_t::cache)}; // last up
}
template <std::random_access_iterator iter_t>
constexpr void on_column_iterator_creation(iter_t host_iter) noexcept
{
// Cache the last diagonal value.
std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
}
template <std::random_access_iterator iter_t>
constexpr void before_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
{
// noop.
}
template <std::random_access_iterator iter_t>
constexpr void after_column_iterator_increment(iter_t host_iter) noexcept
{
// Cache the last diagonal value.
std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
}
};
} // namespace seqan3::detail
std::addressof
T addressof(T... args)
align_config_band.hpp
Provides seqan3::detail::align_config_band.
alignment_matrix_column_major_range_base.hpp
Provides seqan3::detail::alignment_matrix_column_major_range_base.
alignment_score_matrix_one_column_base.hpp
Provides seqan3::detail::alignment_score_matrix_one_column_base.
alignment_score_matrix_proxy.hpp
Provides seqan3::detail::alignment_score_matrix_proxy.
cassert
iterator
std::max
T max(T... args)
std::min
T min(T... args)
Hide me