Skip to content
Snippets Groups Projects
individu.py 4.69 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
Gauthier Roy's avatar
Gauthier Roy committed
from math import sqrt, inf
Gauthier Roy's avatar
Gauthier Roy committed

class Individu():
Santos Garcia Carlos's avatar
Santos Garcia Carlos committed
    ''' Un individu est caractérisé par sa table de rotations (individu.table)'''
Gauthier Roy's avatar
Gauthier Roy committed
    def __init__(self, table):
Santos Garcia Carlos's avatar
Santos Garcia Carlos committed
        lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
        brin = ''.join(lineList[1:])
Gauthier Roy's avatar
Gauthier Roy committed
        self.table = table
        lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
        self.brin = ''.join(lineList[1:])
        #self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA"
        self.score = None

    def evaluate(self):
Santos Garcia Carlos's avatar
Santos Garcia Carlos committed
        ''' Evalue le score d'un individu sur un nombre numb_ajout de points'''
Gauthier Roy's avatar
Gauthier Roy committed
        traj = Traj3D()

        numb_ajout = 6
        fisrt_seq = self.brin[0:numb_ajout]
        last_seq = self.brin[-numb_ajout:]
        traj.compute(last_seq + self.brin + fisrt_seq, self.table)
Gauthier Roy's avatar
Gauthier Roy committed
        traj_array = np.array(traj.getTraj())
Gauthier Roy's avatar
Gauthier Roy committed
        list_distance = []

        begining = traj_array[0:2*numb_ajout, 0:3]
        end = traj_array[-2*numb_ajout:, 0:3]
        for i in range(numb_ajout):
                nuc_coordonate_beg = begining[i]
                nuc_coordonate_end = end[i]
                distance_nuc = np.linalg.norm(nuc_coordonate_beg - nuc_coordonate_end, ord=2)
                list_distance += [distance_nuc]
        self.score = max(list_distance)
Muller Sacha's avatar
Muller Sacha committed

        #return max(list_distance)
Muller Sacha's avatar
Muller Sacha committed

Santos Garcia Carlos's avatar
Santos Garcia Carlos committed
        '''Modifie des rotations dans la table des rotations en préservant les symétries'''
        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])
Muller Sacha's avatar
Muller Sacha committed
                    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]
    def mutation_with_numbers(self, proba = P1, number_of_mutations = 5):
        table_rotations = self.table.rot_table
        for i in range(0,number_of_mutations):
            tir = random()
            if tir < proba :
                doubletNumber = randrange(0,8)
                counter = 0
                for doublet in table_rotations:
                    if counter==doubletNumber:
                        break
                    counter+=1
                for coord in range(3):
                    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)
Gauthier Roy's avatar
Gauthier Roy committed
# qqun=Individu(RotTable())
# qqun.table.rot_table={'AA': [35.576558502141, 7.433901511509349, -154], 'AC': [33.22048222654215, 5.25191751302917, 143], 'AG': [26.446029097301288, 6.052240462237622, -2], 'AT': [30.47045254036881, 1.333716025628036, 0], 'CA': [34.00734209585039, 33.70710613604862, -64], 'CC': [33.61019622767888, 3.713127032109607, -57], 'CG': [29.664061041382677, 6.725155507162601, 0], 'CT': [26.446029097301288, 6.052240462237622, 2], 'GA': [36.655773481637176, 10.45337581740701, 120], 'GC': [42.26984493493484, 3.5310453395352823, 180], 'GG': [33.61019622767888, 3.713127032109607, -57], 'GT': [33.22048222654215, 5.25191751302917, 143], 'TA': [36.951508786388914, -2.5174751178033303, 0], 'TC': [36.655773481637176, 10.45337581740701, -120], 'TG': [34.00734209585039, 33.70710613604862, -64], 'TT': [35.576558502141, 7.433901511509349, -154]}
# qqun.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
# print(qqun.score)