SeqAn3
nucleotide_base.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (chr) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (chr) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
43 #include <seqan3/alphabet/detail/convert.hpp>
45 
46 namespace seqan3
47 {
48 
64 template <typename derived_type, auto size>
65 class nucleotide_base : public alphabet_base<derived_type, size, char>
66 {
67 private:
70 
74  constexpr nucleotide_base() noexcept : base_t{} {}
75  constexpr nucleotide_base(nucleotide_base const &) = default;
76  constexpr nucleotide_base(nucleotide_base &&) = default;
77  constexpr nucleotide_base & operator=(nucleotide_base const &) = default;
78  constexpr nucleotide_base & operator=(nucleotide_base &&) = default;
79  ~nucleotide_base() = default;
81 
83  friend derived_type;
84 
85 public:
86  // Import from base:
87  using typename base_t::char_type;
88  using typename base_t::rank_type;
89  using base_t::value_size;
90  using base_t::to_rank;
91 
95  // This constructor needs to be public, because constructor templates are not inherited otherwise
97  template <typename other_nucl_type>
103  explicit constexpr nucleotide_base(other_nucl_type const & other) noexcept
104  {
105  using seqan3::to_rank;
106  static_cast<derived_type &>(*this) =
107  detail::convert_through_char_representation<derived_type, other_nucl_type>[to_rank(other)];
108  }
110 
131  constexpr derived_type complement() const noexcept
132  {
133  return derived_type::complement_table[to_rank()];
134  }
136 };
137 
138 } // namespace seqan3
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:89
char char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
constexpr derived_type complement() const noexcept
Return the complement of the letter.
Definition: nucleotide_base.hpp:131
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
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:103
static detail::min_viable_uint_t< size > constexpr value_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:198
Provides seqan3::nucleotide_concept.
Provides seqan3::alphabet_base.
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
constexpr rank_type to_rank() const noexcept
Return the letter&#39;s numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:142
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:77
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:65
constexpr underlying_rank_t< alphabet_type > to_rank(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::to_rank() that delegates to a member function...
Definition: member_exposure.hpp:97
A concept that indicates whether an alphabet represents nucleotides.In addition to the requirements f...