SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
masked.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 
13 #pragma once
14 
19 
20 namespace seqan3
21 {
40  template <writable_alphabet sequence_alphabet_t>
42  requires std::regular<sequence_alphabet_t>
44 class masked : public alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>
45 {
46 private:
48  using base_t = alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>;
49 
50 public:
52  using sequence_alphabet_type = sequence_alphabet_t;
53 
56 
58  using typename base_t::rank_type;
59 
63  constexpr masked() = default;
64  constexpr masked(masked const &) = default;
65  constexpr masked(masked &&) = default;
66  constexpr masked & operator =(masked const &) = default;
67  constexpr masked & operator =(masked &&) = default;
68  ~masked() = default;
69 
70  using base_t::base_t; // Inherit non-default constructors
72 
73  // Inherit operators from base
74  using base_t::operator=;
75 
79  constexpr masked & assign_char(char_type const c) noexcept
81  {
82  using index_t = std::make_unsigned_t<char_type>;
83  base_t::assign_rank(char_to_rank[static_cast<index_t>(c)]);
84  return *this;
85  }
87 
91  constexpr char_type to_char() const noexcept
93  {
94  return rank_to_char[base_t::to_rank()];
95  }
97 
98 protected:
101  {
102  [] ()
103  {
105 
106  for (size_t i = 0; i < alphabet_size; ++i)
107  {
108  ret[i] = (i < alphabet_size / 2)
111  }
112 
113  return ret;
114  } ()
115  };
116 
119  {
120  [] ()
121  {
123 
124  for (size_t i = 0; i < 256; ++i)
125  {
126  char_type c = static_cast<char_type>(i);
127 
128  ret[i] = is_lower(c)
131  }
132 
133  return ret;
134  } ()
135  };
136 };
137 
140 template <typename sequence_alphabet_type>
143 } //namespace seqan3
mask.hpp
Create a mask composite which can be applied with another alphabet.
seqan3::assign_rank_to
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:239
seqan3::masked::rank_to_char
static constexpr std::array< char_type, alphabet_size > rank_to_char
Rank to char conversion table.
Definition: masked.hpp:101
seqan3::masked
Implementation of a masked composite, which extends a given alphabet with a mask.
Definition: masked.hpp:45
seqan3::masked::masked
masked(sequence_alphabet_type &&, mask const &) -> masked< std::decay_t< sequence_alphabet_type >>
Type deduction guide enables usage of masked without specifying template args.
seqan3::masked::char_type
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: masked.hpp:55
seqan3::alphabet_base< masked< sequence_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::alphabet_size
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:176
seqan3::alphabet_tuple_base
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:120
seqan3::masked::sequence_alphabet_type
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: masked.hpp:52
seqan3::masked::operator=
constexpr masked & operator=(masked const &)=default
Defaulted.
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:321
seqan3::alphabet_base< masked< sequence_alphabet_t >,(1 *... *alphabet_size< component_types >), void >
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:143
seqan3::masked::masked
constexpr masked(masked const &)=default
Defaulted.
seqan3::masked::masked
constexpr masked()=default
Defaulted.
seqan3::mask
Implementation of a masked alphabet to be used for tuple composites.
Definition: mask.hpp:35
seqan3::masked::to_char
constexpr char_type to_char() const noexcept
Return a character.
Definition: masked.hpp:92
seqan3::masked::masked
constexpr masked(masked &&)=default
Defaulted.
seqan3::masked::char_to_rank
static constexpr std::array< rank_type, detail::size_in_values_v< char_type > > char_to_rank
Char to rank conversion table.
Definition: masked.hpp:119
seqan3::alphabet_char_t
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:330
seqan3::alphabet_base< masked< sequence_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::rank_type
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:64
std::array< char_type, alphabet_size >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
transform.hpp
Provides utilities for modifying characters.
predicate.hpp
Provides character predicates for tokenisation.
seqan3::masked::assign_char
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition: masked.hpp:80
alphabet_tuple_base.hpp
Provides seqan3::alphabet_tuple_base.
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:417
seqan3::masked::~masked
~masked()=default
Defaulted.
seqan3::alphabet_base< masked< sequence_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::assign_rank
constexpr masked< sequence_alphabet_t > & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:167
seqan3::to_lower
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
seqan3::is_lower
constexpr auto is_lower
Checks whether c is a lower case character.
Definition: predicate.hpp:271
seqan3::alphabet_base< masked< sequence_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:118
std::make_unsigned_t