Skip to content
Snippets Groups Projects
Commit 69e8a061 authored by Santos Garcia Carlos's avatar Santos Garcia Carlos
Browse files

minimiser distance, histogrammes et brin affiché

parent d6b865f7
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -8,32 +8,59 @@ import croisement ...@@ -8,32 +8,59 @@ import croisement
from Traj3D import * from Traj3D import *
from random import random from random import random
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time
# Debut du decompte du temps
start_time = time.time()
def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"):
'''lineList = [line.rstrip('\n') for line in open(brin)] def main(N,tmax,pmutation, proportion):
brin = ''.join(lineList[1:])'''
L=[] L=[]
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
People=Population(N) People=Population(N)
S1=[]
for individu in People.indiv:
individu.evaluate(brin)
S1.append(int(individu.score))
maximum=int(max(S1))
for i in range(tmax): for i in range(tmax):
print(i) print(i)
max=0 mini=People.indiv[0].score
best=None best=People.indiv[0]
People.reproduction(p = proportion, proba_mutation= pmutation) People.reproduction(p = proportion, proba_mutation= pmutation)
for individu in People.indiv: for individu in People.indiv:
if individu.score>max: if individu.score<mini:
best=individu best=individu
max=individu.score mini=individu.score
L.append(max) L.append(mini)
plt.subplot(221)
plt.plot([i for i in range(tmax)], L) plt.plot([i for i in range(tmax)], L)
plt.subplot(223)
plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red')
S2=[individu.score for individu in People.indiv]
print("Score final: ",best.score)
plt.subplot(224)
plt.hist(S2, range = (0,maximum+10), bins = 20, color = 'blue')
plt.show() plt.show()
return(best,People)
return(best,People)
best,People = main(100,100,0.01,50) lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
best,People = main(10,10,0.01,5)
test = Traj3D() test = Traj3D()
test.compute("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA", best.table) test.compute(brin, best.table)
test.draw("first_plot") test.draw("first_plot")
# Affichage du temps d execution
print("Temps d'execution : %s secondes " % (time.time() - start_time))
...@@ -37,9 +37,9 @@ class Individu(): ...@@ -37,9 +37,9 @@ class Individu():
list_distance += [distance_first_nuc, distance_last_nuc] list_distance += [distance_first_nuc, distance_last_nuc]
self.score = 1/max(list_distance) self.score = max(list_distance)
return 1/max(list_distance) return max(list_distance)
def mutation(self, proba = P1): def mutation(self, proba = P1):
......
...@@ -67,7 +67,7 @@ class Population: ...@@ -67,7 +67,7 @@ class Population:
p = (self.n)//2 p = (self.n)//2
meilleur = self.indiv[0] meilleur = self.indiv[0]
for individu in self.indiv : for individu in self.indiv :
if meilleur.score < individu.score: if meilleur.score > individu.score:
print("meilleur, individu: ", meilleur.score, individu.score) print("meilleur, individu: ", meilleur.score, individu.score)
meilleur = individu meilleur = individu
newself = [meilleur] newself = [meilleur]
...@@ -83,7 +83,7 @@ class Population: ...@@ -83,7 +83,7 @@ class Population:
x=self.indiv[m] x=self.indiv[m]
y=self.indiv[t] y=self.indiv[t]
if x.score>=y.score: if x.score<y.score:
newself.append(x) newself.append(x)
else: else:
newself.append(y) newself.append(y)
...@@ -167,8 +167,10 @@ class Population: ...@@ -167,8 +167,10 @@ class Population:
y=copy.deepcopy(newself[t]) y=copy.deepcopy(newself[t])
couple_enfant = enfant(x,y) couple_enfant = enfant(x,y)
for child in couple_enfant : for child in couple_enfant :
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
child.mutation(proba_mutation) child.mutation(proba_mutation)
child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") child.evaluate(brin)
newself.append(couple_enfant[0]) newself.append(couple_enfant[0])
newself.append(couple_enfant[1]) newself.append(couple_enfant[1])
self = self.modifier_population(newself) self = self.modifier_population(newself)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment