SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
concept.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 
17 
18 // ============================================================================
19 // to_phred()
20 // ============================================================================
21 
22 namespace seqan3::detail::adl_only
23 {
24 
26 template <typename ...args_t>
27 void to_phred(args_t ...) = delete;
28 
30 struct to_phred_fn
31 {
32 public:
33  SEQAN3_CPO_IMPL(2, seqan3::custom::alphabet<decltype(v)>::to_phred(v)) // explicit customisation
34  SEQAN3_CPO_IMPL(1, to_phred(v) ) // ADL
35  SEQAN3_CPO_IMPL(0, v.to_phred() ) // member
36 
37 public:
39  template <typename alph_t>
41  requires requires (alph_t const chr) { { impl(priority_tag<2>{}, chr) }; }
43  constexpr auto operator()(alph_t const chr) const noexcept
44  {
45  static_assert(noexcept(impl(priority_tag<2>{}, chr)),
46  "Only overloads that are marked noexcept are picked up by seqan3::to_phred().");
47  static_assert(std::constructible_from<size_t, decltype(impl(priority_tag<2>{}, chr))>,
48  "The return type of your to_phred() implementation must be convertible to size_t.");
49 
50  return impl(priority_tag<2>{}, chr);
51  }
52 };
53 
54 } // namespace seqan3::detail::adl_only
55 
56 namespace seqan3
57 {
58 
89 inline constexpr auto to_phred = detail::adl_only::to_phred_fn{};
91 
95 template <typename alphabet_type>
97  requires requires { { seqan3::to_phred(std::declval<alphabet_type>()) }; }
99 using alphabet_phred_t = decltype(seqan3::to_phred(std::declval<alphabet_type>()));
100 
101 } // namespace seqan3
102 
103 // ============================================================================
104 // assign_phred_to()
105 // ============================================================================
106 
107 namespace seqan3::detail::adl_only
108 {
109 
111 template <typename ...args_t>
112 void assign_phred_to(args_t ...) = delete;
113 
116 struct assign_phred_to_fn
117 {
118 public:
119  SEQAN3_CPO_IMPL(2, (seqan3::custom::alphabet<decltype(v)>::assign_phred_to(args..., v))) // explicit customisation
120  SEQAN3_CPO_IMPL(1, (assign_phred_to(args..., v) )) // ADL
121  SEQAN3_CPO_IMPL(0, (v.assign_phred(args...) )) // member
122 
123 public:
125  template <typename alph_t>
127  requires requires (seqan3::alphabet_phred_t<alph_t> const p, alph_t & a)
128  { { impl(priority_tag<2>{}, a, p) }; }
130  constexpr alph_t & operator()(seqan3::alphabet_phred_t<alph_t> const p, alph_t & a) const noexcept
131  {
132  static_assert(noexcept(impl(priority_tag<2>{}, a, p)),
133  "Only overloads that are marked noexcept are picked up by seqan3::assign_phred_to().");
134  static_assert(std::same_as<alph_t &, decltype(impl(priority_tag<2>{}, a, p))>,
135  "The return type of your assign_phred_to() implementation must be 'alph_t &'.");
136 
137  return impl(priority_tag<2>{}, a, p);
138  }
139 
141  template <typename alph_t>
143  requires requires (seqan3::alphabet_phred_t<alph_t> const p, alph_t & a)
144  { { impl(priority_tag<2>{}, a, p) }; } && (!std::is_lvalue_reference_v<alph_t>)
146  constexpr alph_t operator()(seqan3::alphabet_phred_t<alph_t> const p, alph_t && a) const noexcept
147  {
148  return (*this)(p, a); // call above function but return by value
149  }
150 };
151 
152 } // namespace seqan3::detail::adl_only
153 
154 namespace seqan3
155 {
156 
189 inline constexpr auto assign_phred_to = detail::adl_only::assign_phred_to_fn{};
191 
192 } // namespace seqan3
193 
194 // ============================================================================
195 // seqan3::quality_alphabet
196 // ============================================================================
197 
198 namespace seqan3
199 {
200 
228 template <typename t>
230 SEQAN3_CONCEPT quality_alphabet = alphabet<t> && requires(t qual)
231 {
232  { seqan3::to_phred(qual) };
233 };
235 
236 // ============================================================================
237 // seqan3::writable_quality_alphabet
238 // ============================================================================
239 
266 template <typename t>
270  requires(t v, alphabet_phred_t<t> c)
271 {
272  { seqan3::assign_phred_to(c, v) };
273 };
275 
276 } // namespace seqan3
seqan3::custom::alphabet
A type that can be specialised to provide customisation point implementations so that third party typ...
Definition: concept.hpp:46
constructible_from
The std::constructible_from concept specifies that a variable of type T can be initialized with the g...
SEQAN3_CPO_IMPL
#define SEQAN3_CPO_IMPL(PRIO, TERM)
A macro that helps defining the overload set of a customisation point.
Definition: customisation_point.hpp:45
quality_alphabet
A concept that indicates whether an alphabet represents quality scores.
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
seqan3::alphabet_phred_t
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:99
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::to_phred
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:89
seqan3::assign_phred_to
constexpr auto assign_phred_to
Assign a phred score to a quality alphabet object.
Definition: concept.hpp:189
alphabet
The generic alphabet concept that covers most data types used in ranges.
writable_alphabet
Refines seqan3::alphabet and adds assignability.
writable_quality_alphabet
A concept that indicates whether a writable alphabet represents quality scores.
concept.hpp
Core alphabet concept and free function/type trait wrappers.