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

Merge branch 'rodrigo' of...

parents 847c6d79 59c403af
Branches
No related tags found
No related merge requests found
......@@ -12,12 +12,10 @@ 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):
print(i)
#print(i)
max=0
best=None
People.reproduction(p = proportion, proba_mutation= pmutation)
......@@ -26,10 +24,17 @@ def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"):
best=individu
max=individu.score
L.append(max)
print(i,":",max)
plt.plot([i for i in range(tmax)], L)
plt.show()
return(best,People)
return(best, People)
best, People = main(60,100,0.01,20)
traj = Traj3D()
traj.compute(best.brin,best.table)
traj.draw("plot")
best,People = main(100,100,0.01,50)
......
......@@ -2,7 +2,7 @@ from RotTable import RotTable
from Traj3D import Traj3D
import numpy as np
from math import sqrt, inf
from random import random
from random import random, randrange
P1 = 0.015
......@@ -10,17 +10,20 @@ class Individu():
def __init__(self, table):
self.table = table
self.score = self.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
self.brin = ''.join(lineList[1:])
#self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA"
self.score = self.evaluate()
def evaluate(self, brin):
def evaluate(self):
traj = Traj3D()
numb_ajout = 3
fisrt_seq = brin[0:numb_ajout]
last_seq = brin[-numb_ajout:]
fisrt_seq = self.brin[0:numb_ajout]
last_seq = self.brin[-numb_ajout:]
traj.compute(last_seq + brin + fisrt_seq, self.table)
traj.compute(last_seq + self.brin + fisrt_seq, self.table)
traj_array = np.array(traj.getTraj())
list_distance = []
......@@ -44,10 +47,17 @@ class Individu():
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 :
number_of_mutations = 5
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 :
......
......@@ -15,8 +15,7 @@ class Population:
self.n = len(liste_individus)
self.indiv = liste_individus
for i in range(0,self.n):
self.indiv[i].evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
self.indiv[i].evaluate()
return self
def selection_p_best(self,p=None):
......@@ -68,7 +67,7 @@ class Population:
meilleur = self.indiv[0]
for individu in self.indiv :
if meilleur.score < individu.score:
print("meilleur, individu: ", meilleur.score, individu.score)
#print("meilleur, individu: ", meilleur.score, individu.score)
meilleur = individu
newself = [meilleur]
vu=set()
......@@ -168,7 +167,7 @@ class Population:
couple_enfant = enfant(x,y)
for child in couple_enfant :
child.mutation(proba_mutation)
child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
child.evaluate()
newself.append(couple_enfant[0])
newself.append(couple_enfant[1])
self = self.modifier_population(newself)
......@@ -184,7 +183,7 @@ def test():
popu = Population(4)
print("\n POPULATION INITIALE \n")
for individu in popu.indiv :
individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
individu.evaluate()
afficher(popu)
popu.reproduction(selection = popu.selection_duel)
print("\n REPRODUCTION \n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment