BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
translation.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <tuple>
17
22
23namespace bio::alphabet
24{
25
26// forwards:
27class dna4;
28class dna5;
29class dna15;
30class rna4;
31class rna5;
32class rna15;
33
53template <genetic_code gc = genetic_code::CANONICAL, nucleotide nucl_type>
54constexpr aa27 translate_triplet(nucl_type const & n1, nucl_type const & n2, nucl_type const & n3) noexcept
55{
57 {
58 // table exists for dna15 and is generated for dna4 and dna5 (compile time ok, because small)
59 return detail::translation_table<nucl_type, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
60 }
62 {
63 using rna2dna_t =
65 dna4,
67 dna5,
69
70 // we can use dna's tables, because ranks are identical
71 return detail::translation_table<rna2dna_t, gc>::VALUE[to_rank(n1)][to_rank(n2)][to_rank(n3)];
72 }
73 else // composites or user defined nucleotide
74 {
75 // we cast to dna15; slightly slower run-time, but lot's of compile time saved for large alphabets.
76 // (nucleotide types can be converted to dna15 by definition)
77 return detail::translation_table<dna15, gc>::VALUE[to_rank(static_cast<dna15>(n1))][to_rank(
78 static_cast<dna15>(n2))][to_rank(static_cast<dna15>(n3))];
79 }
80}
81
84enum class translation_frames : uint8_t
85{
86 FWD_FRAME_0 = 1,
87 FWD_FRAME_1 = 1 << 1,
88 FWD_FRAME_2 = 1 << 2,
89 REV_FRAME_0 = 1 << 3,
90 REV_FRAME_1 = 1 << 4,
91 REV_FRAME_2 = 1 << 5,
97 SIX_FRAME = FWD | REV
98};
99
106{
108 return static_cast<translation_frames>(static_cast<u_t>(lhs) & static_cast<u_t>(rhs));
109}
110
112{
114 return static_cast<translation_frames>(static_cast<u_t>(lhs) | static_cast<u_t>(rhs));
115}
116
118{
120 return static_cast<translation_frames>(static_cast<u_t>(lhs) ^ static_cast<u_t>(rhs));
121}
122
124{
126 return static_cast<translation_frames>(~static_cast<u_t>(lhs));
127}
128
130{
131 lhs = lhs & rhs;
132 return lhs;
133}
134
136{
137 lhs = lhs | rhs;
138 return lhs;
139}
140
142{
143 lhs = lhs ^ rhs;
144 return lhs;
145}
147
148} // namespace bio::alphabet
Provides bio::alphabet::aa27, container aliases and string literals.
The twenty-seven letter amino acid alphabet..
Definition: aa27.hpp:45
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap..
Definition: dna15.hpp:50
The four letter DNA alphabet of A,C,G,T..
Definition: dna4.hpp:49
The five letter DNA alphabet of A,C,G,T and the unknown character N..
Definition: dna5.hpp:50
Resolves to (std::same_as<query_t, other_types> || ...).
Definition: core_language.hpp:74
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
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:54
translation_frames
Specialisation values for single and multiple translation frames.
Definition: translation.hpp:85
@ FWD_REV_0
The first forward and first reverse frame.
@ REV_FRAME_0
The first reverse frame starting at position 0.
@ REV_FRAME_1
The second reverse frame starting at position 1.
@ FWD_REV_2
The first third and third reverse frame.
@ FWD_FRAME_2
The third forward frame starting at position 2.
@ FWD_FRAME_1
The second forward frame starting at position 1.
@ REV_FRAME_2
The third reverse frame starting at position 2.
@ FWD_FRAME_0
The first forward frame starting at position 0.
@ FWD_REV_1
The second forward and second reverse frame.
The alphabet module's namespace.
Definition: aa10li.hpp:23
constexpr translation_frames operator&(translation_frames lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:105
constexpr translation_frames & operator^=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:141
constexpr translation_frames operator^(translation_frames lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:117
constexpr translation_frames & operator&=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:129
constexpr translation_frames operator~(translation_frames lhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:123
constexpr translation_frames & operator|=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:135
constexpr translation_frames operator|(translation_frames lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:111
Provides translation details for nucleotide to aminoacid translation.
Genetic codes used for translating a triplet of nucleotides into an amino acid.
Provides various transformation traits used by the range module.