SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
concept.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 <iostream>
17 #include <string>
18 
20 
21 // ============================================================================
22 // forwards
23 // ============================================================================
24 
26 namespace seqan3::custom
27 {
28 
29 void to_phred();
30 void assign_phred_to();
31 
32 } // namespace seqan3::custom
34 
35 // ============================================================================
36 // to_phred()
37 // ============================================================================
38 
40 {
41 
43 struct to_phred_fn
44 {
45 private:
46  SEQAN3_CPO_IMPL(2, to_phred(v) ) // ADL
47  SEQAN3_CPO_IMPL(1, seqan3::custom::to_phred(v) ) // customisation namespace
48  SEQAN3_CPO_IMPL(0, v.to_phred() ) // member
49 
50 public:
52  template <typename alph_t>
54  requires requires (alph_t const chr) { { impl(priority_tag<2>{}, chr) }; }
56  constexpr auto operator()(alph_t const chr) const noexcept
57  {
58  static_assert(noexcept(impl(priority_tag<2>{}, chr)),
59  "Only overloads that are marked noexcept are picked up by seqan3::to_phred().");
60  static_assert(std::Constructible<size_t, decltype(impl(priority_tag<2>{}, chr))>,
61  "The return type of your to_phred() implementation must be convertible to size_t.");
62 
63  return impl(priority_tag<2>{}, chr);
64  }
65 };
66 
67 } // namespace seqan3::detail::adl::only
68 
69 namespace seqan3
70 {
71 
104 inline constexpr auto to_phred = detail::adl::only::to_phred_fn{};
106 
110 template <typename alphabet_type>
112  requires requires { { seqan3::to_phred(std::declval<alphabet_type>()) }; }
114 using alphabet_phred_t = decltype(seqan3::to_phred(std::declval<alphabet_type>()));
115 
116 } // namespace seqan3
117 
118 // ============================================================================
119 // assign_phred_to()
120 // ============================================================================
121 
123 {
124 
127 struct assign_phred_to_fn
128 {
129 private:
130  SEQAN3_CPO_IMPL(2, (assign_phred_to(args..., v) )) // ADL
131  SEQAN3_CPO_IMPL(1, (seqan3::custom::assign_phred_to(args..., v) )) // customisation namespace
132  SEQAN3_CPO_IMPL(0, (v.assign_phred(args...) )) // member
133 
134 public:
136  template <typename alph_t>
138  requires requires (seqan3::alphabet_phred_t<alph_t> const p, alph_t & a)
139  { { impl(priority_tag<2>{}, a, p) }; }
141  constexpr alph_t & operator()(seqan3::alphabet_phred_t<alph_t> const p, alph_t & a) const noexcept
142  {
143  static_assert(noexcept(impl(priority_tag<2>{}, a, p)),
144  "Only overloads that are marked noexcept are picked up by seqan3::assign_phred_to().");
145  static_assert(std::Same<alph_t &, decltype(impl(priority_tag<2>{}, a, p))>,
146  "The return type of your assign_phred_to() implementation must be 'alph_t &'.");
147 
148  return impl(priority_tag<2>{}, a, p);
149  }
150 
152  template <typename alph_t>
154  requires requires (seqan3::alphabet_phred_t<alph_t> const p, alph_t & a)
155  { { impl(priority_tag<2>{}, a, p) }; } && (!std::is_lvalue_reference_v<alph_t>)
157  constexpr alph_t operator()(seqan3::alphabet_phred_t<alph_t> const p, alph_t && a) const noexcept
158  {
159  return (*this)(p, a); // call above function but return by value
160  }
161 };
162 
163 } // namespace seqan3::detail::adl::only
164 
165 namespace seqan3
166 {
167 
201 inline constexpr auto assign_phred_to = detail::adl::only::assign_phred_to_fn{};
203 
204 } // namespace seqan3
205 
206 // ============================================================================
207 // seqan3::QualityAlphabet
208 // ============================================================================
209 
210 namespace seqan3
211 {
212 
240 template <typename t>
242 SEQAN3_CONCEPT QualityAlphabet = Alphabet<t> && requires(t qual)
243 {
244  { seqan3::to_phred(qual) };
245 };
247 
248 // ============================================================================
249 // seqan3::WritableQualityAlphabet
250 // ============================================================================
251 
278 template <typename t>
280 SEQAN3_CONCEPT WritableQualityAlphabet = WritableAlphabet<t> && QualityAlphabet<t> && requires(t qual)
281 {
282  { seqan3::assign_phred_to(typename t::rank_type{}, qual) };
283 };
285 
286 } // namespace seqan3
#define SEQAN3_CPO_IMPL(PRIO, TERM)
A macro that helps defining the overload set of a customisation point.
Definition: customisation_point.hpp:45
Definition: concept.hpp:32
The main SeqAn3 namespace.
constexpr auto assign_phred_to
Assign a phred score to a quality alphabet object.
Definition: concept.hpp:201
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:104
The std::Constructible concept specifies that a variable of type T can be initialized with the given ...
decltype(seqan3::to_phred(std::declval< alphabet_type >())) alphabet_phred_t
The phred_type of the alphabet; defined as the return type of seqan3::to_phred.
Definition: concept.hpp:114
Core alphabet concept and free function/type trait wrappers.
A namespace for third party and standard library specialisations of SeqAn customisation points...
Definition: char.hpp:47
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.