SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
nucleotide_base.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
13#include <seqan3/alphabet/detail/convert.hpp>
16
17namespace seqan3
18{
19
38template <typename derived_type, auto size>
39class nucleotide_base : public alphabet_base<derived_type, size, char>
40{
41private:
44
48 constexpr nucleotide_base() noexcept = default;
49 constexpr nucleotide_base(nucleotide_base const &) noexcept = default;
50 constexpr nucleotide_base(nucleotide_base &&) noexcept = default;
51 constexpr nucleotide_base & operator=(nucleotide_base const &) noexcept = default;
52 constexpr nucleotide_base & operator=(nucleotide_base &&) noexcept = default;
53 ~nucleotide_base() noexcept = default;
54
56
58 friend derived_type;
59
60protected:
61 // Import from base:
62 using typename base_t::char_type;
63 using typename base_t::rank_type;
64
65public:
67 using base_t::to_rank;
68
72 // This constructor needs to be public, because constructor templates are not inherited otherwise
77 template <typename other_nucl_type>
78 requires (!std::same_as<nucleotide_base, other_nucl_type>)
79 && (!std::same_as<derived_type, other_nucl_type>) && nucleotide_alphabet<other_nucl_type>
80 explicit constexpr nucleotide_base(other_nucl_type const & other) noexcept
81 {
82 static_cast<derived_type &>(*this) =
83 detail::convert_through_char_representation<other_nucl_type, derived_type>[seqan3::to_rank(other)];
84 }
86
109 constexpr derived_type complement() const noexcept
110 {
111 return derived_type{}.assign_rank(derived_type{}.rank_complement(to_rank()));
112 }
114
136 static constexpr bool char_is_valid(char_type const c) noexcept
137 {
138 return valid_char_table[static_cast<uint8_t>(c)];
139 }
140
141private:
142 // clang-format off
144 static constexpr std::array<bool, 256> valid_char_table
145 {
146 []() constexpr {
148
149 // Value-initialisation of std::array does usually initialise. `fill` is explicit.
150 ret.fill(false);
151
152 // the original valid chars and their lower cases
153 for (size_t rank = 0u; rank < derived_type::alphabet_size; ++rank)
154 {
155 uint8_t c = derived_type::rank_to_char(rank);
156 ret[c] = true;
157 ret[to_lower(c)] = true;
158 }
159
160 // U and T shall be accepted for all
161 ret['U'] = true;
162 ret['T'] = true;
163 ret['u'] = true;
164 ret['t'] = true;
165
166 return ret;
167 }()
168 };
169};
170 // clang-format off
171
172} // namespace seqan3
Provides seqan3::nucleotide_alphabet.
Provides seqan3::alphabet_base.
A CRTP-base that makes defining a custom alphabet easier.
Definition alphabet_base.hpp:54
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition alphabet_base.hpp:77
static constexpr detail::min_viable_uint_t< size > alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition alphabet_base.hpp:196
std::conditional_t< std::same_as< char, void >, char, char > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition alphabet_base.hpp:69
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:40
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character value has a one-to-one mapping to an alphabet value.
Definition nucleotide_base.hpp:136
constexpr derived_type complement() const noexcept
Return the complement of the letter.
Definition nucleotide_base.hpp:109
constexpr nucleotide_base(other_nucl_type const &other) noexcept
Allow explicit construction from any other nucleotide type and convert via the character representati...
Definition nucleotide_base.hpp:80
T fill(T... args)
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
A concept that indicates whether an alphabet represents nucleotides.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
constexpr char_type to_lower(char_type const c) noexcept
Converts 'A'-'Z' to 'a'-'z' respectively; other characters are returned as is.
Definition transform.hpp:80
Provides utilities for modifying characters.
Hide me