Antkeeper  0.0.1
codon.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21 
22 namespace genetics {
23 namespace codon {
24 
31 static inline int base_index(char base)
32 {
33  switch (base)
34  {
35  case 'U':
36  case 'T':
37  return 0;
38  case 'C':
39  return 1;
40  case 'A':
41  return 2;
42  case 'G':
43  return 3;
44  }
45 
46  return ~3;
47 }
48 
57 static inline int codon_index(char base1, char base2, char base3)
58 {
59  int i = base_index(base1);
60  int j = base_index(base2);
61  int k = base_index(base3);
62  return (i << 4) | (j << 2) | k;
63 }
64 
65 inline char translate(char base1, char base2, char base3, const char* aas)
66 {
67  int index = codon_index(base1, base2, base3);
68  if (index < 0)
69  return '-';
70  return aas[index];
71 }
72 
73 bool is_start(char base1, char base2, char base3, const char* starts)
74 {
75  char aa = translate(base1, base2, base3, starts);
76  return ((aa != '-') && (aa != '*'));
77 }
78 
79 bool is_stop(char base1, char base2, char base3, const char* aas)
80 {
81  char aa = translate(base1, base2, base3, aas);
82  return (aa == '*');
83 }
84 
85 } // namspace codon
86 } // namespace genetics
char translate(char base1, char base2, char base3, const char *aas)
Translates a codon into an amino acid.
Definition: codon.cpp:65
bool is_stop(char base1, char base2, char base3, const char *aas)
Returns true if a codon is a stop codon.
Definition: codon.cpp:79
bool is_start(char base1, char base2, char base3, const char *starts)
Returns true if a codon is a start codon.
Definition: codon.cpp:73
Genetic algorithms.
Definition: amino-acid.hpp:25