Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
JC69.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
3/*********************************************************************** * This program is free software; you can
4 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
5 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
6 * *
7 ***************************************************************************/
8
9#ifndef __JC69_H_INCLUDED__
10#define __JC69_H_INCLUDED__
11
13{
14
16{
17 private:
18 int m_t = 0;
19 char m_allelic_state;
20
21 public:
22 cell_JC69(int t) : m_t(t)
23 {
24 }
25 cell_JC69() = default;
26 int time() const
27 {
28 return m_t;
29 }
30 char allelic_state() const
31 {
32 return m_allelic_state;
33 }
34 auto &allelic_state(char a)
35 {
36 m_allelic_state = a;
37 return *this;
38 }
39};
40
41/* @brief Mute allelic states in the Arlequin standard data format.
42 */
44{
45 public:
46 // @typedef typde of the mutational state
47 using state_type = bool;
49 {
50 private:
51 int m_time = 0;
52 state_type m_allelic_state = false;
53
54 public:
55 cell_type(int t) : m_time(t)
56 {
57 }
58 cell_type() = default;
59 int time() const
60 {
61 return m_time;
62 }
63 state_type allelic_state() const
64 {
65 return m_allelic_state;
66 }
67 auto &allelic_state(state_type a)
68 {
69 m_allelic_state = a;
70 return *this;
71 }
72 };
73 /* @brief Sample a new mutational state
74 * @param state the initial mutational state
75 * @param nb_mutations the number of mutational event to simulate
76 * @return the updated mutational state
77 */
78 template <typename UnusedRNG> static bool mute(state_type state, unsigned int nb_mutations, UnusedRNG &)
79 {
80 if (nb_mutations % 2 != 0)
81 {
82 state = !state;
83 }
84 return state;
85 }
86};
87
88/* @brief JC69 mutational kernel
89 */
90class JC69
91{
92 static const std::map<char, std::string> dico;
93
94 public:
95 // @typedef allelic state type
96 using state_type = char;
97 /*
98 * @brief Sample a new mutational state
99 * @param state the initial mutational state
100 * @param nb_mutations the number of mutational events to simulate
101 * @param gen a random number generator
102 * @tparam Generator a random number generator
103 * @return
104 */
105 template <typename Generator> static state_type mute(state_type state, unsigned int nb_mutations, Generator &gen)
106 {
107 assert(dico.find(state) != dico.end());
108 for (unsigned int i = 0; i < nb_mutations; ++i)
109 {
110 std::uniform_int_distribution dist(0, 2);
111 state = dico.at(state)[dist(gen)];
112 }
113 return state;
114 }
115};
116
117} // namespace quetzal::mutation::JC69
118
119// const std::map<char, std::string> quetzal::mutation::JC69::dico = { {'A', "TGC"}, {'T', "ACG"}, {'G', "ATC"}, {'C',
120// "ATG"} };
121
122#endif
Definition JC69.hpp:91
Jukes and Cantor 1969: implest substitution model.
Definition mutation.hpp:20