Loading...
Searching...
No Matches
dot_bracket3.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/alphabet_base.hpp>
#include <seqan3/alphabet/structure/concept.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
// ------------------------------------------------------------------
// dot_bracket3
// ------------------------------------------------------------------
namespace seqan3
{
class dot_bracket3 : public alphabet_base<dot_bracket3, 3>
{
private:
using base_t = alphabet_base<dot_bracket3, 3>;
friend base_t;
public:
constexpr dot_bracket3() noexcept = default;
constexpr dot_bracket3(dot_bracket3 const &) noexcept = default;
constexpr dot_bracket3(dot_bracket3 &&) noexcept = default;
constexpr dot_bracket3 & operator=(dot_bracket3 const &) noexcept = default;
constexpr dot_bracket3 & operator=(dot_bracket3 &&) noexcept = default;
~dot_bracket3() noexcept = default;
constexpr bool is_pair_open() const noexcept
{
return to_rank() == 1u;
}
constexpr bool is_pair_close() const noexcept
{
return to_rank() == 2u;
}
constexpr bool is_unpaired() const noexcept
{
return to_rank() == 0u;
}
static constexpr uint8_t max_pseudoknot_depth{1u};
constexpr std::optional<uint8_t> pseudoknot_id() const noexcept
{
if (is_unpaired())
return std::nullopt;
else
return 0;
}
private:
static constexpr char_type rank_to_char_table[alphabet_size]{'.', '(', ')'};
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> rank_table{};
// Value-initialisation of std::array does usually initialise. `fill` is explicit.
rank_table.fill(0u);
// canonical
rank_table['.'] = 0u;
rank_table['('] = 1u;
rank_table[')'] = 2u;
return rank_table;
}()};
};
inline namespace literals
{
constexpr dot_bracket3 operator""_db3(char const ch) noexcept
{
return dot_bracket3{}.assign_char(ch);
}
SEQAN3_WORKAROUND_LITERAL std::vector<dot_bracket3> operator""_db3(char const * str, std::size_t len)
{
std::vector<dot_bracket3> vec;
vec.resize(len);
for (size_t idx = 0ul; idx < len; ++idx)
vec[idx].assign_char(str[idx]);
return vec;
}
} // namespace literals
} // namespace seqan3
concept.hpp
Provides seqan3::rna_structure_alphabet.
alphabet_base.hpp
Provides seqan3::alphabet_base.
seqan3::alphabet_base< dot_bracket3, 3 >::assign_char
constexpr dot_bracket3 & assign_char(char_type const chr) noexcept
Definition alphabet_base.hpp:160
seqan3::alphabet_base< dot_bracket3, 3 >::alphabet_base
constexpr alphabet_base() noexcept=default
seqan3::alphabet_base< dot_bracket3, 3 >::to_rank
constexpr rank_type to_rank() const noexcept
Definition alphabet_base.hpp:134
seqan3::alphabet_base< dot_bracket3, 3 >::rank_type
detail::min_viable_uint_t< size - 1 > rank_type
Definition alphabet_base.hpp:77
seqan3::alphabet_base< dot_bracket3, 3 >::char_type
std::conditional_t< std::same_as< char, void >, char, char > char_type
Definition alphabet_base.hpp:69
seqan3::dot_bracket3::is_pair_close
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition dot_bracket3.hpp:90
seqan3::dot_bracket3::pseudoknot_id
constexpr std::optional< uint8_t > pseudoknot_id() const noexcept
Get an identifier for a pseudoknotted interaction, where opening and closing brackets of the same typ...
Definition dot_bracket3.hpp:119
seqan3::dot_bracket3::max_pseudoknot_depth
static constexpr uint8_t max_pseudoknot_depth
The ability of this alphabet to represent pseudoknots, i.e. crossing interactions,...
Definition dot_bracket3.hpp:111
seqan3::dot_bracket3::is_unpaired
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition dot_bracket3.hpp:100
seqan3::dot_bracket3::dot_bracket3
constexpr dot_bracket3() noexcept=default
Defaulted.
seqan3::dot_bracket3::is_pair_open
constexpr bool is_pair_open() const noexcept
Check whether the character represents a rightward interaction in an RNA structure.
Definition dot_bracket3.hpp:80
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
std::optional
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