SeqAn3  3.0.1
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 
18 #include <seqan3/std/concepts>
19 
20 namespace seqan3
21 {
22 
23 // ------------------------------------------------------------------
24 // seqan3::gap_score
25 // ------------------------------------------------------------------
26 
33 template <arithmetic score_type>
34 struct gap_score : detail::strong_type<score_type, gap_score<score_type>, detail::strong_type_skill::convert>
35 {
36  using detail::strong_type<score_type, gap_score<score_type>, detail::strong_type_skill::convert>::strong_type;
37 };
38 
44 template <arithmetic score_type>
46 gap_score(score_type) -> gap_score<score_type>;
48 
49 // ------------------------------------------------------------------
50 // seqan3::gap_open_score
51 // ------------------------------------------------------------------
52 
59 template <arithmetic score_type>
60 struct gap_open_score : detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>
61 {
62  using detail::strong_type<score_type, gap_open_score<score_type>, detail::strong_type_skill::convert>::strong_type;
63 };
64 
70 template <arithmetic score_type>
74 
75 // ------------------------------------------------------------------
76 // seqan3::gap_scheme
77 // ------------------------------------------------------------------
78 
83 template <arithmetic score_t = int8_t>
85 {
86 public:
87 
91  using score_type = score_t;
94 
98  constexpr gap_scheme() noexcept = default;
99  constexpr gap_scheme(gap_scheme const &) noexcept = default;
100  constexpr gap_scheme(gap_scheme &&) noexcept = default;
101  constexpr gap_scheme & operator=(gap_scheme const &) noexcept = default;
102  constexpr gap_scheme & operator=(gap_scheme &&) noexcept = default;
103  ~gap_scheme() noexcept = default;
104 
108  template <arithmetic score_arg_t>
110  {
111  set_affine(g, go);
112  }
113 
117  template <arithmetic score_arg_t>
119  {
120  set_linear(g);
121  }
123 
141  template <arithmetic score_arg_t>
143  {
144  std::conditional_t<std::integral<score_t>, int64_t, double> i_g = static_cast<score_arg_t>(g);
145  std::conditional_t<std::integral<score_t>, int64_t, double> i_go = static_cast<score_arg_t>(go);
148  {
149  throw std::invalid_argument{"You passed a score value to set_affine/set_linear that is out of range of the "
150  "scoring scheme's underlying type. Define your scoring scheme with a larger "
151  "template parameter or down-cast your score value beforehand to prevent "
152  "this exception."};
153  }
154 
155  gap = static_cast<score_arg_t>(g);
156  gap_open = static_cast<score_arg_t>(go);
157  }
158 
169  template <arithmetic score_arg_t>
170  constexpr void set_linear(gap_score<score_arg_t> const g)
171  {
173  }
175 
181  constexpr score_t & get_gap_score() noexcept
182  {
183  return gap;
184  }
185 
187  constexpr score_t get_gap_score() const noexcept
188  {
189  return gap;
190  }
191 
194  constexpr score_t & get_gap_open_score() noexcept
195  {
196  return gap_open;
197  }
198 
200  constexpr score_t get_gap_open_score() const noexcept
201  {
202  return gap_open;
203  }
204 
209  constexpr ptrdiff_t score(size_t const number_of_consecutive_gaps) const noexcept
210  {
211  return (gap_open * (number_of_consecutive_gaps ? 1 : 0)) + number_of_consecutive_gaps * gap;
212  }
214 
219  constexpr bool operator==(gap_scheme const & rhs) const noexcept
221  {
222  return std::tie(gap, gap_open) == std::tie(rhs.gap, rhs.gap_open);
223  }
224 
226  constexpr bool operator!=(gap_scheme const & rhs) const noexcept
227  {
228  return !(*this == rhs);
229  }
231 
239  template <cereal_archive archive_t>
240  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
241  {
242  archive(gap);
243  archive(gap_open);
244  }
246 
247 private:
249  score_t gap = -1;
251  score_t gap_open = 0;
252 };
253 
259 gap_scheme() -> gap_scheme<int8_t>;
261 
266 template <floating_point score_arg_type>
267 gap_scheme(gap_score<score_arg_type>, gap_open_score<score_arg_type>) -> gap_scheme<float>;
268 
273 template <floating_point score_arg_type>
274 gap_scheme(gap_score<score_arg_type>) -> gap_scheme<float>;
275 
280 template <arithmetic score_arg_type>
281 gap_scheme(gap_score<score_arg_type>, gap_open_score<score_arg_type>) -> gap_scheme<int8_t>;
282 
287 template <arithmetic score_arg_type>
288 gap_scheme(gap_score<score_arg_type>) -> gap_scheme<int8_t>;
290 
291 } // 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:209
seqan3::gap
The alphabet of a gap character '-'.
Definition: gap.hpp:36
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:187
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:226
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:170
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:118
seqan3::gap_scheme
A scheme for representing and computing scores against gap characters.
Definition: gap_scheme.hpp:84
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:200
seqan3::gap_open_score
A strong type of underlying type score_type that represents an additional score (usually negative) th...
Definition: gap_scheme.hpp:60
seqan3::gap_scheme::gap_scheme
constexpr gap_scheme(gap_score< score_arg_t > const g, gap_open_score< score_arg_t > const go)
Constructor for the Affine gap costs model (delegates to set_affine()).
Definition: gap_scheme.hpp:109
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:34
concepts
The Concepts library.
std::tie
T tie(T... args)
seqan3::gap_scheme::operator=
constexpr gap_scheme & operator=(gap_scheme const &) noexcept=default
Defaulted.
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
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:194
seqan3::gap_scheme::gap_scheme
constexpr gap_scheme() noexcept=default
Defaulted.
cereal.hpp
Adaptions of concepts from the Cereal library.
seqan3::gap_scheme::operator==
constexpr bool operator==(gap_scheme const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition: gap_scheme.hpp:220
seqan3::gap_scheme::~gap_scheme
~gap_scheme() noexcept=default
Defaulted.
seqan3::gap_scheme::score_type
score_t score_type
The template parameter exposed as member type.
Definition: gap_scheme.hpp:92
std::conditional_t
seqan3::gap_scheme::get_gap_score
constexpr score_t & get_gap_score() noexcept
Return the gap score.
Definition: gap_scheme.hpp:181
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:142