SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
max_error_rate.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 
14 #pragma once
15 
16 #include <range/v3/numeric/accumulate.hpp>
17 
24 #include <seqan3/std/algorithm>
25 
26 namespace seqan3::search_cfg
27 {
28 
37 template <typename ...errors_t>
39  requires sizeof...(errors_t) <= 4 &&
40  ((detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, total> ||
41  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, substitution> ||
42  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, deletion> ||
43  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, insertion>) && ...)
45 class max_error_rate : public pipeable_config_element<max_error_rate<errors_t...>, std::array<double, 4>>
46 {
47 
50 
52  template <typename ..._errors_t>
53  static constexpr bool check_consistency(_errors_t ...errors)
54  {
55  if constexpr (sizeof...(errors) < 2)
56  {
57  return true;
58  }
59  else
60  {
61  return [] (auto head, auto ...tail) constexpr
62  {
63  using head_t = decltype(head);
64  if constexpr (((head_t::_id != decltype(tail)::_id) && ...))
65  return check_consistency(tail...);
66  else
67  return false;
68  }(errors...);
69  }
70  }
71 
72  static_assert(check_consistency(errors_t{}...),
73  "You may not use the same error specifier more than once.");
74 
75 public:
76 
79  static constexpr detail::search_config_id id{detail::search_config_id::max_error_rate};
80 
82 
86  constexpr max_error_rate() noexcept = default;
87  constexpr max_error_rate(max_error_rate const &) noexcept = default;
88  constexpr max_error_rate(max_error_rate &&) noexcept = default;
89  constexpr max_error_rate & operator=(max_error_rate const &) noexcept = default;
90  constexpr max_error_rate & operator=(max_error_rate &&) noexcept = default;
91  ~max_error_rate() noexcept = default;
92 
117  constexpr max_error_rate(errors_t && ...errors)
119  requires sizeof...(errors_t) > 0
121  : base_t{}
122  {
123  detail::for_each([this](auto e)
124  {
125  base_t::value[remove_cvref_t<decltype(e)>::_id()] = e.get();
126  }, std::forward<errors_t>(errors)...);
127 
128  // check correct values.
129  std::ranges::for_each(base_t::value, [](auto error_elem)
130  {
131  if (0.0 > error_elem || error_elem > 1.0)
132  throw std::invalid_argument("Error rates must be between 0 and 1.");
133  });
134 
135  // Only total is set so we set all other errors to the total limit.
136  if constexpr (((std::remove_reference_t<errors_t>::_id() == 0) || ...) && sizeof...(errors) == 1)
137  {
138  std::ranges::fill(base_t::value | views::slice(1, 4), base_t::value[0]);
139  } // otherwise if total is not set but any other field is set than use total as the sum of all set errors.
140  else if constexpr (!((std::remove_reference_t<errors_t>::_id() == 0) || ...) && sizeof...(errors) > 0)
141  {
142  base_t::value[0] = std::min(1., ranges::accumulate(base_t::value | views::slice(1, 4), .0));
143  }
144  }
146 };
147 
153 max_error_rate() -> max_error_rate<>;
155 
157 template <typename ...errors_t>
158 max_error_rate(errors_t && ...) -> max_error_rate<remove_cvref_t<errors_t>...>;
160 
161 } // namespace seqan3::search_cfg
seqan3::search_cfg::max_error_rate::max_error_rate
constexpr max_error_rate(errors_t &&...errors)
Constructs the object from a set of error specifiers.
Definition: max_error_rate.hpp:117
pack_algorithm.hpp
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
configuration.hpp
Provides seqan3::detail::configuration and utility functions.
detail.hpp
Provides compatibility matrix for search configurations.
pipeable_config_element.hpp
Provides seqan3::pipeable_config_element.
algorithm
Adaptations of algorithms from the Ranges TS.
seqan3::search_cfg
A special sub namespace for the search configurations.
seqan3::search_cfg::max_error_rate::~max_error_rate
~max_error_rate() noexcept=default
Destructor.
seqan3::search_cfg::max_error_rate
A configuration element for the maximum number of errors in percent of the query length across all er...
Definition: max_error_rate.hpp:45
slice.hpp
Provides seqan3::views::slice.
seqan3::search_cfg::max_error_rate::max_error_rate
constexpr max_error_rate() noexcept=default
Default constructor.
std::array< double, 4 >
seqan3::pipeable_config_element
Adds pipe interface to configuration elements.
Definition: pipeable_config_element.hpp:30
std::invalid_argument
seqan3::pipeable_config_element< max_error_rate< errors_t... >, std::array< double, 4 > >::value
std::array< double, 4 > value
The stored config value.
Definition: pipeable_config_element.hpp:33
std::min
T min(T... args)
std::remove_reference_t
seqan3::search_cfg::max_error_rate::operator=
constexpr max_error_rate & operator=(max_error_rate const &) noexcept=default
Copy assignment.
max_error_common.hpp
Provides the error types for maximum number of errors.
seqan3::views::slice
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:141
std::remove_cv_t