SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
translation.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
52 template <genetic_code gc = genetic_code::CANONICAL, nucleotide_alphabet nucl_type>
53 constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
54 {
56  {
57  // table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
58  return seqan3::detail::translation_table<nucl_type, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
59  }
61  {
65 
66  // we can use dna's tables, because ranks are identical
67  return seqan3::detail::translation_table<rna2dna_t, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
68  }
69  else // composites or user defined nucleotide
70  {
71  // we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
72  // (nucleotide types can be converted to dna15 by definition)
73  return seqan3::detail::translation_table<dna15, gc>::VALUE[to_rank(static_cast<dna15>(n1))]
74  [to_rank(static_cast<dna15>(n2))]
75  [to_rank(static_cast<dna15>(n3))];
76  }
77 }
78 
98 template <genetic_code gc = genetic_code::CANONICAL, typename tuple_type>
100  requires std::tuple_size<tuple_type>::value == 3 &&
105 constexpr aa27 translate_triplet SEQAN3_DEPRECATED_310 (tuple_type const & input_tuple) noexcept
106 {
107  return translate_triplet(std::get<0>(input_tuple), std::get<1>(input_tuple), std::get<2>(input_tuple));
108 }
109 
129 template <genetic_code gc = genetic_code::CANONICAL, std::ranges::input_range range_type>
133 constexpr aa27 translate_triplet SEQAN3_DEPRECATED_310 (range_type && input_range)
134 {
135  auto n1 = begin(input_range);
136  auto n2 = ++n1;
137  auto n3 = ++n2;
138 
139  assert(n1 != end(input_range));
140  assert(n2 != end(input_range));
141  assert(n3 != end(input_range));
142 
143  return translate_triplet(*n1, *n2, *n3);
144 }
145 
165 template <genetic_code gc = genetic_code::CANONICAL, std::ranges::random_access_range rng_t>
169 constexpr aa27 translate_triplet SEQAN3_DEPRECATED_310 (rng_t && input_range)
170 {
171  assert(input_range.begin() != end(input_range));
172  assert(input_range.begin() + 1 != end(input_range));
173  assert(input_range.begin() + 2 != end(input_range));
174 
175  return translate_triplet(input_range[0], input_range[1], input_range[2]);
176 }
177 
178 } // namespace seqan3
seqan3::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:48
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:142
tuple
translation_details.hpp
Provides translation details for nucleotide to aminoacid translation.
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:53
SEQAN3_DEPRECATED_310
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:185
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
aa27.hpp
Provides seqan3::aa27, container aliases and string literals.
nucleotide_alphabet
A concept that indicates whether an alphabet represents nucleotides.
range.hpp
Provides various transformation traits used by the range module.
seqan3::dna4
The four letter DNA alphabet of A,C,G,T.
Definition: dna4.hpp:47
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
translation_genetic_code.hpp
Genetic codes used for translating a triplet of nucleotides into an amino acid.
seqan3::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:48
std::conditional_t
seqan3::aa27
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:43