This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Organism.h
166 lines (119 loc) · 4.37 KB
/
Organism.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// ***************************************************************************************************************
//
// Mini-Aevol is a reduced version of Aevol -- An in silico experimental evolution platform
//
// ***************************************************************************************************************
//
// Copyright: See the AUTHORS file provided with the package or <https://gitlab.inria.fr/rouzaudc/mini-aevol>
// Web: https://gitlab.inria.fr/rouzaudc/mini-aevol
// E-mail: See <[email protected]>
// Original Authors : Jonathan Rouzaud-Cornabas
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ***************************************************************************************************************
#pragma once
#include <map>
#include <memory>
#include <set>
#include <zlib.h>
#include <list>
#include <cstdint>
#include "RNA.h"
#include "Protein.h"
#include "Dna.h"
#include "MutationEvent.h"
#include "aevol_constants.h"
/**
* Class that implements an organism and its related DNAs, RNAs, Protein and Phenotype
*/
class Organism {
public:
Organism(int length, Threefry::Gen &&rng);
explicit Organism(const std::shared_ptr<Organism> &clone);
explicit Organism(gzFile backup_file);
~Organism();
void save(gzFile backup_file) const;
void load(gzFile backup_file);
void apply_mutations(const std::list<MutationEvent *> &mutation_list);
void reset_mutation_stats();
void compute_protein_stats();
void locate_promoters();
void evaluate(const double* target);
// Printings
void print_info();
using ErrorType = int8_t;
// Map position (int) to Promoter
std::map<int, ErrorType> promoters_;
std::set<int> terminators;
std::vector<RNA *> rnas;
std::vector<Protein *> proteins;
double phenotype[FUZZY_SAMPLING]{};
double delta[FUZZY_SAMPLING]{};
double fitness = 0.0;
double metaerror = 0.0;
Dna *dna_ = nullptr;
int protein_count_ = 0;
int rna_count_ = 0;
// Stats
int nb_genes_activ = 0;
int nb_genes_inhib = 0;
int nb_func_genes = 0;
int nb_non_func_genes = 0;
int nb_coding_RNAs = 0;
int nb_non_coding_RNAs = 0;
int nb_swi_ = 0;
int nb_mut_ = 0;
private:
// Evaluation
void compute_RNA();
void search_start_protein();
void compute_protein();
void translate_protein();
void compute_phenotype();
void compute_fitness(const double* target);
// Mutation
bool do_switch(int pos);
void remove_all_promoters();
void remove_promoters_around(int32_t pos);
void remove_promoters_around(int32_t pos_1, int32_t pos_2);
void remove_promoters_starting_between(int32_t pos_1, int32_t pos_2);
void remove_promoters_starting_after(int32_t pos);
void remove_promoters_starting_before(int32_t pos);
void look_for_new_promoters_around(int32_t pos_1, int32_t pos_2);
void look_for_new_promoters_around(int32_t pos);
void look_for_new_promoters_starting_between(int32_t pos_1, int32_t pos_2);
void look_for_new_promoters_starting_after(int32_t pos);
void look_for_new_promoters_starting_before(int32_t pos);
void add_new_promoter(int32_t position, int8_t error);
static inline int32_t mod(int32_t a, int32_t b) {
assert(b > 0);
while (a < 0) a += b;
while (a >= b) a -= b;
return a;
//return m >= 0 ? m % n : ( n - abs ( m%n ) ) % n;
}
static inline int64_t mod(int64_t a, int64_t b) {
assert(b > 0);
while (a < 0) a += b;
while (a >= b) a -= b;
return a;
//return m >= 0 ? m % n : ( n - abs ( m%n ) ) % n;
}
int loop_back(int &position) const {
if (position >= dna_->length_)
position -= dna_->length_;
return position;
}
};