SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
translation.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <tuple>
16 
21 
22 namespace seqan3
23 {
24 
25 // forwards:
26 class dna4;
27 class dna5;
28 class dna15;
29 class rna4;
30 class rna5;
31 class rna15;
32 
54 template <genetic_code gc = genetic_code::canonical, nucleotide_alphabet nucl_type>
55 constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
56 {
57  if constexpr (std::same_as<nucl_type, dna4> || std::same_as<nucl_type, dna5> || std::same_as<nucl_type, dna15>)
58  {
59  // table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
60  return seqan3::detail::translation_table<nucl_type, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
61  }
62  else if constexpr (std::same_as<nucl_type, rna4> || std::same_as<nucl_type, rna5> || std::same_as<nucl_type, rna15>)
63  {
64  using rna2dna_t =
66  dna4,
68  dna5,
70 
71  // we can use dna's tables, because ranks are identical
72  return seqan3::detail::translation_table<rna2dna_t, gc>::value[to_rank(n1)][to_rank(n2)][to_rank(n3)];
73  }
74  else // composites or user defined nucleotide
75  {
76  // we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
77  // (nucleotide types can be converted to dna15 by definition)
78  return seqan3::detail::translation_table<dna15, gc>::value[to_rank(static_cast<dna15>(n1))][to_rank(
79  static_cast<dna15>(n2))][to_rank(static_cast<dna15>(n3))];
80  }
81 }
82 
83 } // namespace seqan3
Provides seqan3::aa27, container aliases and string literals.
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:46
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:51
The four letter DNA alphabet of A,C,G,T.
Definition: dna4.hpp:53
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:51
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:55
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: alphabet/concept.hpp:155
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides translation details for nucleotide to aminoacid translation.
Genetic codes used for translating a triplet of nucleotides into an amino acid.