diff --git a/.vscode/settings.json b/.vscode/settings.json index 395ba2d31e295f66eef5e2bd3db334975a462037..31e7ddfdf3472dbdd1b04dd753c498bc2995fd54 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "python.pythonPath": "D:\\Programmes\\Anaconda3\\python.exe" + "python.pythonPath": "/Users/gauthierroy/anaconda3/bin/python" } \ No newline at end of file diff --git a/RotTable.py b/RotTable.py index 912cbb001760b2ced0c934ca28b8f7aefec53628..9f841efe35b5e7de98443db1b6948ec1a040ef33 100644 --- a/RotTable.py +++ b/RotTable.py @@ -99,6 +99,7 @@ class RotTable: ################### -table1 = RotTable() +#table1 = RotTable() +#print(table1.orta()) # print(table1.rot_table) diff --git a/Traj3D.py b/Traj3D.py index eee71819327b28c570771dcdca2b603043a014b9..92cc9720555ee8c29c954b2ea9a40cfc814917aa 100644 --- a/Traj3D.py +++ b/Traj3D.py @@ -65,3 +65,9 @@ class Traj3D: ax.plot(x,y,z) plt.show() plt.savefig(filename) + +# from RotTable import RotTable +# table = RotTable() +# test = Traj3D() +# test.compute("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA", table) +# test.draw("first_plot") \ No newline at end of file diff --git a/__pycache__/RotTable.cpython-36.pyc b/__pycache__/RotTable.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a8064bb45dbaad46db289f9e730b7dd816423ae4 Binary files /dev/null and b/__pycache__/RotTable.cpython-36.pyc differ diff --git a/__pycache__/Traj3D.cpython-36.pyc b/__pycache__/Traj3D.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b5c1da4e7f16d56be5828446b2f8423d03027c1c Binary files /dev/null and b/__pycache__/Traj3D.cpython-36.pyc differ diff --git a/algogenetique.py b/algogenetique.py index cbcde6366a75846200845f298aabc3b3588fda1c..8a1874e03d214a4c3f2f9804b275af26d35d8f5e 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -16,30 +16,23 @@ def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): brin = ''.join(lineList[1:])''' L=[] People=Population(N) - # afficher(People) for i in range(tmax): - print("\n \n NOUVELLE GENERATION \n \n") + print(i) max=0 best=None - for individu in People.indiv: - individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") People.reproduction(p = proportion, proba_mutation= pmutation) - # 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 - afficher(People) L.append(max) - #print(L) + plt.plot([i for i in range(tmax)], L) plt.show() return(best) -main(10,50,0,5) +main(100,100,0,50) diff --git a/sample.png b/first_plot.png similarity index 96% rename from sample.png rename to first_plot.png index e091d954c547a80658df7854ba7835a2e39f1b11..0e536fb530ea40bc82a9395940755ad27a030609 100644 Binary files a/sample.png and b/first_plot.png differ diff --git a/individu.py b/individu.py index 3ef8ae652a28fe19037ae25fad68465ad44a22bb..24193810b0c780eb4bc09bdd034a82094d59f376 100644 --- a/individu.py +++ b/individu.py @@ -1,38 +1,45 @@ from RotTable import RotTable from Traj3D import Traj3D import numpy as np -from math import sqrt +from math import sqrt, inf from random import random P1 = 0.015 class Individu(): - - def __init__(self, table): self.table = table - self.score = None + self.score = self.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") def evaluate(self, brin): traj = Traj3D() - traj.compute(brin, self.table) + + numb_ajout = 3 + + fisrt_seq = brin[0:numb_ajout] + last_seq = brin[-numb_ajout:] + + traj.compute(last_seq + brin + fisrt_seq, self.table) traj_array = np.array(traj.getTraj()) + list_distance = [] - first_nucleotide = traj_array[0, 0:3] - last_nucleotide = traj_array[-1, 0:3] - distance = sqrt(sum((first_nucleotide - last_nucleotide) ** 2)) + for i in range(numb_ajout): + first_nuc_coordonate = traj_array[numb_ajout+i, 0:3] + first_nuc_coordonate_compute = traj_array[-(numb_ajout-i), 0:3] + + last_nuc_coordonate = traj_array[-(2*numb_ajout-i), 0:3] + last_nuc_coordonate_compute = traj_array[i, 0:3] - first_name = brin[0] - last_name = brin[-1] + distance_first_nuc = np.linalg.norm(first_nuc_coordonate - first_nuc_coordonate_compute, ord=2) + distance_last_nuc = np.linalg.norm(last_nuc_coordonate - last_nuc_coordonate_compute, ord=2) - #rot_computed = self.table.rot_table[last_name+first_name] - #rot_traj = first_nucleotide - last_nucleotide - # print(rot_traj) - # print(rot_computed) - #diff_angle = sum(abs(rot_computed - rot_traj)) + list_distance += [distance_first_nuc, distance_last_nuc] - self.score = 1/distance + + self.score = 1/max(list_distance) + + return 1/max(list_distance) def mutation(self, proba = P1): @@ -57,4 +64,10 @@ class Individu(): # table = RotTable() # test = Individu(table) # test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") -# print(test.score) \ No newline at end of file +# print(test.score) + + +# qqun=Individu(RotTable()) +# qqun.table.rot_table={'AA': [35.576558502141, 7.433901511509349, -154], 'AC': [33.22048222654215, 5.25191751302917, 143], 'AG': [26.446029097301288, 6.052240462237622, -2], 'AT': [30.47045254036881, 1.333716025628036, 0], 'CA': [34.00734209585039, 33.70710613604862, -64], 'CC': [33.61019622767888, 3.713127032109607, -57], 'CG': [29.664061041382677, 6.725155507162601, 0], 'CT': [26.446029097301288, 6.052240462237622, 2], 'GA': [36.655773481637176, 10.45337581740701, 120], 'GC': [42.26984493493484, 3.5310453395352823, 180], 'GG': [33.61019622767888, 3.713127032109607, -57], 'GT': [33.22048222654215, 5.25191751302917, 143], 'TA': [36.951508786388914, -2.5174751178033303, 0], 'TC': [36.655773481637176, 10.45337581740701, -120], 'TG': [34.00734209585039, 33.70710613604862, -64], 'TT': [35.576558502141, 7.433901511509349, -154]} +# qqun.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") +# print(qqun.score) diff --git a/inutile.py b/inutile.py index 1a2947e5d6d776eaab4c42387fcd36f075272bea..420a646fc6e25c17b5aec102de8321736ae1ebaf 100644 --- a/inutile.py +++ b/inutile.py @@ -31,7 +31,7 @@ class table_rotation(rotation): self.dict = {doublet : rotation(doublet) for doublet in ORIGINAL_ROT_TABLE} table1 = table_rotation() -print(table1.dict["AA"].x) +# print(table1.dict["AA"].x) #table1.dict --> {'AA': <__main__.rotation object at 0x000001A722E1BAC8>, 'AC': <__main__.rotation object at 0x000001A722E1BB00>, 'AG': <__main__.rotation object at 0x000001A729A66A58>, 'AT': <__main__.rotation object at 0x000001A729A66A20>, 'CA': <__main__.rotation object at 0x000001A729A669E8>, 'CC': <__main__.rotation object at 0x000001A729A66A90>, 'CG': <__main__.rotation object at 0x000001A729A66B00>, 'CT': <__main__.rotation object at 0x000001A729A66B70>, 'GA': <__main__.rotation object at 0x000001A729B88D68>, 'GC': <__main__.rotation object at 0x000001A729B88DA0>, 'GG': <__main__.rotation object at 0x000001A729B88DD8>, 'GT': <__main__.rotation object at 0x000001A729B88E10>, 'TA': <__main__.rotation object at 0x000001A729B88E48>, 'TC': <__main__.rotation object at 0x000001A729B88E80>, 'TG': <__main__.rotation object at 0x000001A729B88EB8>, 'TT': <__main__.rotation object at 0x000001A729B88EF0>} #table1.dict["AA"] ---> <__main__.rotation object at 0x000001A722E1BAC8> (qui est l'object rotation) diff --git a/population.py b/population.py index dc51f8c876c286ad1822991da190f5dcf3804b40..828caac54389b4296f47305d41e41a990b3b09dd 100644 --- a/population.py +++ b/population.py @@ -1,8 +1,9 @@ -import random -from random import random, randint, randrange + +from random import * from individu import Individu from RotTable import RotTable from croisement import croisement_un_point, croisement_deux_points +import copy class Population: def __init__(self,n): @@ -13,8 +14,30 @@ class Population: """Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus""" self.n = len(liste_individus) self.indiv = liste_individus + for i in range(0,self.n): + self.indiv[i].evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + return self + def selection_p_best(self,p=None): + if p==None: + p=(self.n)//2 + + 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_individus=self.indiv + tri_rapide(liste_individus) + individus_selectionnes = [element for element in liste_individus[:p]] + self = self.modifier_population(individus_selectionnes) + + def selection_duel_pondere(self,p=None): if p == None : p = (self.n)//2 @@ -45,27 +68,29 @@ class Population: meilleur = self.indiv[0] for individu in self.indiv : if meilleur.score < individu.score: + print("meilleur, individu: ", meilleur.score, individu.score) meilleur = individu newself = [meilleur] - print("\n \n \nmeilleur", meilleur.table.rot_table, "\n \nscore", meilleur.score) vu=set() t=randrange(0,self.n) - m=randrange(0,self.n) + m=randrange(0,self.n) + non_vu = [i for i in range(0, self.n)] while len(newself)<p: - while m in vu: - m=randrange(0,self.n) - while t in vu: - t=randrange(0,self.n) + m = choice(non_vu) + non_vu.remove(m) + t = choice(non_vu) + non_vu.remove(t) + x=self.indiv[m] y=self.indiv[t] - vu.add(t) - vu.add(m) if x.score>=y.score: newself.append(x) else: newself.append(y) self = self.modifier_population(newself) + + def selection_par_rang(self,p = None): if p == None : p = (self.n)//2 @@ -134,19 +159,21 @@ class Population: p = (self.n)//2 vieille_taille = self.n selection(p) - newself = list(self.indiv) + newself = [element for element in self.indiv] while len(newself)<vieille_taille: m=randrange(0,self.n) t=randrange(0,self.n) - x=newself[m] - y=newself[t] + x=copy.deepcopy(newself[m]) + y=copy.deepcopy(newself[t]) couple_enfant = enfant(x,y) for child in couple_enfant : child.mutation(proba_mutation) + child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") 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") @@ -165,8 +192,6 @@ def test(): #test() - -