From a7eeb77d53d8fa0021800b213a8d250bce0f6e02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chlo=C3=A9=20Muller?= <chloe.muller@student-cs.fr>
Date: Tue, 28 Jan 2020 09:21:13 +0100
Subject: [PATCH] creation de la fonction mutation et correction de RotTable et
 individu.py

---
 RotTable.py | 10 +++++-----
 individu.py | 33 ++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/RotTable.py b/RotTable.py
index b7ee23f..59c56c8 100644
--- a/RotTable.py
+++ b/RotTable.py
@@ -25,23 +25,23 @@ class RotTable:
         }
 
     def __init__(self):
-        self.Rot_Table = {}
+        self.rot_table = {}
         for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
-            self.Rot_Table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
+            self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
         self.alea()
 
     
     def alea(self):
         for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
             for i in range(2):
-                self.Rot_Table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) 
+                self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) 
 
 
     ###################
     # WRITING METHODS #
     ###################
 #table = RotTable()
-#table.__Rot_Table["AA"] --> [35.62, 7.2, -154]
+#table.rot_table["AA"] --> [35.62, 7.2, -154]
 
     ###################
     # READING METHODS #
@@ -59,4 +59,4 @@ class RotTable:
     ###################
 
 table1 = RotTable()
-print(table1.Rot_Table["AA"])
+print(table1.rot_table["AA"])
diff --git a/individu.py b/individu.py
index 380d402..ae4d556 100644
--- a/individu.py
+++ b/individu.py
@@ -1,17 +1,20 @@
-from Initialisation import table_rotation
+from RotTable import RotTable
 from Traj3D import *
 import numpy as np
 from math import sqrt
+from random import random
+
+P1 = 0.015
 
 class Individu():
 
-    def __init__(self, rot_table):
-        self.rot_table = rot_table
+    def __init__(self, table):
+        self.table = table
         self.score = None
     
     def evaluate(self, brin):
         traj = Traj3D()
-        traj.compute(brin, self.rot_table)
+        traj.compute(brin, self.table)
         traj_array = np.array(traj.getTraj())
 
         first_nucleotide = traj_array[0, :]
@@ -21,16 +24,24 @@ class Individu():
         first_name = brin[0]
         last_name = brin[-1]
 
-        rot_computed = self.rot_table[last_name+first_name]
+        rot_computed = self.table[last_name+first_name]
         rot_traj = first_name - last_name
         diff_angle = sum(abs(rot_computed - rot_traj))
 
         self.score = 1/(distance + diff_angle)
         
     
-    # def mutation(self):
-
-    #     return mutation
-
-individu1 = Individu(table_rotation())
-print(individu1.rot_table.dict["AA"].x)
\ No newline at end of file
+    def mutation(self, proba = P1):
+        table_rotations = self.table.rot_table
+        for doublet in table_rotations :
+            for coord in range(3):
+                tir = random()
+                if tir < proba :
+                    print("mutation", doublet, coord)
+                    print("table", table_rotations[doublet][coord])
+                    table_rotations[doublet][coord] =np.random.uniform(low = self.table.__ORIGINAL_ROT_TABLE[doublet][coord] - self.table.__ORIGINAL_ROT_TABLE[doublet][coord + 3], high = self.table.__ORIGINAL_ROT_TABLE[doublet][coord] + self.table.__ORIGINAL_ROT_TABLE[doublet][coord + 3])
+                    print("table", table_rotations[doublet][coord])
+
+individu1 = Individu(RotTable())
+print(individu1.table.rot_table)
+individu1.mutation()
\ No newline at end of file
-- 
GitLab