Skip to content
Snippets Groups Projects
Commit 59c403af authored by Kappes Marques Rodrigo's avatar Kappes Marques Rodrigo
Browse files

added everything

parent 7e47e04b
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -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,13 +24,16 @@ 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)
return(best, People)
main(100,100,0,50)
best, People = main(60,100,0.01,20)
traj = Traj3D()
traj.compute(best.brin,best.table)
traj.draw("plot")
......@@ -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.
Finish editing this message first!
Please register or to comment