Commit d1a04d4c authored by SINDT--BARET Yanis's avatar SINDT--BARET Yanis
Browse files

[Update] Rename + patch

parent db8c4273
......@@ -19,5 +19,5 @@ target_link_libraries(module_lineage PUBLIC aevol)
add_executable(module_anc_stat module_anc_stat.cpp)
target_link_libraries(module_anc_stat PUBLIC aevol)
add_executable(sswm sswm.cpp MutationSswm.cpp)
add_executable(sswm sswm.cpp MutationFactorySswm.cpp)
target_link_libraries(sswm PUBLIC aevol)
\ No newline at end of file
#include "MutationSswm.h"
#include "MutationFactorySswm.h"
#include "AbstractFuzzy_7.h"
#include "AeTime.h"
#include "DnaMutator.h"
#include "Individual_7.h"
#include "JumpingMT.h"
#include "Metadata.h"
#include "MutationDataAdapter.h"
#include "Promoter.h"
#include "Protein_7.h"
#include "Rna_7.h"
#include "MutationDataAdapter.h"
#include "Individual_7.h"
#include "JumpingMT.h"
#include "DnaMutator.h"
#include <algorithm>
#include <chrono>
#include <err.h>
#include <fstream>
#include <utility>
#include <sys/stat.h>
#include <utility>
MutationFactorySswm::MutationFactorySswm(std::shared_ptr<aevol::JumpingMT> prng,
MutationParametersSswm mut_parameters) {
prng_nb = prng; // permet d'eviter d'incrimenter 2 fois
mp_sswm = mut_parameters;
}
MutationFactorySswm::MutationFactorySswm(int seed,
MutationParametersSswm mut_parameters)
: mp_sswm(mut_parameters), prng_nb(seed) {}
bool MutationFactorySswm::is_inversion() {
auto* probs = new double[2]; //
probs[0] = mp_sswm.inversion_rate_; // par défaut [0] = prob de inversion
probs[1] = 1-probs[0];
int nb = prng_nb->roulette_random(probs, 2);
int nb = prng_nb.roulette_random(probs, 2);
return nb == 0; // par defition on 0 = inversion
}
......@@ -41,12 +36,12 @@ aevol::MutationEvent MutationFactorySswm::do_mutation(int dna_lenght) {
// _____ If inversion
if (is_inversion_bool) {
int32_t pos_1, pos_2;
pos_1 = prng_nb->random(dna_lenght);
pos_2 = prng_nb->random(dna_lenght);
pos_1 = prng_nb.random(dna_lenght);
pos_2 = prng_nb.random(dna_lenght);
while (pos_2 == pos_1)
{
pos_2 = prng_nb->random(dna_lenght);
pos_2 = prng_nb.random(dna_lenght);
}
// if (pos_1 == pos_2) return nullptr; // Invert everything <=> Invert nothing!
......@@ -62,7 +57,7 @@ aevol::MutationEvent MutationFactorySswm::do_mutation(int dna_lenght) {
}
// _____If not inversion
else {
int32_t pos = prng_nb->random(dna_lenght);
int32_t pos = prng_nb.random(dna_lenght);
auto mevent = aevol::MutationEvent();
mevent.switch_pos(pos);
// printf("Its a ponctual mutation\n");
......
......@@ -20,11 +20,10 @@ struct MutationParametersSswm {
class MutationFactorySswm {
bool is_inversion();
MutationParametersSswm mp_sswm{};
std::shared_ptr<aevol::JumpingMT> prng_nb;
const MutationParametersSswm mp_sswm;
aevol::JumpingMT prng_nb;
public:
MutationFactorySswm(std::shared_ptr<aevol::JumpingMT> prng,
MutationParametersSswm mut_parameters);
MutationFactorySswm(int seed, MutationParametersSswm mut_parameters);
aevol::MutationEvent do_mutation(int dna_lenght);
......
......@@ -4,12 +4,12 @@
#include "Individual_7.h"
#include "json.hpp"
#include "JumpingMT.h"
#include "MutationSswm.h"
#include "MutationFactorySswm.h"
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <iostream>
using namespace aevol;
using json = nlohmann::json;
......@@ -75,7 +75,7 @@ void from_json(const json& j, Parameters& p) {
}
int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RATE NB_GENERATION NEUTRAL_MUTATION_BOOL
if (argc != 5) {
if (argc != 6 and argc != 5 ) {
printf("!!!\nPlease don't forget to write the json file then the"
" inversion rate, the number of generation"
" and to chose if neutral mutation are selected\n!!!\n");
......@@ -92,6 +92,10 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
const float inversion_rate = std::stof(argv[2]);
const long nb_gen = std::stol(argv[3]);
const std::string if_eq = argv[4];
std::string hikes;
if (argc == 6) {
hikes = argv[5];
}
json inputs;
input_file >> inputs;
......@@ -120,9 +124,6 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
}
FuzzyFactory_7 fuzzyFactory(VECTOR, p.sampling);
auto* target = define_target(gaussians, p.sampling, fuzzyFactory);
JumpingMT prng(p.seed); // générateur de nombre aléatoire à partir d'une seed.
const auto& seq = inputs.at("individual").get<std::string>();
int src_seq_length = seq.length();
......@@ -137,7 +138,6 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
Individual_7* new_indiv = nullptr;
auto* fuzzyFac = &fuzzyFactory;
auto prng_shared_ptr = std::make_shared<aevol::JumpingMT>(prng); // ici on crééer un shared pointeur (le truc a droite permet de faire un shared pointeur)
const int dna_length = individual->dna_->length();
long good_mut = 0;
long neutral_mut = 0;
......@@ -156,19 +156,23 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
underscore +
if_eq +
underscore +
hikes +
underscore +
extension;
std::ofstream output_evol_file(result_evol_file);
output_evol_file << " nb_gen,non_mutant,mutant,mutation" << std::endl;
MutationFactorySswm mutationFactorySswm(prng_shared_ptr, mp);
// Création de la fabrique de mutation, la seed permet d'initialiser le
// générateur de nombre aléatoire interne
MutationFactorySswm mutationFactorySswm(p.seed, mp);
if (not output_evol_file.is_open()) {
fprintf(stderr, "Error, cannot open file %s\n", result_evol_file.c_str()); // utilisation de `fprintf` parmet d'écrire spécifiquement dans le stderr. C'est explicitement une erreur
exit(EXIT_FAILURE);
}
for (int i = 0; i <= nb_gen; i++) {
for (int i = 0; i < nb_gen; i++) {
auto mutationEvent = mutationFactorySswm.do_mutation(dna_length);
new_indiv = new aevol::Individual_7(individual);
new_indiv->dna_->apply_mutation(mutationEvent);
......@@ -187,9 +191,15 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
else if (individual->fitness == new_indiv->fitness and if_eq == "y") {
delete individual;
individual = new_indiv;
output_evol_file << i << "," << individual->fitness << ","
<< new_indiv->fitness << "," << mutationEvent.type()
<< std::endl;
neutral_mut++;
}
else {
output_evol_file << i << "," << individual->fitness << ","
<< new_indiv->fitness << "," << mutationEvent.type()
<< std::endl;
delete new_indiv;
new_indiv = nullptr;
}
......@@ -206,8 +216,15 @@ int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RAT
inputs["individual"] = result;
std::string base_result_file = "sswm_result_";
std::string result_file = base_result_file + nbgen_result_file +
underscore + prob_result_file + underscore + if_eq + underscore +
std::string result_file = base_result_file +
nbgen_result_file +
underscore +
prob_result_file +
underscore +
if_eq +
underscore +
hikes +
underscore +
who_result_file;
std::ofstream output_file(result_file);
output_file << std::setw(2) << inputs << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment