diff --git a/__pycache__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc index 20d277d55079d7a6401199aa6d99042a10aacd32..d0d2bee9e71c849781de9a96c497f02788ecaaf7 100644 Binary files a/__pycache__/RotTable.cpython-37.pyc and b/__pycache__/RotTable.cpython-37.pyc differ diff --git a/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc index 3051667333c64564621cb2fe405f2b8ac037b6bd..9f5f20ef7c01a060943e03ea5beaee567c92ae7e 100644 Binary files a/__pycache__/Traj3D.cpython-37.pyc and b/__pycache__/Traj3D.cpython-37.pyc differ diff --git a/__pycache__/individu.cpython-37.pyc b/__pycache__/individu.cpython-37.pyc index 98e1fc46b75b89e6b1481052c1f6d4bf92a9d04c..83b7aac12df9ffd210cc807f63745df4b2a39629 100644 Binary files a/__pycache__/individu.cpython-37.pyc and b/__pycache__/individu.cpython-37.pyc differ diff --git a/algogenetique.py b/algogenetique.py index 7726e23836b7b1aee14371db67c9da0cce462b1e..8bd3ab469cb73c306a3423f0bf5f499079880190 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -22,11 +22,11 @@ def main(N,tmax,pmutation, proportion): People=Population(N) S1=[] for individu in People.indiv: - individu.evaluate(brin) + individu.evaluate() S1.append(int(individu.score)) maximum=int(max(S1)) for i in range(tmax): - print(i) + #print(i) mini=People.indiv[0].score best=People.indiv[0] People.reproduction(p = proportion, proba_mutation= pmutation) @@ -35,6 +35,7 @@ def main(N,tmax,pmutation, proportion): best=individu mini=individu.score L.append(mini) + print(i,":",mini) plt.subplot(221) plt.plot([i for i in range(tmax)], L) diff --git a/individu.py b/individu.py index 20958d3de778f360a6da39856777dffe233336bf..873d8c5dbfb6ddd61fd975582c59ad1cbcad7164 100644 --- a/individu.py +++ b/individu.py @@ -10,17 +10,20 @@ class Individu(): def __init__(self, table): self.table = table - self.score = self.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") - - def evaluate(self, brin): + 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): 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 = [] @@ -56,6 +59,25 @@ class Individu(): #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] # individu1 = Individu(RotTable()) # print(individu1.table.rot_table) diff --git a/population.py b/population.py index 104f66bb97b274d923f7dcf554ea4fe3599ef717..405c73055b5ecf59261c8a1a74f4190ebca5c8e5 100644 --- a/population.py +++ b/population.py @@ -15,7 +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 @@ -68,7 +68,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() @@ -170,7 +170,7 @@ class Population: lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] brin = ''.join(lineList[1:]) child.mutation(proba_mutation) - child.evaluate(brin) + child.evaluate() newself.append(couple_enfant[0]) newself.append(couple_enfant[1]) self = self.modifier_population(newself) @@ -186,7 +186,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")