diff --git a/.gitignore b/.gitignore index 7e99e367f8443d86e5e8825b9fda39dfbb39630d..09bf5d65f59f67ea5457404e72300a693093ada1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.pyc \ No newline at end of file +*.pyc +__pycache__/ \ No newline at end of file diff --git a/RotTable.py b/RotTable.py index 9a4d2e7b0198f228401b843ca847662948c3ca1a..912cbb001760b2ced0c934ca28b8f7aefec53628 100644 --- a/RotTable.py +++ b/RotTable.py @@ -40,9 +40,21 @@ class RotTable: "TA": "TA",\ "TC": "GA",\ "TG": "CA",\ - "TT": "AA",\ + "TT": "AA"\ } + __SOUS_CORRESPONDANCE = {\ + "AA": "TT",\ + "AC": "GT",\ + "AG": "CT",\ + "AT": "AT",\ + "CA": "TG",\ + "CC": "GG",\ + "CG": "CG",\ + "GA": "TC",\ + "GC": "GC",\ + "TA": "TA"\ + } # get the angles in each axis (x, y, z), considering the deviation def __init__(self): self.rot_table = {} @@ -53,9 +65,11 @@ class RotTable: # get a random deviation, considering the "limits" given in the last 3 columns # of __ORIGINAL_ROT_TABLE def alea(self): - for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: + for dinucleotide in RotTable.__SOUS_CORRESPONDANCE: for i in range(2): - self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) + delta = numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) + self.rot_table[dinucleotide][i] += delta + self.rot_table[RotTable.__SOUS_CORRESPONDANCE[dinucleotide]][i] += delta # return __ORIGINAL_ROT_TABLE def orta(self): @@ -86,6 +100,5 @@ class RotTable: ################### table1 = RotTable() -print(table1.orta()) -print(table1.rot_table["AA"]) +# print(table1.rot_table) diff --git a/__pycache__/croisement.cpython-37.pyc b/__pycache__/croisement.cpython-37.pyc deleted file mode 100644 index 3c0b7814b5726496f728cff297117c1679b51da0..0000000000000000000000000000000000000000 Binary files a/__pycache__/croisement.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/population.cpython-37.pyc b/__pycache__/population.cpython-37.pyc deleted file mode 100644 index cd1f744dd32f7a248c3ae2481fa0bd1243989c5a..0000000000000000000000000000000000000000 Binary files a/__pycache__/population.cpython-37.pyc and /dev/null differ diff --git a/algogenetique.py b/algogenetique.py index 9e681de9dd01d77569355a0ae01139ec8828adbc..fcdb9895d145935e45c1685b2fc0f4ddce2fe373 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -3,19 +3,22 @@ import math import numpy import RotTable from individu import Individu -from population import Population +from population import Population, afficher import croisement from Traj3D import * from random import random import matplotlib.pyplot as plt + def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): '''lineList = [line.rstrip('\n') for line in open(brin)] brin = ''.join(lineList[1:])''' L=[] People=Population(N) + afficher(People) for i in range(tmax): + print("\n \n NOUVELLE GENERATION \n \n") max=0 best=None for individu in People.indiv: diff --git a/croisement.py b/croisement.py index 2bdb485cc5acfb57439e45e856e88296edb25876..96f85a8a89e1dcaa97cbed0f06233942ee36f211 100644 --- a/croisement.py +++ b/croisement.py @@ -18,7 +18,7 @@ ROT_TABLE = {\ "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]\ + "TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ } @@ -26,30 +26,71 @@ def croisement_un_point(parent1, parent2): enfant1 = Individu(RotTable()) enfant2 = Individu(RotTable()) comp = 0 - point_crois= numpy.random.random_integers(0,16) + point_crois= numpy.random.random_integers(0,8) for doublet in ROT_TABLE: + if doublet == "GA": + break if comp < point_crois: enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent1.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent2.table.rot_table[correspondent_doublet2] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + else : enfant1.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent2.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent1.table.rot_table[correspondent_doublet1] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + comp += 1 return enfant1, enfant2 def croisement_deux_points(parent1, parent2): - enfant1 = RotTable() - enfant2 = RotTable() + enfant1 = Individu(RotTable()) + enfant2 = Individu(RotTable()) comp = 0 - point_crois1= numpy.random.random_integers(0,16) - point_crois2= numpy.random.random_integers(0,16) + point_crois1= numpy.random.random_integers(0,8) + point_crois2= numpy.random.random_integers(0,8) for doublet in ROT_TABLE: if comp < min(point_crois1,point_crois2) or comp > max(point_crois1,point_crois2): - enfant1.rot_table[doublet] = parent1.rot_table[doublet] - enfant2.rot_table[doublet] = parent2.rot_table[doublet] + enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent1.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + + enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent2.table.rot_table[correspondent_doublet2] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + else : - enfant1.rot_table[doublet] = parent2.rot_table[doublet] - enfant2.rot_table[doublet] = parent1.rot_table[doublet] + enfant1.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent2.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + + enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent1.table.rot_table[correspondent_doublet1] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 comp += 1 - return enfant1, enfant2 \ No newline at end of file + return enfant1, enfant2 + +# parent1 = Individu(RotTable()) +# parent2 = Individu(RotTable()) +# print("parent1: ", parent1.table.rot_table) +# print("parent2: ", parent2.table.rot_table) +# enfant1, enfant2 = croisement_un_point(parent1, parent2) +# print("enfant1: ", enfant1.table.rot_table) +# print("enfant2: ", enfant2.table.rot_table) \ No newline at end of file diff --git a/individu.py b/individu.py index 5116b5ef465663be26bc96913278830ccde2ad96..3ef8ae652a28fe19037ae25fad68465ad44a22bb 100644 --- a/individu.py +++ b/individu.py @@ -57,4 +57,4 @@ class Individu(): # table = RotTable() # test = Individu(table) # test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") -# print(test.score) +# print(test.score) \ No newline at end of file diff --git a/population.py b/population.py index c16d0101e1233c9ff230563b1ca492f6bf6656fa..7268915b15f592aa862b42b3c6decc53c587020e 100644 --- a/population.py +++ b/population.py @@ -142,6 +142,7 @@ def afficher(popu): for individu in popu.indiv : print("\n individu \n") print(individu.table.rot_table) + print ("score", individu.score) def test(): popu = Population(4)