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__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc index 64b41c9070f8c3bcccf58f1c80d64aa9e723cf13..0665bddc8d3fe8aeea7fabbae0d2c01f9aaae884 100644 Binary files a/__pycache__/RotTable.cpython-37.pyc and b/__pycache__/RotTable.cpython-37.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/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc index 5bcb4d8418f4525b71a8bb56bf694fb3e384bafb..a2a274a976ce1c2947d34c190976cd65879f2491 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 deleted file mode 100644 index 40c376d68717c46fb59d812ec0e07760c3dfa49e..0000000000000000000000000000000000000000 Binary files a/__pycache__/individu.cpython-37.pyc and /dev/null differ diff --git a/algogenetique.py b/algogenetique.py index 2dab902ae6d3fb5d5936b82b2d06d8621ccb46ff..81da80b77b9edfbb0a7e5a89350883ae4085f9c9 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(6,8,0.01,2) +main(100,100,0.1,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 667f973bb5f8e0e32e57e9e6f5a70652259a01a7..f243bfaba7e6bb7c22cc5c5eb3949ffbf0302d8f 100644 --- a/individu.py +++ b/individu.py @@ -1,7 +1,7 @@ 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 @@ -10,27 +10,36 @@ 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 = [] + + 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] + + 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) - first_nucleotide = traj_array[0, 0:3] - last_nucleotide = traj_array[-1, 0:3] - distance = sqrt(sum((first_nucleotide - last_nucleotide) ** 2)) + list_distance += [distance_first_nuc, distance_last_nuc] - first_name = brin[0] - last_name = brin[-1] - #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)) + self.score = 1/max(list_distance) - self.score = 1/distance + return 1/distance def mutation(self, proba = P1): @@ -58,7 +67,7 @@ class Individu(): # 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) +# 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/population.py b/population.py index 9d8b171aa909eaa341897efb77fe206d7d5e1f39..559bebbe83e60dab6a55747e9a11f189d99dae0d 100644 --- a/population.py +++ b/population.py @@ -64,8 +64,7 @@ class Population: 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) non_vu = [i for i in range(0, self.n)] @@ -155,7 +154,7 @@ 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) @@ -164,10 +163,12 @@ class Population: 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") @@ -186,8 +187,6 @@ def test(): #test() - -