Loading...
Searching...
No Matches
dna15.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <vector>
#include <seqan3/alphabet/nucleotide/nucleotide_base.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
// ------------------------------------------------------------------
// dna15
// ------------------------------------------------------------------
namespace seqan3
{
class rna15;
class dna15 : public nucleotide_base<dna15, 15>
{
private:
using base_t = nucleotide_base<dna15, 15>;
friend base_t;
friend base_t::base_t;
friend rna15;
public:
constexpr dna15() noexcept = default;
constexpr dna15(dna15 const &) noexcept = default;
constexpr dna15(dna15 &&) noexcept = default;
constexpr dna15 & operator=(dna15 const &) noexcept = default;
constexpr dna15 & operator=(dna15 &&) noexcept = default;
~dna15() noexcept = default;
using base_t::base_t;
template <std::same_as<rna15> t> // Accept incomplete type
constexpr dna15(t const & r) noexcept
{
assign_rank(r.to_rank());
}
private:
static constexpr char_type
rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'D', 'G', 'H', 'K', 'M', 'N', 'R', 'S', 'T', 'V', 'W', 'Y'};
static constexpr rank_type rank_complement_table[alphabet_size]{
11, // T is complement of 'A'_dna15
12, // V is complement of 'B'_dna15
4, // G is complement of 'C'_dna15
5, // H is complement of 'D'_dna15
2, // C is complement of 'G'_dna15
3, // D is complement of 'H'_dna15
7, // M is complement of 'K'_dna15
6, // K is complement of 'M'_dna15
8, // N is complement of 'N'_dna15
14, // Y is complement of 'R'_dna15
10, // S is complement of 'S'_dna15
0, // A is complement of 'T'_dna15
1, // B is complement of 'V'_dna15
13, // W is complement of 'W'_dna15
9 // R is complement of 'Y'_dna15
};
static constexpr rank_type rank_complement(rank_type const rank)
{
return rank_complement_table[rank];
}
static constexpr char_type rank_to_char(rank_type const rank)
{
return rank_to_char_table[rank];
}
static constexpr rank_type char_to_rank(char_type const chr)
{
using index_t = std::make_unsigned_t<char_type>;
return char_to_rank_table[static_cast<index_t>(chr)];
}
static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr
{
std::array<rank_type, 256> ret{};
ret.fill(8u); // initialize with UNKNOWN ('N')
// reverse mapping for characters and their lowercase
for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
{
ret[rank_to_char_table[rnk]] = rnk;
ret[to_lower(rank_to_char_table[rnk])] = rnk;
}
// set U equal to T
ret['U'] = ret['T'];
ret['u'] = ret['t'];
return ret;
}()};
};
// ------------------------------------------------------------------
// containers
// ------------------------------------------------------------------
using dna15_vector = std::vector<dna15>;
// ------------------------------------------------------------------
// literals
// ------------------------------------------------------------------
inline namespace literals
{
constexpr dna15 operator""_dna15(char const c) noexcept
{
return dna15{}.assign_char(c);
}
SEQAN3_WORKAROUND_LITERAL dna15_vector operator""_dna15(char const * s, std::size_t n)
{
dna15_vector r;
r.resize(n);
for (size_t i = 0; i < n; ++i)
r[i].assign_char(s[i]);
return r;
}
} // namespace literals
} // namespace seqan3
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
seqan3::alphabet_base::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:77
seqan3::alphabet_base::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:196
seqan3::alphabet_base::char_type
std::conditional_t< std::same_as< char_t, void >, char, char_t > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition alphabet_base.hpp:69
seqan3::alphabet_base::assign_rank
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
seqan3::dna15::dna15_vector
std::vector< dna15 > dna15_vector
Alias for a std::vector of seqan3::dna15.
Definition dna15.hpp:190
seqan3::dna15::dna15
constexpr dna15() noexcept=default
Defaulted.
seqan3::nucleotide_base< dna15, 15 >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
seqan3::rna15
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition rna15.hpp:48
std::array::fill
T fill(T... args)
seqan3::alphabet_size
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition alphabet/concept.hpp:834
seqan3::literals
The SeqAn namespace for literals.
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:74
std
SeqAn specific customisations in the standard namespace.
nucleotide_base.hpp
Provides seqan3::nucleotide_base.
SEQAN3_WORKAROUND_LITERAL
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition platform.hpp:310
std::vector::resize
T resize(T... args)
std::size_t
transform.hpp
Provides utilities for modifying characters.
vector
Hide me