From a9408419f77b8751dc2b25b8d744c82758bc18d6 Mon Sep 17 00:00:00 2001
From: Juliette Luiselli <juliette.luiselli@inria.fr>
Date: Tue, 22 Nov 2022 17:19:32 +0100
Subject: [PATCH] make sure no mutation occurs at the breaking point

---
 src/libaevol/7/DnaMutator.cpp | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/libaevol/7/DnaMutator.cpp b/src/libaevol/7/DnaMutator.cpp
index d8ae17647..20917ac08 100644
--- a/src/libaevol/7/DnaMutator.cpp
+++ b/src/libaevol/7/DnaMutator.cpp
@@ -165,9 +165,14 @@ MutationEvent* DnaMutator::generate_next_mutation(int32_t length) {
         if (pos_1 < pos_2) {
           seqlen = pos_2 - pos_1;
         } else {
-          int32_t tmp1_len = length_ - pos_1;
-          int32_t tmp2_len = pos_2;
-          seqlen = tmp1_len + tmp2_len;
+          #ifdef __EUKARYOTE
+            Utils::exchange(pos_1, pos_2);
+            seqlen = pos_2 - pos_1;
+          #else
+            int32_t tmp1_len = length_ - pos_1;
+            int32_t tmp2_len = pos_2;
+            seqlen = tmp1_len + tmp2_len;
+          #endif
         }
 
       int32_t genome_size_after = length_ + seqlen;
@@ -206,8 +211,13 @@ MutationEvent* DnaMutator::generate_next_mutation(int32_t length) {
       if (pos_1 < pos_2) {
         genome_size_after = length_ - (pos_2 - pos_1);
       } else {
+        #ifdef __EUKARYOTE
+        Utils::exchange(pos_1, pos_2);
+        genome_size_after = length_ - (pos_2 - pos_1);
+        #else
         genome_size_after = length_ - (length_ - pos_1);
         genome_size_after = genome_size_after - pos_2;
+        #endif
       }
       
       // printf("Remove %d %d : LB %d LA %d\n",pos_1,pos_2,length_,genome_size_after);
@@ -226,6 +236,9 @@ MutationEvent* DnaMutator::generate_next_mutation(int32_t length) {
 
     }
     else if (random_value < nb_large_dupl_ + nb_large_del_ + nb_large_trans_) {
+      #ifdef __EUKARYOTE
+      std::cout << "Warning : performing a translocation with a eukaryotic individual"<<std::endl;
+      #endif
       nb_large_trans_--;
 
         if (length_ == 1)
@@ -292,6 +305,7 @@ MutationEvent* DnaMutator::generate_next_mutation(int32_t length) {
       // if (pos_1 == pos_2) return nullptr; // Invert everything <=> Invert nothing!
 
       // Invert the segment that don't contain OriC
+      // Convenient for prokaryotes, absolutely necessary for eukaryotes
       if (pos_1 > pos_2) Utils::exchange(pos_1, pos_2);
 
       mevent = new MutationEvent();
@@ -374,6 +388,12 @@ MutationEvent* DnaMutator::generate_next_mutation(int32_t length) {
 
       if (length_ - nb_pos_to_del < min_genome_length_)
         return nullptr;
+      
+      #ifdef __EUKARYOTE
+      if (pos + nb_pos_to_del > length_){
+        nb_pos_to_del = length_ - pos; // Doing the maximal possible deletion
+      }
+      #endif
 
       length_ = length_ - nb_pos_to_del;
 
-- 
GitLab