Skip to content
Snippets Groups Projects
Commit ddaee6a7 authored by Nihama Sandra Ayumi's avatar Nihama Sandra Ayumi
Browse files

croisement loop corrected

parents 46d399ae c2f171cc
No related branches found
No related tags found
No related merge requests found
......@@ -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
No preview for this file type
......@@ -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")
......
......@@ -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
......
first_plot.png

2.35 KiB | W: | H:

first_plot.png

2.35 KiB | W: | H:

first_plot.png
first_plot.png
first_plot.png
first_plot.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -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())
......
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 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():
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment