SeqAn3
The Modern C++ library for sequence analysis.
translation.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
23 #include <seqan3/std/ranges>
25 
26 namespace seqan3
27 {
28 
29 // forwards:
30 class dna4;
31 class dna5;
32 class dna15;
33 class rna4;
34 class rna5;
35 class rna15;
36 
55 template <genetic_code gc = genetic_code::CANONICAL, NucleotideAlphabet nucl_type>
56 constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
57 {
59  {
60  // table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
61  return seqan3::detail::translation_table<nucl_type, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
62  }
64  {
68 
69  // we can use dna's tables, because ranks are identical
70  return seqan3::detail::translation_table<rna2dna_t, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
71  }
72  else // composites or user defined nucleotide
73  {
74  // we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
75  // (nucleotide types can be converted to dna15 by definition)
76  return seqan3::detail::translation_table<dna15, gc>::VALUE[to_rank(static_cast<dna15>(n1))]
77  [to_rank(static_cast<dna15>(n2))]
78  [to_rank(static_cast<dna15>(n3))];
79  }
80 }
81 
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(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 
126 template <genetic_code gc = genetic_code::CANONICAL, std::ranges::InputRange range_type>
130 constexpr aa27 translate_triplet(range_type && input_range)
131 {
132  auto n1 = begin(input_range);
133  auto n2 = ++n1;
134  auto n3 = ++n2;
135 
136  assert(n1 != end(input_range));
137  assert(n2 != end(input_range));
138  assert(n3 != end(input_range));
139 
140  return translate_triplet(*n1, *n2, *n3);
141 }
142 
143 
160 template <genetic_code gc = genetic_code::CANONICAL, std::ranges::RandomAccessRange range_type>
164 constexpr aa27 translate_triplet(range_type && input_range)
165 {
166  assert(input_range.begin() != end(input_range));
167  assert(input_range.begin() + 1 != end(input_range));
168  assert(input_range.begin() + 2 != end(input_range));
169 
170  return translate_triplet(input_range[0], input_range[1], input_range[2]);
171 }
172 
173 } // namespace seqan3
Provides translation details for nucleotide to aminoacid translation.
The four letter DNA alphabet of A,C,G,T.
Definition: dna4.hpp:48
Provides various transformation trait base templates and shortcuts.
Provides various shortcuts for common std::ranges functions.
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:103
Provides seqan3::aa27, container aliases and string literals.
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:48
The main SeqAn3 namespace.
Genetic codes used for translating a triplet of nucleotides into an amino acid.
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:43
A concept that indicates whether an alphabet represents nucleotides.
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:48
Provides seqan3::NucleotideAlphabet.
Adaptations of concepts from the Ranges TS.
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
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:56
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:179