Skip to content
Snippets Groups Projects
Commit c94f8e67 authored by Busson Loic's avatar Busson Loic
Browse files

merge

parents bf286909 a02fe225
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,26 @@ class RotTable: ...@@ -21,7 +21,26 @@ class RotTable:
"TA": [36, 0.9, 0, 1.1, 2, 0],\ "TA": [36, 0.9, 0, 1.1, 2, 0],\
"TC": [36.9, 5.3, -120, 0.9, 6, 0],\ "TC": [36.9, 5.3, -120, 0.9, 6, 0],\
"TG": [34.5, 3.5, 64, 0.9, 34, 0],\ "TG": [34.5, 3.5, 64, 0.9, 34, 0],\
"TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ "TT": [35.62, 7.2, 154, 0.06, 0.6, 0]\
}
__CORRESPONDANCE = {\
"AA": "TT",\
"AC": "TG",\
"AG": "TC",\
"AT": "TA",\
"CA": "GT",\
"CC": "GG",\
"CG": "GC",\
"CT": "GA",\
"GA": "CT",\
"GC": "CG",\
"GG": "CC",\
"GT": "CA",\
"TA": "AT",\
"TC": "AG",\
"TG": "AC",\
"TT": "AA",\
} }
# get the angles in each axis (x, y, z), considering the deviation # get the angles in each axis (x, y, z), considering the deviation
...@@ -41,6 +60,9 @@ class RotTable: ...@@ -41,6 +60,9 @@ class RotTable:
# return __ORIGINAL_ROT_TABLE # return __ORIGINAL_ROT_TABLE
def orta(self): def orta(self):
return self.__ORIGINAL_ROT_TABLE return self.__ORIGINAL_ROT_TABLE
def corr(self):
return self.__CORRESPONDANCE
################### ###################
# WRITING METHODS # # WRITING METHODS #
......
No preview for this file type
File added
File added
File added
import mathutils
import math
import numpy
import RotTable
from individu import Individu
from population import Population
import croisement
from Traj3D import *
from random import random
import matplotlib.pyplot as plt
def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"):
'''lineList = [line.rstrip('\n') for line in open(brin)]
brin = ''.join(lineList[1:])'''
L=[]
People=Population(N)
for i in range(tmax):
max=0
best=None
for individu in People.indiv:
individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
People.reproduction(p = proportion)
for individu in People.indiv:
individu.mutation(pmutation)
for individu in People.indiv:
individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
if individu.score>max:
best=individu
max=individu.score
L.append(max)
print(L)
plt.plot([i for i in range(tmax)], L)
plt.show()
return(individu)
main(100,50,0.015,2)
import numpy import numpy
from RotTable import RotTable from RotTable import RotTable
from individu import Individu
ROT_TABLE = {\ ROT_TABLE = {\
"AA": [35.62, 7.2, -154, 0.06, 0.6, 0],\ "AA": [35.62, 7.2, -154, 0.06, 0.6, 0],\
...@@ -22,17 +23,17 @@ ROT_TABLE = {\ ...@@ -22,17 +23,17 @@ ROT_TABLE = {\
def croisement_un_point(parent1, parent2): def croisement_un_point(parent1, parent2):
enfant1 = RotTable() enfant1 = Individu(RotTable())
enfant2 = RotTable() enfant2 = Individu(RotTable())
comp = 0 comp = 0
point_crois= numpy.random.random_integers(0,16) point_crois= numpy.random.random_integers(0,16)
for doublet in ROT_TABLE: for doublet in ROT_TABLE:
if comp < point_crois: if comp < point_crois:
enfant1.rot_table[doublet] = parent1.rot_table[doublet] enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet]
enfant2.rot_table[doublet] = parent2.rot_table[doublet] enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet]
else : else :
enfant1.rot_table[doublet] = parent2.rot_table[doublet] enfant1.table.rot_table[doublet] = parent2.table.rot_table[doublet]
enfant2.rot_table[doublet] = parent1.rot_table[doublet] enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet]
comp += 1 comp += 1
return enfant1, enfant2 return enfant1, enfant2
......
from RotTable import RotTable from RotTable import RotTable
from Traj3D import * from Traj3D import Traj3D
import numpy as np import numpy as np
from math import sqrt from math import sqrt
from random import random from random import random
...@@ -8,6 +8,8 @@ P1 = 0.015 ...@@ -8,6 +8,8 @@ P1 = 0.015
class Individu(): class Individu():
def __init__(self, table): def __init__(self, table):
self.table = table self.table = table
self.score = None self.score = None
...@@ -24,7 +26,7 @@ class Individu(): ...@@ -24,7 +26,7 @@ class Individu():
first_name = brin[0] first_name = brin[0]
last_name = brin[-1] last_name = brin[-1]
rot_computed = self.table.Rot_Table[last_name+first_name] rot_computed = self.table.rot_table[last_name+first_name]
rot_traj = first_nucleotide - last_nucleotide rot_traj = first_nucleotide - last_nucleotide
# print(rot_traj) # print(rot_traj)
# print(rot_computed) # print(rot_computed)
...@@ -39,10 +41,14 @@ class Individu(): ...@@ -39,10 +41,14 @@ class Individu():
for coord in range(3): for coord in range(3):
tir = random() tir = random()
if tir < proba : if tir < proba :
# print("mutation", doublet, coord)
# print("table", table_rotations[doublet][coord])
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]) 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])
# print("table", table_rotations[doublet][coord]) 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]
# individu1 = Individu(RotTable()) # individu1 = Individu(RotTable())
# print(individu1.table.rot_table) # print(individu1.table.rot_table)
......
import random import random
from random import random, randint, randrange
from individu import Individu
from RotTable import RotTable
from croisement import croisement_un_point, croisement_deux_points
class Population: class Population:
def __init__(self,n): def __init__(self,n):
self.indiv=[Individu(rot_table.alea) for k in range (n)] self.indiv=[Individu(RotTable()) for k in range (n)]
self.n = n self.n = n
def selection_duel_pondere(self,p=(self.n)//2): def modifier_population(self, liste_individus):
"""Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus"""
self.n = len(liste_individus)
self.indiv = liste_individus
return self
def selection_duel_pondere(self,p=None):
if p == None :
p = (self.n)//2
newself=[] newself=[]
vu={} vu=set()
m=None m=randrange(0,self.n)
t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer t=randrange(0,self.n) #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
while len(newself)<p: while len(newself)<p:
while m in vu: while m in vu:
m=random.randrange(0,len(self)) m=randrange(0,self.n)
while t in vu: while t in vu:
t=random.randrange(0,len(self)) t=randrange(0,self.n)
x=self[m] x=self.indiv[m]
y=self[t] y=self.indiv[t]
vu.add(t) vu.add(t)
vu.add(m) vu.add(m)
p=uniform(0,1) p=random()
if p>x.score/(x.score+y.score): if p>x.score/(x.score+y.score):
newself.append(y) newself.append(y)
else: else:
newself.append(x) newself.append(x)
return(newself) self = self.modifier_population(newself)
def selection_duel(self,p=(self.n)//2): def selection_duel(self,p=None):
if p == None :
p = (self.n)//2
newself=[] newself=[]
vu={} vu=set()
t=None t=randrange(0,self.n)
m=None m=randrange(0,self.n)
while len(newself)<p: while len(newself)<p:
while m in vu: while m in vu:
m=random.randrange(0,len(self)) m=randrange(0,self.n)
while t in vu: while t in vu:
t=random.randrange(0,len(self)) t=randrange(0,self.n)
x=self[m] x=self.indiv[m]
y=self[t] y=self.indiv[t]
vu.add(t) vu.add(t)
vu.add(m) vu.add(m)
if x.score<=y.score: if x.score<=y.score:
newself.append(x) newself.append(x)
else: else:
newself.append(y) newself.append(y)
return(newself) self = self.modifier_population(newself)
def selection_par_rang(self, p=(self.n)//2): def selection_par_rang(self,p = None):
if p == None :
p = (self.n)//2
liste_individus = self.indiv liste_individus = self.indiv
n = self.n n = self.n
...@@ -58,7 +74,7 @@ class Population: ...@@ -58,7 +74,7 @@ class Population:
echanger(tableau,debut,randint(debut,fin-1)) echanger(tableau,debut,randint(debut,fin-1))
partition=debut partition=debut
for i in range(debut+1,fin): for i in range(debut+1,fin):
if tableau[i] < tableau[debut]: # if tableau[i] < tableau[debut]:
if tableau[i].score<tableau[debut].score: if tableau[i].score<tableau[debut].score:
partition+=1 partition+=1
echanger(tableau,i,partition) echanger(tableau,i,partition)
...@@ -85,39 +101,59 @@ class Population: ...@@ -85,39 +101,59 @@ class Population:
j+=1 j+=1
#on doit prendre l'individu avec le jème score #on doit prendre l'individu avec le jème score
# print("individus selectionés", individus_selectionnes) # print("individus selectionés", individus_selectionnes)
individus_selectionnes.append(liste[j-1]) individus_selectionnes.append(liste_individus[j-1])
def modifier_population(self, liste_individus):
self.n = len(liste_individus)
self.indiv = liste_individus
return self
self = modifier_population(self, individus_selectionnes) self = self.modifier_population(individus_selectionnes)
def selection_proportionelle(self,p=(self.n)//2): def selection_proportionelle(self,p= None):
if p == None :
p = (self.n)//2
newself=[] newself=[]
somme=0 somme=0
for indiv in self: for indiv in self.indiv:
somme=somme+indiv.score somme=somme+indiv.score
while len(newself)<p: while len(newself)<p:
m=m=random.randrange(0,len(self)) m=m=randrange(0, self.n)
x=self[m] x=self.indiv[m]
p=uniform(0,1) p=random()
if p<=x.score/somme: if p<=x.score/somme:
newself.append(x) newself.append(x)
return(newself) self = self.modifier_population(newself)
def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2): def reproduction(self,selection=None,enfant=croisement_un_point, p = None):
newself=selection(self,p) if selection == None :
while len(newself)<self.n: selection = self.selection_duel
m=random.randrange(0,len(newself)) if p == None :
t=random.randrange(0,len(newself)) p = (self.n)//2
vieille_taille = self.n
selection(p)
newself = list(self.indiv)
while len(newself)<vieille_taille:
m=randrange(0,self.n)
t=randrange(0,self.n)
x=newself[m] x=newself[m]
y=newself[t] y=newself[t]
newself.append(enfant(x,y)) couple_enfant = enfant(x,y)
return(newself) newself.append(couple_enfant[0])
newself.append(couple_enfant[1])
self = self.modifier_population(newself)
def afficher(popu):
for individu in popu.indiv :
print("\n individu \n")
print(individu.table.rot_table)
def test():
popu = Population(4)
print("\n POPULATION INITIALE \n")
for individu in popu.indiv :
individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
afficher(popu)
popu.reproduction(selection = popu.selection_duel)
print("\n REPRODUCTION \n")
afficher(popu)
#test()
......
from random import random
def creer_population(self, liste_individus):
self.n = len(liste_individus)
self.indiv = set(liste_individus)
return self
def selection_par_rang(self, p = n//2):
set_individus = self.indiv
n = self.n
def partitionner(tableau,debut,fin):
echanger(tableau,debut,random.randint(debut,fin-1))
partition=debut
for i in range(debut+1,fin):
if tableau[i].score<tableau[debut].score:
partition+=1
echanger(tableau,i,partition)
echanger(tableau,debut,partition)
return partition
def tri_rapide_aux(tableau,debut,fin):
if debut < fin-1:
positionPivot=partitionner(tableau,debut,fin)
tri_rapide_aux(tableau,debut,positionPivot)
tri_rapide_aux(tableau,positionPivot+1,fin)
def tri_rapide(tableau):
tri_rapide_aux(tableau,0,len(tableau))
liste = list(set_individus)
tri_rapide(liste)
individus_selectionnes = []
for _ in range(p):
curseur = random()*n*(n+1)/2
j = 1
while j*(j+1)/2 < curseur :
j+=1
#on doit prendre l'individu avec le jème score
individus_selectionnes.append(liste[j])
self = creer_population(self, liste_individus)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment