SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
translation.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <tuple>
13
18
19namespace seqan3
20{
21
22// forwards:
23class dna4;
24class dna5;
25class dna15;
26class rna4;
27class rna5;
28class rna15;
29
51template <genetic_code gc = genetic_code::canonical, nucleotide_alphabet nucl_type>
52constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
53{
54 if constexpr (std::same_as<nucl_type, dna4> || std::same_as<nucl_type, dna5> || std::same_as<nucl_type, dna15>)
55 {
56 // table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
57 return seqan3::detail::translation_table<nucl_type, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
58 }
59 else if constexpr (std::same_as<nucl_type, rna4> || std::same_as<nucl_type, rna5> || std::same_as<nucl_type, rna15>)
60 {
61 using rna2dna_t =
63 dna4,
65 dna5,
67
68 // we can use dna's tables, because ranks are identical
69 return seqan3::detail::translation_table<rna2dna_t, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
70 }
71 else // composites or user defined nucleotide
72 {
73 // we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
74 // (nucleotide types can be converted to dna15 by definition)
75 return seqan3::detail::translation_table<dna15, gc>::value[to_rank(static_cast<dna15>(n1))][to_rank(
76 static_cast<dna15>(n2))][to_rank(static_cast<dna15>(n3))];
77 }
78}
79
80} // namespace seqan3
Provides seqan3::aa27, container aliases and string literals.
The twenty-seven letter amino acid alphabet.
Definition aa27.hpp:43
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition dna15.hpp:48
The four letter DNA alphabet of A,C,G,T.
Definition dna4.hpp:50
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
Provides various transformation traits used by the range module.
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
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides translation details for nucleotide to aminoacid translation.
Genetic codes used for translating a triplet of nucleotides into an amino acid.
Hide me