SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
masked.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
13 #pragma once
14 
19 
20 namespace seqan3
21 {
42 template <writable_alphabet sequence_alphabet_t>
44  requires std::regular<sequence_alphabet_t>
46 class masked : public alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>
47 {
48 private:
50  using base_t = alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>;
51 
52 public:
57  using sequence_alphabet_type = sequence_alphabet_t;
58 
64 
66  using typename base_t::rank_type;
67 
71  constexpr masked() = default;
72  constexpr masked(masked const &) = default;
73  constexpr masked(masked &&) = default;
74  constexpr masked & operator =(masked const &) = default;
75  constexpr masked & operator =(masked &&) = default;
76  ~masked() = default;
77 
78  using base_t::base_t; // Inherit non-default constructors
80 
81  // Inherit operators from base
82  using base_t::operator=;
83 
91  constexpr masked & assign_char(char_type const c) noexcept
92  {
93  using index_t = std::make_unsigned_t<char_type>;
94  base_t::assign_rank(char_to_rank[static_cast<index_t>(c)]);
95  return *this;
96  }
98 
106  constexpr char_type to_char() const noexcept
107  {
108  return rank_to_char[base_t::to_rank()];
109  }
111 
112 protected:
115  {
116  [] ()
117  {
119 
120  for (size_t i = 0; i < alphabet_size; ++i)
121  {
122  ret[i] = (i < alphabet_size / 2)
125  }
126 
127  return ret;
128  } ()
129  };
130 
133  {
134  [] ()
135  {
137 
138  for (size_t i = 0; i < 256; ++i)
139  {
140  char_type c = static_cast<char_type>(i);
141 
142  ret[i] = is_lower(c)
145  }
146 
147  return ret;
148  } ()
149  };
150 };
151 
154 template <typename sequence_alphabet_type>
157 } //namespace seqan3
Provides seqan3::alphabet_tuple_base.
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:185
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:104
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:276
constexpr masked< sequence_alphabet_t > & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:264
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:124
Implementation of a masked alphabet to be used for tuple composites.
Definition: mask.hpp:37
Implementation of a masked composite, which extends a given alphabet with a mask.
Definition: masked.hpp:47
static constexpr std::array< rank_type, detail::size_in_values_v< char_type > > char_to_rank
Char to rank conversion table.
Definition: masked.hpp:133
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: masked.hpp:63
constexpr masked & operator=(masked const &)=default
Defaulted.
static constexpr std::array< char_type, alphabet_size > rank_to_char
Rank to char conversion table.
Definition: masked.hpp:115
~masked()=default
Defaulted.
constexpr masked(masked &&)=default
Defaulted.
constexpr masked()=default
Defaulted.
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: masked.hpp:57
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(masked const &)=default
Defaulted.
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition: masked.hpp:91
constexpr char_type to_char() const noexcept
Return a character.
Definition: masked.hpp:106
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:523
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:384
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:291
decltype(seqan3::to_char(std::declval< alphabet_type const >())) alphabet_char_t
The char_type of the alphabet; defined as the return type of seqan3::to_char.
Definition: concept.hpp:396
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:155
constexpr auto is_lower
Checks whether c is a lower case character.
Definition: predicate.hpp:271
Create a mask composite which can be applied with another alphabet.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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:81
Provides character predicates for tokenisation.
Provides utilities for modifying characters.