diff --git a/RotTable.py b/RotTable.py index b7ee23ff6e100598381eb52c8fdceb34a1f53689..59c56c883954a8dc8bbe47493845fbf4f655ae72 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 380d40297e6d82986ca90d5a499f67c062807a61..ae4d55652fe55994a4bd9578f00b52272e7fc6c3 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