Skip to content
Snippets Groups Projects
Commit 31abe2cf authored by Muller Sacha's avatar Muller Sacha
Browse files

Merge branch 'master' of...

parents 174bb079 e67c2b9d
Branches
No related tags found
No related merge requests found
...@@ -36,3 +36,13 @@ Sont fournis : ...@@ -36,3 +36,13 @@ Sont fournis :
- le fichier <tt>Main.py</tt> illustrant un exemple d'utilisation de la classe Traj3D, - 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). - 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: Création de la classe Individu (attributs et méthodes) qui permettent de donner un score à chaque table de rotations et l'apparition de mutations.
- population.py: Création de la classe Population. Une population à un attribut "indiv" qui est une liste d'individus, chacun caractérisé par sa table de rotations. Cette classe permet de faire la séléction des individus à garder à chaque itération par de différentes méthodes et d'actualiser la population.
- 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
...@@ -50,6 +50,9 @@ def main(N,tmax,pmutation, proportion, indice_selection, population_initiale, en ...@@ -50,6 +50,9 @@ def main(N,tmax,pmutation, proportion, indice_selection, population_initiale, en
if individu.score<mini: if individu.score<mini:
best=individu best=individu
mini=individu.score mini=individu.score
S2=[individu.score for individu in People.indiv]
avg = sum(S2)/len(S2)
L.append(mini) L.append(mini)
# plt.subplot(221) # plt.subplot(221)
......
...@@ -23,11 +23,14 @@ ROT_TABLE = {\ ...@@ -23,11 +23,14 @@ ROT_TABLE = {\
def croisement_un_point(parent1, parent2): 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()) enfant1 = Individu(RotTable())
enfant2 = Individu(RotTable()) enfant2 = Individu(RotTable())
comp = 0 comp = 0
point_crois= numpy.random.random_integers(0,8) point_crois= numpy.random.random_integers(0,8)
for doublet in ROT_TABLE: list_dinucleotides = sorted(ROT_TABLE)
for doublet in list_dinucleotides:
if doublet == "GA": if doublet == "GA":
break break
if comp < point_crois: if comp < point_crois:
...@@ -57,12 +60,15 @@ def croisement_un_point(parent1, parent2): ...@@ -57,12 +60,15 @@ def croisement_un_point(parent1, parent2):
def croisement_deux_points(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()) enfant1 = Individu(RotTable())
enfant2 = Individu(RotTable()) enfant2 = Individu(RotTable())
comp = 0 comp = 0
point_crois1= numpy.random.random_integers(0,8) point_crois1= numpy.random.random_integers(0,8)
point_crois2= numpy.random.random_integers(0,8) point_crois2= numpy.random.random_integers(0,8)
for doublet in ROT_TABLE: list_dinucleotides = sorted(ROT_TABLE)
for doublet in list_dinucleotides:
if comp < min(point_crois1,point_crois2) or comp > max(point_crois1,point_crois2): if comp < min(point_crois1,point_crois2) or comp > max(point_crois1,point_crois2):
enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet] enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet]
correspondent_doublet1 = enfant1.table.corr()[doublet] correspondent_doublet1 = enfant1.table.corr()[doublet]
......
...@@ -2,12 +2,12 @@ from RotTable import RotTable ...@@ -2,12 +2,12 @@ from RotTable import RotTable
from Traj3D import Traj3D from Traj3D import Traj3D
import numpy as np import numpy as np
from math import sqrt, inf from math import sqrt, inf
from random import random from random import random, choice
P1 = 0.015 P1 = 0.015
class Individu(): class Individu():
''' Un individu est caractérisé par sa table de rotations (individu.table)'''
def __init__(self, table): def __init__(self, table):
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
...@@ -15,9 +15,12 @@ class Individu(): ...@@ -15,9 +15,12 @@ class Individu():
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
self.brin = ''.join(lineList[1:]) self.brin = ''.join(lineList[1:])
#self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA" #self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA"
self.score = self.evaluate() self.score = None
def evaluate(self): def evaluate(self):
''' Evalue le score d'un individu sur un nombre numb_ajout de points'''
traj = Traj3D() traj = Traj3D()
numb_ajout = 6 numb_ajout = 6
...@@ -26,12 +29,12 @@ class Individu(): ...@@ -26,12 +29,12 @@ class Individu():
last_seq = self.brin[-numb_ajout:] last_seq = self.brin[-numb_ajout:]
traj.compute(last_seq + self.brin + fisrt_seq, self.table) traj.compute(last_seq + self.brin + fisrt_seq, self.table)
traj_array = np.array(traj.getTraj()) traj_array = traj.getTraj()
list_distance = [] list_distance = []
begining = traj_array[0:2*numb_ajout, 0:3] begining = traj_array[0:2*numb_ajout]
end = traj_array[-2*numb_ajout:, 0:3] end = traj_array[-2*numb_ajout:]
for i in range(numb_ajout): for i in range(numb_ajout):
...@@ -48,7 +51,7 @@ class Individu(): ...@@ -48,7 +51,7 @@ class Individu():
def mutation(self, proba = P1): def mutation(self, proba = P1):
table_rotations = self.table.rot_table table_rotations = self.table.rot_table
for doublet in table_rotations : for doublet in sorted(table_rotations.keys()) :
for coord in range(3): for coord in range(3):
tir = random() tir = random()
if tir < proba : if tir < proba :
...@@ -60,17 +63,18 @@ class Individu(): ...@@ -60,17 +63,18 @@ class Individu():
#sur l'axe z il y a un moins #sur l'axe z il y a un moins
table_rotations[doublet2][coord] = - table_rotations[doublet][coord] table_rotations[doublet2][coord] = - table_rotations[doublet][coord]
def mutation_with_numbers(self, proba = P1, number_of_mutations = 5): def mutation_with_numbers(self, proba = P1, number_of_mutations = 1):
table_rotations = self.table.rot_table table_rotations = self.table.rot_table
for i in range(0,number_of_mutations): table_rotation_not_seen = [i for i in sorted(table_rotations.keys())]
tir = random() table_rotation_not_seen = table_rotation_not_seen[:8]
if tir < proba :
doubletNumber = randrange(0,8) tir = random()
counter = 0 if tir < proba :
for doublet in table_rotations: for i in range(0,number_of_mutations):
if counter==doubletNumber:
break doublet = choice(table_rotation_not_seen)
counter+=1 table_rotation_not_seen.remove(doublet)
for coord in range(3): 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]) 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] doublet2 = self.table.corr()[doublet]
...@@ -80,6 +84,34 @@ class Individu(): ...@@ -80,6 +84,34 @@ class Individu():
#sur l'axe z il y a un moins #sur l'axe z il y a un moins
table_rotations[doublet2][coord] = - table_rotations[doublet][coord] table_rotations[doublet2][coord] = - table_rotations[doublet][coord]
def mutation_close_values(self, proba = P1, number_of_mutations = 1):
table_rotations = self.table.rot_table
table_rotation_not_seen = [i for i in sorted(table_rotations.keys())]
table_rotation_not_seen = table_rotation_not_seen[:8]
tir = random()
if tir < proba :
for i in range(0,number_of_mutations):
doublet = choice(table_rotation_not_seen)
table_rotation_not_seen.remove(doublet)
for coord in range(3):
value = table_rotations[doublet][coord] + np.random.normal(0, self.table.orta()[doublet][coord + 3]/15)
if value > self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]:
value = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]
elif value < self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3]:
value = self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3]
table_rotations[doublet][coord] = value
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()) # individu1 = Individu(RotTable())
# print(individu1.table.rot_table) # print(individu1.table.rot_table)
# individu1.mutation() # individu1.mutation()
......
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
from random import * from random import *
from individu import Individu from individu import Individu
from RotTable import RotTable from RotTable import RotTable
...@@ -14,9 +13,6 @@ class Population: ...@@ -14,9 +13,6 @@ class Population:
"""Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus""" """Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus"""
self.n = len(liste_individus) self.n = len(liste_individus)
self.indiv = liste_individus self.indiv = liste_individus
for i in range(0,self.n):
self.indiv[i].evaluate()
return self return self
def selection_p_best(self,p=None): def selection_p_best(self,p=None):
...@@ -73,7 +69,7 @@ class Population: ...@@ -73,7 +69,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)
...@@ -142,7 +138,7 @@ class Population: ...@@ -142,7 +138,7 @@ class Population:
for child in couple_enfant : for child in couple_enfant :
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
child.mutation(proba_mutation) child.mutation_close_values(proba_mutation, number_of_mutations = 2)
child.evaluate() child.evaluate()
newself.append(couple_enfant[0]) newself.append(couple_enfant[0])
newself.append(couple_enfant[1]) newself.append(couple_enfant[1])
...@@ -191,5 +187,6 @@ def test2(): ...@@ -191,5 +187,6 @@ def test2():
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment