SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
gap_scheme.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <stdexcept>
16 
20 #include <seqan3/std/concepts>
21 
22 namespace seqan3
23 {
24 
25 // ------------------------------------------------------------------
26 // seqan3::gap_score
27 // ------------------------------------------------------------------
28 
36 template <arithmetic score_type>
37 struct 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 
47 template <arithmetic score_type>
51 
52 // ------------------------------------------------------------------
53 // seqan3::gap_open_score
54 // ------------------------------------------------------------------
55 
63 template <arithmetic score_type>
64 struct gap_open_score : detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>
65 {
66  using detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>::strong_type;
67 };
68 
74 template <arithmetic score_type>
78 
79 // ------------------------------------------------------------------
80 // seqan3::gap_scheme
81 // ------------------------------------------------------------------
82 
88 template <arithmetic score_t = int8_t>
90 {
91 public:
92 
96  using score_type = score_t;
99 
103  constexpr gap_scheme() noexcept = default;
104  constexpr gap_scheme(gap_scheme const &) noexcept = default;
105  constexpr gap_scheme(gap_scheme &&) noexcept = default;
106  constexpr gap_scheme & operator=(gap_scheme const &) noexcept = default;
107  constexpr gap_scheme & operator=(gap_scheme &&) noexcept = default;
108  ~gap_scheme() noexcept = default;
109 
113  template <arithmetic score_arg_t>
114  constexpr gap_scheme(gap_score<score_arg_t> const g, gap_open_score<score_arg_t> const go)
115  {
116  set_affine(g, go);
117  }
118 
122  template <arithmetic score_arg_t>
124  {
125  set_linear(g);
126  }
128 
146  template <arithmetic score_arg_t>
148  {
149  std::conditional_t<std::integral<score_t>, int64_t, double> i_g = static_cast<score_arg_t>(g);
150  std::conditional_t<std::integral<score_t>, int64_t, double> i_go = static_cast<score_arg_t>(go);
153  {
154  throw std::invalid_argument{"You passed a score value to set_affine/set_linear that is out of range of the "
155  "scoring scheme's underlying type. Define your scoring scheme with a larger "
156  "template parameter or down-cast your score value beforehand to prevent "
157  "this exception."};
158  }
159 
160  gap = static_cast<score_arg_t>(g);
161  gap_open = static_cast<score_arg_t>(go);
162  }
163 
174  template <arithmetic score_arg_t>
175  constexpr void set_linear(gap_score<score_arg_t> const g)
176  {
177  set_affine(g, gap_open_score<score_arg_t>{0});
178  }
180 
186  constexpr score_t & get_gap_score() noexcept
187  {
188  return gap;
189  }
190 
192  constexpr score_t get_gap_score() const noexcept
193  {
194  return gap;
195  }
196 
199  constexpr score_t & get_gap_open_score() noexcept
200  {
201  return gap_open;
202  }
203 
205  constexpr score_t get_gap_open_score() const noexcept
206  {
207  return gap_open;
208  }
209 
214  constexpr ptrdiff_t score(size_t const number_of_consecutive_gaps) const noexcept
215  {
216  return (gap_open * (number_of_consecutive_gaps ? 1 : 0)) + number_of_consecutive_gaps * gap;
217  }
219 
224  constexpr bool operator==(gap_scheme const & rhs) const noexcept
226  {
227  return std::tie(gap, gap_open) == std::tie(rhs.gap, rhs.gap_open);
228  }
229 
231  constexpr bool operator!=(gap_scheme const & rhs) const noexcept
232  {
233  return !(*this == rhs);
234  }
236 
244  template <cereal_archive archive_t>
245  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
246  {
247  archive(gap);
248  archive(gap_open);
249  }
251 
252 private:
254  score_t gap = -1;
256  score_t gap_open = 0;
257 };
258 
264 // avoid deprecation warning of seqan3::gap_sheme
265 #pragma GCC diagnostic push
266 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
267 
270 
275 template <floating_point score_arg_type>
277 
282 template <floating_point score_arg_type>
284 
289 template <arithmetic score_arg_type>
291 
296 template <arithmetic score_arg_type>
299 
300 #pragma GCC diagnostic pop
301 } // namespace seqan3
seqan3::gap_scheme::score
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:214
seqan3::gap
The alphabet of a gap character '-'.
Definition: gap.hpp:37
seqan3::gap_scheme::get_gap_score
constexpr score_t get_gap_score() const noexcept
A strong type of underlying type score_type that represents the score of any character against a gap ...
Definition: gap_scheme.hpp:192
seqan3::gap_scheme::operator!=
constexpr bool operator!=(gap_scheme const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition: gap_scheme.hpp:231
seqan3::gap_scheme::set_linear
constexpr void set_linear(gap_score< score_arg_t > const g)
Set the Linear gap costs model.
Definition: gap_scheme.hpp:175
seqan3::gap_scheme::gap_scheme
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:123
seqan3::gap_scheme
A scheme for representing and computing scores against gap characters.
Definition: gap_scheme.hpp:90
strong_type.hpp
Provides basic data structure for strong types.
seqan3::gap_scheme::get_gap_open_score
constexpr score_t get_gap_open_score() const noexcept
A strong type of underlying type score_type that represents an additional score (usually negative) th...
Definition: gap_scheme.hpp:205
seqan3::gap_open_score
A strong type of underlying type score_type that represents an additional score (usually negative) th...
Definition: gap_scheme.hpp:65
seqan3::gap_scheme::gap_scheme
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_...
seqan3::gap_score::gap_score
gap_score(score_type) -> gap_score< score_type >
Deduce the score type from the given argument.
seqan3::gap_score
A strong type of underlying type score_type that represents the score of any character against a gap ...
Definition: gap_scheme.hpp:38
seqan3::gap_scheme::gap_scheme
gap_scheme() -> gap_scheme< int8_t >
Default constructed objects deduce to int8_t.
concepts
The Concepts library.
seqan3::gap_scheme::gap_scheme
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...
SEQAN3_DEPRECATED_310
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:194
std::tie
T tie(T... args)
stdexcept
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
seqan3::gap_scheme::gap_scheme
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...
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
std::invalid_argument
seqan3::gap_scheme::get_gap_open_score
constexpr score_t & get_gap_open_score() noexcept
Return the gap open score.
Definition: gap_scheme.hpp:199
seqan3::gap_open_score::gap_open_score
gap_open_score(score_type) -> gap_open_score< score_type >
Deduce the score type from the given argument.
seqan3::gap_scheme::gap_scheme
constexpr gap_scheme() noexcept=default
Defaulted.
cereal.hpp
Adaptions of concepts from the Cereal library.
arithmetic
A type that satisfies std::is_arithmetic_v<t>.
seqan3::gap_scheme::score_type
score_t score_type
The template parameter exposed as member type.
Definition: gap_scheme.hpp:97
std::conditional_t
std::numeric_limits::max
T max(T... args)
seqan3::gap_scheme::get_gap_score
constexpr score_t & get_gap_score() noexcept
Return the gap score.
Definition: gap_scheme.hpp:186
seqan3::views::convert
auto const convert
A view that converts each element in the input range (implicitly or via static_cast).
Definition: convert.hpp:71
std::numeric_limits
seqan3::gap_scheme::set_affine
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:147
seqan3::gap_scheme::gap_scheme
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_...