SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
gap_scheme.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 <seqan3/std/concepts>
16 #include <stdexcept>
17 
21 
22 namespace seqan3
23 {
24 
25 // ------------------------------------------------------------------
26 // seqan3::gap_score
27 // ------------------------------------------------------------------
28 
36 template <arithmetic score_type>
37 struct SEQAN3_DEPRECATED_310 gap_score : detail::strong_type<score_type, gap_score<score_type>, detail::strong_type_skill::convert>
38 {
39  using detail::strong_type<score_type, gap_score<score_type>, detail::strong_type_skill::convert>::strong_type;
40 };
41 
48 template <arithmetic score_type>
51 
52 // ------------------------------------------------------------------
53 // seqan3::gap_open_score
54 // ------------------------------------------------------------------
55 
64 template <arithmetic score_type>
65 struct SEQAN3_DEPRECATED_310 gap_open_score : detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>
66 {
67  using detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>::strong_type;
68 };
69 
76 template <arithmetic score_type>
79 
80 // ------------------------------------------------------------------
81 // seqan3::gap_scheme
82 // ------------------------------------------------------------------
83 
90 template <arithmetic score_t = int8_t>
92 {
93 public:
94 
99  using score_type = score_t;
101 
105  constexpr gap_scheme() noexcept = default;
106  constexpr gap_scheme(gap_scheme const &) noexcept = default;
107  constexpr gap_scheme(gap_scheme &&) noexcept = default;
108  constexpr gap_scheme & operator=(gap_scheme const &) noexcept = default;
109  constexpr gap_scheme & operator=(gap_scheme &&) noexcept = default;
110  ~gap_scheme() noexcept = default;
111 
115  template <arithmetic score_arg_t>
116  constexpr gap_scheme(gap_score<score_arg_t> const g, gap_open_score<score_arg_t> const go)
117  {
118  set_affine(g, go);
119  }
120 
124  template <arithmetic score_arg_t>
126  {
127  set_linear(g);
128  }
130 
148  template <arithmetic score_arg_t>
150  {
151  std::conditional_t<std::integral<score_t>, int64_t, double> i_g = static_cast<score_arg_t>(g);
152  std::conditional_t<std::integral<score_t>, int64_t, double> i_go = static_cast<score_arg_t>(go);
155  {
156  throw std::invalid_argument{"You passed a score value to set_affine/set_linear that is out of range of the "
157  "scoring scheme's underlying type. Define your scoring scheme with a larger "
158  "template parameter or down-cast your score value beforehand to prevent "
159  "this exception."};
160  }
161 
162  gap = static_cast<score_arg_t>(g);
163  gap_open = static_cast<score_arg_t>(go);
164  }
165 
176  template <arithmetic score_arg_t>
177  constexpr void set_linear(gap_score<score_arg_t> const g)
178  {
179  set_affine(g, gap_open_score<score_arg_t>{0});
180  }
182 
188  constexpr score_t & get_gap_score() noexcept
189  {
190  return gap;
191  }
192 
194  constexpr score_t get_gap_score() const noexcept
195  {
196  return gap;
197  }
198 
201  constexpr score_t & get_gap_open_score() noexcept
202  {
203  return gap_open;
204  }
205 
207  constexpr score_t get_gap_open_score() const noexcept
208  {
209  return gap_open;
210  }
211 
216  constexpr ptrdiff_t score(size_t const number_of_consecutive_gaps) const noexcept
217  {
218  return (gap_open * (number_of_consecutive_gaps ? 1 : 0)) + number_of_consecutive_gaps * gap;
219  }
221 
227  constexpr bool operator==(gap_scheme const & rhs) const noexcept
228  {
229  return std::tie(gap, gap_open) == std::tie(rhs.gap, rhs.gap_open);
230  }
231 
233  constexpr bool operator!=(gap_scheme const & rhs) const noexcept
234  {
235  return !(*this == rhs);
236  }
238 
246  template <cereal_archive archive_t>
247  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
248  {
249  archive(gap);
250  archive(gap_open);
251  }
253 
254 private:
256  score_t gap = -1;
258  score_t gap_open = 0;
259 };
260 
266 // avoid deprecation warning of seqan3::gap_sheme
267 #pragma GCC diagnostic push
268 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
269 
272 
277 template <floating_point score_arg_type>
279 
284 template <floating_point score_arg_type>
286 
291 template <arithmetic score_arg_type>
293 
298 template <arithmetic score_arg_type>
301 
302 #pragma GCC diagnostic pop
303 } // namespace seqan3
304 
306  "This header and its provided functions are deprecated and will be removed in SeqAn-3.1.0.")
Adaptions of concepts from the Cereal library.
[DEPRECATED] A scheme for representing and computing scores against gap characters.
Definition: gap_scheme.hpp:92
score_t score_type
The template parameter exposed as member type.
Definition: gap_scheme.hpp:99
constexpr score_t get_gap_score() const noexcept
[DEPRECATED] A strong type of underlying type score_type that represents the score of any character a...
Definition: gap_scheme.hpp:194
gap_scheme(gap_score< score_arg_type >) -> gap_scheme< int8_t >
Attention: This guide does not actually deduce from the underlying type, but always defaults to int8_...
constexpr score_t & get_gap_open_score() noexcept
Return the gap open score.
Definition: gap_scheme.hpp:201
constexpr bool operator==(gap_scheme const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition: gap_scheme.hpp:227
constexpr score_t & get_gap_score() noexcept
Return the gap score.
Definition: gap_scheme.hpp:188
constexpr score_t get_gap_open_score() const noexcept
[DEPRECATED] A strong type of underlying type score_type that represents an additional score (usually...
Definition: gap_scheme.hpp:207
constexpr void set_affine(gap_score< score_arg_t > const g, gap_open_score< score_arg_t > const go)
Set the Affine gap costs model.
Definition: gap_scheme.hpp:149
gap_scheme(gap_score< score_arg_type >) -> gap_scheme< float >
Attention: This guide does not actually deduce from the underlying type, but always defaults to float...
gap_scheme() -> gap_scheme< int8_t >
Default constructed objects deduce to int8_t.
constexpr gap_scheme(gap_score< score_arg_t > const g)
Constructor for the Linear gap costs model (delegates to set_linear()).
Definition: gap_scheme.hpp:125
gap_scheme(gap_score< score_arg_type >, gap_open_score< score_arg_type >) -> gap_scheme< int8_t >
Attention: This guide does not actually deduce from the underlying type, but always defaults to int8_...
gap_scheme(gap_score< score_arg_type >, gap_open_score< score_arg_type >) -> gap_scheme< float >
Attention: This guide does not actually deduce from the underlying type, but always defaults to float...
constexpr gap_scheme() noexcept=default
Defaulted.
constexpr void set_linear(gap_score< score_arg_t > const g)
Set the Linear gap costs model.
Definition: gap_scheme.hpp:177
constexpr ptrdiff_t score(size_t const number_of_consecutive_gaps) const noexcept
Compute the score of a stretch of gap characters.
Definition: gap_scheme.hpp:216
constexpr bool operator!=(gap_scheme const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition: gap_scheme.hpp:233
The alphabet of a gap character '-'.
Definition: gap.hpp:39
The Concepts library.
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
A type that satisfies std::is_arithmetic_v<t>.
T max(T... args)
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:203
#define SEQAN3_DEPRECATED_HEADER(message)
Deprecation message for deprecated header.
Definition: platform.hpp:213
Provides basic data structure for strong types.
[DEPRECATED] A strong type of underlying type score_type that represents an additional score (usually...
Definition: gap_scheme.hpp:66
gap_open_score(score_type) -> gap_open_score< score_type >
Deduce the score type from the given argument.
[DEPRECATED] A strong type of underlying type score_type that represents the score of any character a...
Definition: gap_scheme.hpp:38
gap_score(score_type) -> gap_score< score_type >
Deduce the score type from the given argument.
T tie(T... args)