diff --git a/README.md b/README.md index f18054be9d47027bfb4d1f5c892c9d55bce0aad4..7bba7923fc98a8c8f731404404a41a1e7df6dc74 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,13 @@ Sont fournis : - le fichier <tt>Main.py</tt> illustrant un exemple d'utilisation de la classe Traj3D, - deux fichiers <tt>.fasta</tt> contenant les séquences de deux plasmides de longueur différente (8 000 dans un cas et 180 000 dans l'autre). + +## Instructions + +Le groupe est composé de Loïc Busson, Claire Zhao, Sandra Ayumi, Rodrigo Kappes, Solal O'Sullivan, Chloé Muller, Gauthier Roy et Carlos Santos Garcia. +Pour utiliser notre algorithme génétique, appeler la fonction main() du fichier algogenetique.py en introduisant le nombre d'individus par générations, le nombre de générations, la probabilité de mutation et le nombre d'individus séléctionnés à chaque itération. L'algorithme évalue les individus sur la séquence de nucléotides choisie. Il affiche aussi la trajectoire de la séquence voulue avec la meilleure table de rotations générée par l'algorithme à la dernière étape. +Les fichiers introduits par nous sont: +- individu.py +- +- algogenetique.py : Rassemble les fonctionnalités des autres algorithmes pour faire tourner l'algorithme génétique et afficher la trajectoire après l'algorithme génétique. +- croisement.py : Fonctions de croisement utilisées pour la génération des enfants au moment de la diff --git a/__pycache__/RotTable.cpython-36.pyc b/__pycache__/RotTable.cpython-36.pyc index a8064bb45dbaad46db289f9e730b7dd816423ae4..459e4374c306aebaf525b830c17f00a8820843ca 100644 Binary files a/__pycache__/RotTable.cpython-36.pyc and b/__pycache__/RotTable.cpython-36.pyc differ diff --git a/algogenetique.py b/algogenetique.py index 8bd3ab469cb73c306a3423f0bf5f499079880190..3c025857a6bdaad65acc70446290e33480716928 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -8,14 +8,14 @@ import croisement from Traj3D import * from random import random import matplotlib.pyplot as plt -import time +import time # Debut du decompte du temps start_time = time.time() - def main(N,tmax,pmutation, proportion): + L=[] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] brin = ''.join(lineList[1:]) @@ -26,7 +26,6 @@ def main(N,tmax,pmutation, proportion): S1.append(int(individu.score)) maximum=int(max(S1)) for i in range(tmax): - #print(i) mini=People.indiv[0].score best=People.indiv[0] People.reproduction(p = proportion, proba_mutation= pmutation) @@ -57,7 +56,7 @@ def main(N,tmax,pmutation, proportion): lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] brin = ''.join(lineList[1:]) -best,People = main(10,10,0.01,5) +best,People = main(200,10,0.01,100) test = Traj3D() test.compute(brin, best.table) test.draw("first_plot") diff --git a/croisement.py b/croisement.py index f582b97adf677ee8b286e66fed052044192acd48..95119ecfe8ad91ea23492e9e9eab8fb3ced18b09 100644 --- a/croisement.py +++ b/croisement.py @@ -23,6 +23,8 @@ ROT_TABLE = {\ def croisement_un_point(parent1, parent2): + '''Croise les tables de rotation des parents pour former deux enfants en respectant les symétries du problème''' + ''' Retourne deux enfants''' enfant1 = Individu(RotTable()) enfant2 = Individu(RotTable()) comp = 0 @@ -58,6 +60,8 @@ def croisement_un_point(parent1, parent2): def croisement_deux_points(parent1, parent2): + ''' Croise les tables de rotationd des deux parents en croisant à deux points et respectant les symétries du problème''' + ''' Retourne deux enfants''' enfant1 = Individu(RotTable()) enfant2 = Individu(RotTable()) comp = 0 diff --git a/first_plot.png b/first_plot.png index e091d954c547a80658df7854ba7835a2e39f1b11..f9294f16e9e6dc29674f763436bc6927a5b6bbb7 100644 Binary files a/first_plot.png and b/first_plot.png differ diff --git a/individu.py b/individu.py index 873d8c5dbfb6ddd61fd975582c59ad1cbcad7164..22f1a4d5b3d158b7a87944d80ba3fed8f3398eed 100644 --- a/individu.py +++ b/individu.py @@ -7,45 +7,50 @@ from random import random P1 = 0.015 class Individu(): - + ''' Un individu est caractérisé par sa table de rotations (individu.table)''' def __init__(self, table): + lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] + brin = ''.join(lineList[1:]) self.table = table lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] self.brin = ''.join(lineList[1:]) #self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA" - self.score = self.evaluate() + self.score = None def evaluate(self): + ''' Evalue le score d'un individu sur un nombre numb_ajout de points''' + + traj = Traj3D() - numb_ajout = 3 + numb_ajout = 6 fisrt_seq = self.brin[0:numb_ajout] last_seq = self.brin[-numb_ajout:] traj.compute(last_seq + self.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] + begining = traj_array[0:2*numb_ajout, 0:3] + end = traj_array[-2*numb_ajout:, 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) + for i in range(numb_ajout): - list_distance += [distance_first_nuc, distance_last_nuc] + nuc_coordonate_beg = begining[i] + nuc_coordonate_end = end[i] + distance_nuc = np.linalg.norm(nuc_coordonate_beg - nuc_coordonate_end, ord=2) + list_distance += [distance_nuc] self.score = max(list_distance) - return max(list_distance) + #return max(list_distance) def mutation(self, proba = P1): + '''Modifie des rotations dans la table des rotations en préservant les symétries''' table_rotations = self.table.rot_table for doublet in table_rotations : for coord in range(3): @@ -83,10 +88,10 @@ class Individu(): # print(individu1.table.rot_table) # individu1.mutation() -# table = RotTable() -# test = Individu(table) -# test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") -# print(test.score) +#table = RotTable() +#test = Individu(table) +#test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") +#print(test.score) # qqun=Individu(RotTable()) diff --git a/inutile.py b/inutile.py deleted file mode 100644 index 420a646fc6e25c17b5aec102de8321736ae1ebaf..0000000000000000000000000000000000000000 --- a/inutile.py +++ /dev/null @@ -1,38 +0,0 @@ -import numpy - -ORIGINAL_ROT_TABLE = {\ - "AA": [35.62, 7.2, -154, 0.06, 0.6, 0],\ - "AC": [34.4, 1.1, 143, 1.3, 5, 0],\ - "AG": [27.7, 8.4, 2, 1.5, 3, 0],\ - "AT": [31.5, 2.6, 0, 1.1, 2, 0],\ - "CA": [34.5, 3.5, -64, 0.9, 34, 0],\ - "CC": [33.67, 2.1, -57, 0.07, 2.1, 0],\ - "CG": [29.8, 6.7, 0, 1.1, 1.5, 0],\ - "CT": [27.7, 8.4, -2, 1.5, 3, 0],\ - "GA": [36.9, 5.3, 120, 0.9, 6, 0],\ - "GC": [40, 5, 180, 1.2, 1.275, 0],\ - "GG": [33.67, 2.1, 57, 0.07, 2.1, 0],\ - "GT": [34.4, 1.1, -143, 1.3, 5, 0],\ - "TA": [36, 0.9, 0, 1.1, 2, 0],\ - "TC": [36.9, 5.3, -120, 0.9, 6, 0],\ - "TG": [34.5, 3.5, 64, 0.9, 34, 0],\ - "TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ - } - -class rotation: - def __init__(self,doublet): - self.x = numpy.random.uniform(low = ORIGINAL_ROT_TABLE[doublet][0] - ORIGINAL_ROT_TABLE[doublet][3], high = ORIGINAL_ROT_TABLE[doublet][0] + ORIGINAL_ROT_TABLE[doublet][3]) - self.y = numpy.random.uniform(low = ORIGINAL_ROT_TABLE[doublet][1] - ORIGINAL_ROT_TABLE[doublet][4], high = ORIGINAL_ROT_TABLE[doublet][1] + ORIGINAL_ROT_TABLE[doublet][4]) - self.z = ORIGINAL_ROT_TABLE[doublet][2] - self.doublet = doublet - -class table_rotation(rotation): - def __init__(self): - self.dict = {doublet : rotation(doublet) for doublet in ORIGINAL_ROT_TABLE} - -table1 = table_rotation() -# 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) -#table1.dict["AA"].x ---> 35.67097790545279 (rotation selon x de AA) \ No newline at end of file diff --git a/population.py b/population.py index 405c73055b5ecf59261c8a1a74f4190ebca5c8e5..28a8700140b4f50e4fbad62f36110da084087edd 100644 --- a/population.py +++ b/population.py @@ -1,4 +1,3 @@ - from random import * from individu import Individu from RotTable import RotTable @@ -14,9 +13,6 @@ 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() - return self def selection_p_best(self,p=None): @@ -207,5 +203,6 @@ def test(): +