Skip to content
Snippets Groups Projects
Commit a7eeb77d authored by Muller Sacha's avatar Muller Sacha
Browse files

creation de la fonction mutation et correction de RotTable et individu.py

parent e65fba6d
Branches
No related tags found
No related merge requests found
...@@ -25,23 +25,23 @@ class RotTable: ...@@ -25,23 +25,23 @@ class RotTable:
} }
def __init__(self): def __init__(self):
self.Rot_Table = {} self.rot_table = {}
for dinucleotide in RotTable.__ORIGINAL_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() self.alea()
def alea(self): def alea(self):
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
for i in range(2): 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 # # WRITING METHODS #
################### ###################
#table = RotTable() #table = RotTable()
#table.__Rot_Table["AA"] --> [35.62, 7.2, -154] #table.rot_table["AA"] --> [35.62, 7.2, -154]
################### ###################
# READING METHODS # # READING METHODS #
...@@ -59,4 +59,4 @@ class RotTable: ...@@ -59,4 +59,4 @@ class RotTable:
################### ###################
table1 = RotTable() table1 = RotTable()
print(table1.Rot_Table["AA"]) print(table1.rot_table["AA"])
from Initialisation import table_rotation from RotTable import RotTable
from Traj3D import * from Traj3D import *
import numpy as np import numpy as np
from math import sqrt from math import sqrt
from random import random
P1 = 0.015
class Individu(): class Individu():
def __init__(self, rot_table): def __init__(self, table):
self.rot_table = rot_table self.table = table
self.score = None self.score = None
def evaluate(self, brin): def evaluate(self, brin):
traj = Traj3D() traj = Traj3D()
traj.compute(brin, self.rot_table) traj.compute(brin, self.table)
traj_array = np.array(traj.getTraj()) traj_array = np.array(traj.getTraj())
first_nucleotide = traj_array[0, :] first_nucleotide = traj_array[0, :]
...@@ -21,16 +24,24 @@ class Individu(): ...@@ -21,16 +24,24 @@ class Individu():
first_name = brin[0] first_name = brin[0]
last_name = brin[-1] 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 rot_traj = first_name - last_name
diff_angle = sum(abs(rot_computed - rot_traj)) diff_angle = sum(abs(rot_computed - rot_traj))
self.score = 1/(distance + diff_angle) self.score = 1/(distance + diff_angle)
# def mutation(self): def mutation(self, proba = P1):
table_rotations = self.table.rot_table
# return mutation for doublet in table_rotations :
for coord in range(3):
individu1 = Individu(table_rotation()) tir = random()
print(individu1.rot_table.dict["AA"].x) if tir < proba :
\ No newline at end of file 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment