SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alignment_score_matrix_one_column_banded.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 <cassert>
13#include <iterator>
14#include <ranges>
15#include <span>
16
21
22namespace seqan3::detail
23{
24
38template <typename score_t>
41 public alignment_matrix_column_major_range_base<alignment_score_matrix_one_column_banded<score_t>>
42{
43private:
48
51
52protected:
54 using typename range_base_t::alignment_column_type;
57
58public:
61
76
94
109 template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
111 second_sequence_t && second,
113 score_t const initial_value = score_t{})
114 {
115 matrix_base_t::num_cols = static_cast<size_type>(std::ranges::distance(first) + 1);
116 matrix_base_t::num_rows = static_cast<size_type>(std::ranges::distance(second) + 1);
117
118 band_col_index = std::min<int32_t>(std::max<int32_t>(band.upper_diagonal, 0), matrix_base_t::num_cols - 1);
120 std::min<int32_t>(std::abs(std::min<int32_t>(band.lower_diagonal, 0)), matrix_base_t::num_rows - 1);
121
123 // Reserve one more cell to deal with last cell in the banded column which needs only the diagonal and up cell.
125 }
127
129 int32_t band_col_index{};
131 int32_t band_row_index{};
133 int32_t band_size{};
134
135private:
137 constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
138 {
139 int32_t slice_begin = std::max<int32_t>(0, band_col_index - column_index);
140 int32_t row_end_index = column_index - band_col_index + band_size;
141 int32_t slice_end = band_size - std::max<int32_t>(row_end_index - matrix_base_t::num_rows, 0);
142
143 assert(row_end_index >= 0);
144 assert(slice_begin >= 0);
145 assert(slice_end > 0);
147
148 return alignment_column_type{*this,
151 }
152
154 template <std::random_access_iterator iter_t>
155 constexpr value_type make_proxy(iter_t host_iter) noexcept
156 {
157 return {std::get<0>(*host_iter), // current
158 std::get<0>(matrix_base_t::cache), // last diagonal
159 std::get<1>(*(host_iter + 1)), // last left (read)
160 std::get<1>(*(host_iter)), // next left (write)
161 std::get<1>(matrix_base_t::cache)}; // last up
162 }
163
165 template <std::random_access_iterator iter_t>
166 constexpr void on_column_iterator_creation(iter_t host_iter) noexcept
167 {
168 // Cache the last diagonal value.
169 std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
170 }
171
173 template <std::random_access_iterator iter_t>
175 {
176 // noop.
177 }
178
180 template <std::random_access_iterator iter_t>
181 constexpr void after_column_iterator_increment(iter_t host_iter) noexcept
182 {
183 // Cache the last diagonal value.
184 std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
185 }
186};
187
188} // namespace seqan3::detail
T addressof(T... args)
Provides seqan3::detail::align_config_band.
Provides seqan3::detail::alignment_matrix_column_major_range_base.
Provides seqan3::detail::alignment_score_matrix_one_column_base.
Provides seqan3::detail::alignment_score_matrix_proxy.
Configuration element for setting a fixed size band.
Definition align_config_band.hpp:60
Allocates uninitialized storage whose memory-alignment is specified by alignment.
Definition aligned_allocator.hpp:74
Provides a range interface for alignment matrices.
Definition alignment_matrix_column_major_range_base.hpp:60
std::default_sentinel_t sentinel
The type of sentinel.
Definition alignment_matrix_column_major_range_base.hpp:477
iterator_type iterator
The type of the iterator.
Definition alignment_matrix_column_major_range_base.hpp:475
A banded alignment score matrix storing only a single banded column for the computation.
Definition alignment_score_matrix_one_column_banded.hpp:42
alignment_score_matrix_proxy< score_t > value_type
The proxy type of an alignment matrix.
Definition alignment_score_matrix_one_column_banded.hpp:66
constexpr value_type make_proxy(iter_t host_iter) noexcept
Creates the proxy value returned when dereferencing the alignment-column-iterator.
Definition alignment_score_matrix_one_column_banded.hpp:155
constexpr alignment_score_matrix_one_column_banded(alignment_score_matrix_one_column_banded const &)=default
Defaulted.
size_t size_type
The size type.
Definition alignment_score_matrix_one_column_base.hpp:48
constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
Returns the current alignment-column at the given column_index.
Definition alignment_score_matrix_one_column_banded.hpp:137
constexpr void after_column_iterator_increment(iter_t host_iter) noexcept
Allows to perform additional steps after incrementing the alignment-column-iterator.
Definition alignment_score_matrix_one_column_banded.hpp:181
int32_t band_row_index
The row index where the lower bound of the band passes through.
Definition alignment_score_matrix_one_column_banded.hpp:131
typename range_base_t::sentinel sentinel
The type of sentinel.
Definition alignment_score_matrix_one_column_banded.hpp:72
constexpr void on_column_iterator_creation(iter_t host_iter) noexcept
Allows additional initialisations when calling begin on an alignment-column.
Definition alignment_score_matrix_one_column_banded.hpp:166
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{})
Construction from two ranges and a band.
Definition alignment_score_matrix_one_column_banded.hpp:110
int32_t band_size
The size of the band.
Definition alignment_score_matrix_one_column_banded.hpp:133
friend range_base_t
Befriend the range base class.
Definition alignment_score_matrix_one_column_banded.hpp:50
constexpr alignment_score_matrix_one_column_banded & operator=(alignment_score_matrix_one_column_banded &&)=default
Defaulted.
constexpr alignment_score_matrix_one_column_banded()=default
Defaulted.
typename range_base_t::iterator iterator
The type of the iterator.
Definition alignment_score_matrix_one_column_banded.hpp:70
std::tuple< underlying_type, underlying_type > element_type
The actual element type.
Definition alignment_score_matrix_one_column_base.hpp:42
constexpr void before_column_iterator_increment(iter_t host_iter) noexcept
Allows to perform additional steps before incrementing the alignment-column-iterator.
Definition alignment_score_matrix_one_column_banded.hpp:174
constexpr alignment_score_matrix_one_column_banded(alignment_score_matrix_one_column_banded &&)=default
Defaulted.
int32_t band_col_index
The column index where the upper bound of the band passes through.
Definition alignment_score_matrix_one_column_banded.hpp:129
constexpr alignment_score_matrix_one_column_banded & operator=(alignment_score_matrix_one_column_banded const &)=default
Defaulted.
@ band
ID for the band option.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T resize(T... args)
A base class for alignment score matrices using only one column to compute the matrix.
Definition alignment_score_matrix_one_column_base.hpp:34
std::array< underlying_type, 3 > cache
Internal cache for the last diagonal and vertical value during the alignment computation.
Definition alignment_score_matrix_one_column_base.hpp:54
pool_type pool
The linearised memory pool storing only one column of the matrix.
Definition alignment_score_matrix_one_column_base.hpp:52
size_t size_type
The size type.
Definition alignment_score_matrix_one_column_base.hpp:48
score_t underlying_type
The underlying type of the scores.
Definition alignment_score_matrix_one_column_base.hpp:40
size_type num_rows
The number of num_rows.
Definition alignment_score_matrix_one_column_base.hpp:58
std::tuple< underlying_type, underlying_type > element_type
The actual element type.
Definition alignment_score_matrix_one_column_base.hpp:42
aligned_allocator< element_type, sizeof(element_type)> allocator_type
The allocator type.
Definition alignment_score_matrix_one_column_base.hpp:44
size_type num_cols
The number of columns.
Definition alignment_score_matrix_one_column_base.hpp:56
Hide me