Loading...
Searching...
No Matches
translation.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 <tuple>
#include <seqan3/alphabet/aminoacid/aa27.hpp>
#include <seqan3/alphabet/aminoacid/translation_details.hpp>
#include <seqan3/alphabet/aminoacid/translation_genetic_code.hpp>
#include <seqan3/core/range/type_traits.hpp>
namespace seqan3
{
// forwards:
class dna4;
class dna5;
class dna15;
class rna4;
class rna5;
class rna15;
template <genetic_code gc = genetic_code::canonical, nucleotide_alphabet nucl_type>
constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
{
if constexpr (std::same_as<nucl_type, dna4> || std::same_as<nucl_type, dna5> || std::same_as<nucl_type, dna15>)
{
// table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
return seqan3::detail::translation_table<nucl_type, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
}
else if constexpr (std::same_as<nucl_type, rna4> || std::same_as<nucl_type, rna5> || std::same_as<nucl_type, rna15>)
{
using rna2dna_t =
std::conditional_t<std::same_as<nucl_type, rna4>,
dna4,
std::conditional_t<std::same_as<nucl_type, rna5>,
dna5,
std::conditional_t<std::same_as<nucl_type, rna15>, dna15, void>>>;
// we can use dna's tables, because ranks are identical
return seqan3::detail::translation_table<rna2dna_t, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
}
else // composites or user defined nucleotide
{
// we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
// (nucleotide types can be converted to dna15 by definition)
return seqan3::detail::translation_table<dna15, gc>::value[to_rank(static_cast<dna15>(n1))][to_rank(
static_cast<dna15>(n2))][to_rank(static_cast<dna15>(n3))];
}
}
} // namespace seqan3
aa27.hpp
Provides seqan3::aa27, container aliases and string literals.
seqan3::aa27
The twenty-seven letter amino acid alphabet.
Definition aa27.hpp:43
seqan3::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition dna15.hpp:48
seqan3::dna4
The four letter DNA alphabet of A,C,G,T.
Definition dna4.hpp:50
seqan3::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
seqan3::rna15
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition rna15.hpp:48
seqan3::rna4
The four letter RNA alphabet of A,C,G,U.
Definition rna4.hpp:46
seqan3::rna5
The five letter RNA alphabet of A,C,G,U and the unknown character N.
Definition rna5.hpp:46
std::conditional_t
type_traits.hpp
Provides various transformation traits used by the range module.
seqan3::translate_triplet
constexpr aa27 translate_triplet(nucl_type const &n1, nucl_type const &n2, nucl_type const &n3) noexcept
Translate one nucleotide triplet into single amino acid (single nucleotide interface).
Definition translation.hpp:52
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
translation_details.hpp
Provides translation details for nucleotide to aminoacid translation.
translation_genetic_code.hpp
Genetic codes used for translating a triplet of nucleotides into an amino acid.
tuple
Hide me