BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
masked.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
17#include <bio/alphabet/detail/to_lower.hpp>
19
20namespace bio::alphabet
21{
40template <writable_alphabet sequence_alphabet_t>
41 requires std::regular<sequence_alphabet_t>
42class masked : public tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>
43{
44private:
46 using base_t = tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>;
47
48public:
50 using sequence_alphabet_type = sequence_alphabet_t;
51
54
56 using typename base_t::rank_type;
57
61 constexpr masked() = default;
62 constexpr masked(masked const &) = default;
63 constexpr masked(masked &&) noexcept = default;
64 constexpr masked & operator=(masked const &) = default;
65 constexpr masked & operator=(masked &&) noexcept = default;
66 ~masked() = default;
67
68 using base_t::base_t; // Inherit non-default constructors
70
71 // Inherit operators from base
72 using base_t::operator=;
73
78 constexpr masked & assign_char(char_type const c) noexcept
79 {
80 using index_t = std::make_unsigned_t<char_type>;
81 base_t::assign_rank(char_to_rank[static_cast<index_t>(c)]);
82 return *this;
83 }
85
90 constexpr char_type to_char() const noexcept { return rank_to_char[base_t::to_rank()]; }
92
93protected:
96 {
98
99 for (size_t i = 0; i < alphabet_size / 2; ++i)
100 {
102 ret[i + alphabet_size / 2] = detail::to_lower(ret[i]);
103 }
104
105 return ret;
106 }();
107
110 {
112
113 for (size_t i = 0; i < meta::detail::size_in_values_v<char_type>; ++i)
114 {
115 char_type c = static_cast<char_type>(i);
116
117 ret[i] =
118 detail::is_lower(c)
121 }
122
123 return ret;
124 }();
125};
126
129template <typename sequence_alphabet_type>
131} //namespace bio::alphabet
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: base.hpp:168
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
meta::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: base.hpp:65
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: base.hpp:124
Implementation of a masked semialphabet to be used for tuple composites..
Definition: mask.hpp:37
A template for composite alphabets that differentiate between upper and lower case characters....
Definition: masked.hpp:43
static constexpr std::array< rank_type, meta::detail::size_in_values_v< char_type > > char_to_rank
Char to rank conversion table.
Definition: masked.hpp:109
constexpr masked(masked &&) noexcept=default
Defaulted.
char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: masked.hpp:53
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: masked.hpp:50
static constexpr std::array< char_type, alphabet_size > rank_to_char
Rank to char conversion table.
Definition: masked.hpp:95
constexpr masked(masked const &)=default
Defaulted.
constexpr masked()=default
Defaulted.
masked(sequence_alphabet_type &&, mask const &) -> masked< std::decay_t< sequence_alphabet_type > >
Type deduction guide enables usage of masked without specifying template args.
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition: masked.hpp:78
constexpr char_type to_char() const noexcept
Return a character.
Definition: masked.hpp:90
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: tuple_base.hpp:96
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:192
constexpr auto assign_char_to
Assign a char to an alphabet object.
Definition: concept.hpp:260
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
decltype(bio::alphabet::to_char(std::declval< alphabet_type const >())) char_t
The char_type of the alphabet; defined as the return type of bio::alphabet::to_char.
Definition: concept.hpp:212
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:138
Create a mask composite which can be applied with another alphabet.
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::tuple_base.