SeqAn3 3.3.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// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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 <cassert>
16#include <iterator>
17#include <ranges>
18#include <span>
19
24
25namespace seqan3::detail
26{
27
41template <typename score_t>
44 public alignment_matrix_column_major_range_base<alignment_score_matrix_one_column_banded<score_t>>
45{
46private:
51
54
55protected:
56 using typename matrix_base_t::element_type;
57 using typename range_base_t::alignment_column_type;
60
61public:
64
76 using typename matrix_base_t::size_type;
77 using typename matrix_base_t::underlying_type;
79
97
112 template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
113 constexpr alignment_score_matrix_one_column_banded(first_sequence_t && first,
114 second_sequence_t && second,
116 score_t const initial_value = score_t{})
117 {
118 matrix_base_t::num_cols = static_cast<size_type>(std::ranges::distance(first) + 1);
119 matrix_base_t::num_rows = static_cast<size_type>(std::ranges::distance(second) + 1);
120
121 band_col_index = std::min<int32_t>(std::max<int32_t>(band.upper_diagonal, 0), matrix_base_t::num_cols - 1);
123 std::min<int32_t>(std::abs(std::min<int32_t>(band.lower_diagonal, 0)), matrix_base_t::num_rows - 1);
124
126 // Reserve one more cell to deal with last cell in the banded column which needs only the diagonal and up cell.
127 matrix_base_t::pool.resize(band_size + 1, element_type{initial_value, initial_value});
128 }
130
132 int32_t band_col_index{};
134 int32_t band_row_index{};
136 int32_t band_size{};
137
138private:
140 constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
141 {
142 int32_t slice_begin = std::max<int32_t>(0, band_col_index - column_index);
143 int32_t row_end_index = column_index - band_col_index + band_size;
144 int32_t slice_end = band_size - std::max<int32_t>(row_end_index - matrix_base_t::num_rows, 0);
145
146 assert(row_end_index >= 0);
147 assert(slice_begin >= 0);
148 assert(slice_end > 0);
149 assert(slice_begin < slice_end);
150
151 return alignment_column_type{*this,
154 }
155
157 template <std::random_access_iterator iter_t>
158 constexpr value_type make_proxy(iter_t host_iter) noexcept
159 {
160 return {std::get<0>(*host_iter), // current
161 std::get<0>(matrix_base_t::cache), // last diagonal
162 std::get<1>(*(host_iter + 1)), // last left (read)
163 std::get<1>(*(host_iter)), // next left (write)
164 std::get<1>(matrix_base_t::cache)}; // last up
165 }
166
168 template <std::random_access_iterator iter_t>
169 constexpr void on_column_iterator_creation(iter_t host_iter) noexcept
170 {
171 // Cache the last diagonal value.
172 std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
173 }
174
176 template <std::random_access_iterator iter_t>
177 constexpr void before_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
178 {
179 // noop.
180 }
181
183 template <std::random_access_iterator iter_t>
184 constexpr void after_column_iterator_increment(iter_t host_iter) noexcept
185 {
186 // Cache the last diagonal value.
187 std::get<0>(matrix_base_t::cache) = std::get<0>(*host_iter);
188 }
189};
190
191} // 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:63
Provides a range interface for alignment matrices.
Definition: alignment_matrix_column_major_range_base.hpp:63
std::default_sentinel_t sentinel
The type of sentinel.
Definition: alignment_matrix_column_major_range_base.hpp:480
iterator_type iterator
The type of the iterator.
Definition: alignment_matrix_column_major_range_base.hpp:478
A banded alignment score matrix storing only a single banded column for the computation.
Definition: alignment_score_matrix_one_column_banded.hpp:45
alignment_score_matrix_proxy< score_t > value_type
The proxy type of an alignment matrix.
Definition: alignment_score_matrix_one_column_banded.hpp:69
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:158
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:51
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:140
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:184
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:134
typename range_base_t::sentinel sentinel
The type of sentinel.
Definition: alignment_score_matrix_one_column_banded.hpp:75
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:169
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:113
int32_t band_size
The size of the band.
Definition: alignment_score_matrix_one_column_banded.hpp:136
friend range_base_t
Befriend the range base class.
Definition: alignment_score_matrix_one_column_banded.hpp:53
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:73
std::tuple< underlying_type, underlying_type > element_type
The actual element type.
Definition: alignment_score_matrix_one_column_base.hpp:45
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:177
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:132
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:29
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:37
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:57
pool_type pool
The linearised memory pool storing only one column of the matrix.
Definition: alignment_score_matrix_one_column_base.hpp:55
size_t size_type
The size type.
Definition: alignment_score_matrix_one_column_base.hpp:51
score_t underlying_type
The underlying type of the scores.
Definition: alignment_score_matrix_one_column_base.hpp:43
size_type num_rows
The number of num_rows.
Definition: alignment_score_matrix_one_column_base.hpp:61
std::tuple< underlying_type, underlying_type > element_type
The actual element type.
Definition: alignment_score_matrix_one_column_base.hpp:45
size_type num_cols
The number of columns.
Definition: alignment_score_matrix_one_column_base.hpp:59
A proxy type for a unified access to the score matrix during alignment computation.
Definition: alignment_score_matrix_proxy.hpp:36