Skip to content
Snippets Groups Projects
individu.py 1.94 KiB
Newer Older
Gauthier Roy's avatar
Gauthier Roy committed
from RotTable import RotTable
Gauthier Roy's avatar
Gauthier Roy committed
import numpy as np
from math import sqrt
Gauthier Roy's avatar
Gauthier Roy committed

class Individu():

Gauthier Roy's avatar
Gauthier Roy committed
    def __init__(self, table):
        self.table = table
Gauthier Roy's avatar
Gauthier Roy committed
        self.score = None
    
    def evaluate(self, brin):
        traj = Traj3D()
Gauthier Roy's avatar
Gauthier Roy committed
        traj.compute(brin, self.table)
Gauthier Roy's avatar
Gauthier Roy committed
        traj_array = np.array(traj.getTraj())

Gauthier Roy's avatar
Gauthier Roy committed
        first_nucleotide = traj_array[0, 0:3]
        last_nucleotide = traj_array[-1, 0:3]
        distance = sqrt(sum((first_nucleotide - last_nucleotide) ** 2))
Gauthier Roy's avatar
Gauthier Roy committed

        first_name = brin[0]
        last_name = brin[-1]

        rot_computed = self.table.rot_table[last_name+first_name]
Gauthier Roy's avatar
Gauthier Roy committed
        rot_traj = first_nucleotide - last_nucleotide
        # print(rot_traj)
        # print(rot_computed)
Gauthier Roy's avatar
Gauthier Roy committed
        diff_angle = sum(abs(rot_computed - rot_traj))

        self.score = 1/(distance + diff_angle)
    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 :
                    table_rotations[doublet][coord] =np.random.uniform(low = self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3], high = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3])
                    doublet2 = self.table.corr()[doublet]
                    if coord = 0 or coord = 1 :
                        table_rotations[doublet2][coord] = table_rotations[doublet][coord]
                    else :
                        #sur l'axe z il y a un moins
                        table_rotations[doublet2][coord] = - table_rotations[doublet][coord]
Muller Sacha's avatar
Muller Sacha committed
# individu1 = Individu(RotTable())
# print(individu1.table.rot_table)
# individu1.mutation()

# table = RotTable()
# test = Individu(table)
# test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
# print(test.score)