Loading...
Searching...
No Matches
dna3bs.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>
// ------------------------------------------------------------------
// dna3bs
// ------------------------------------------------------------------
namespace seqan3
{
class dna3bs : public nucleotide_base<dna3bs, 3>
{
private:
using base_t = nucleotide_base<dna3bs, 3>;
friend base_t;
friend base_t::base_t;
public:
constexpr dna3bs() noexcept = default;
constexpr dna3bs(dna3bs const &) noexcept = default;
constexpr dna3bs(dna3bs &&) noexcept = default;
constexpr dna3bs & operator=(dna3bs const &) noexcept = default;
constexpr dna3bs & operator=(dna3bs &&) noexcept = default;
~dna3bs() noexcept = default;
using base_t::base_t;
private:
static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'G', 'T'};
static constexpr rank_type rank_complement_table[alphabet_size]{
2, // T is complement of 'A'_dna3bs
2, // T is complement of 'G'_dna3bs
0 // A is complement of 'T'_dna3bs
};
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{};
// 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 C and U equal to T
ret['C'] = ret['T'];
ret['c'] = ret['t'];
ret['U'] = ret['T'];
ret['u'] = ret['t'];
// iupac characters get special treatment, because there is no N
ret['R'] = ret['A'];
ret['r'] = ret['A']; // A or G becomes A
ret['Y'] = ret['T'];
ret['y'] = ret['T']; // C or T becomes T
ret['S'] = ret['T'];
ret['s'] = ret['T']; // C or G becomes T
ret['W'] = ret['A'];
ret['w'] = ret['A']; // A or T becomes A
ret['K'] = ret['G'];
ret['k'] = ret['G']; // G or T becomes G
ret['M'] = ret['A'];
ret['m'] = ret['A']; // A or C becomes A
ret['B'] = ret['T'];
ret['b'] = ret['T']; // C or G or T becomes T
ret['D'] = ret['A'];
ret['d'] = ret['A']; // A or G or T becomes A
ret['H'] = ret['A'];
ret['h'] = ret['A']; // A or C or T becomes A
ret['V'] = ret['A'];
ret['v'] = ret['A']; // A or C or G becomes A
return ret;
}()};
};
// ------------------------------------------------------------------
// containers
// ------------------------------------------------------------------
using dna3bs_vector = std::vector<dna3bs>;
// ------------------------------------------------------------------
// literals
// ------------------------------------------------------------------
inline namespace literals
{
constexpr dna3bs operator""_dna3bs(char const c) noexcept
{
return dna3bs{}.assign_char(c);
}
SEQAN3_WORKAROUND_LITERAL dna3bs_vector operator""_dna3bs(char const * s, std::size_t n)
{
dna3bs_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::dna3bs::dna3bs_vector
std::vector< dna3bs > dna3bs_vector
Alias for a std::vector of seqan3::dna3bs.
Definition dna3bs.hpp:167
seqan3::dna3bs::dna3bs
constexpr dna3bs() noexcept=default
Defaulted.
seqan3::nucleotide_base< dna3bs, 3 >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
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
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