Skip to content
Snippets Groups Projects
Commit 52c0c5a5 authored by Gauthier Roy's avatar Gauthier Roy
Browse files

work on fitness

parents 0cbbb09b f55549be
Branches
No related tags found
No related merge requests found
......@@ -24,39 +24,45 @@ class RotTable:
"TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\
}
# get the angles in each axis (x, y, z), considering the deviation
def __init__(self):
self.Rot_Table = {}
self.rot_table = {}
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
self.Rot_Table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
self.alea()
# 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 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])
self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3])
# return __ORIGINAL_ROT_TABLE
def orta(self):
return self.__ORIGINAL_ROT_TABLE
###################
# WRITING METHODS #
###################
#table = RotTable()
#table.__Rot_Table["AA"] --> [35.62, 7.2, -154]
#table = RotTable()
#table.rot_table["AA"] --> [35.62, 7.2, -154]
###################
# READING METHODS #
###################
def getTwist(self, dinucleotide):
return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][0]
return self.rot_table[dinucleotide][0]
def getWedge(self, dinucleotide):
return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][1]
return self.rot_table[dinucleotide][1]
def getDirection(self, dinucleotide):
return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][2]
return self.rot_table[dinucleotide][2]
###################
table1 = RotTable()
print(table1.Rot_Table["AA"])
#table1 = RotTable()
#print(table1.orta())
......@@ -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
No preview for this file type
File added
import numpy
from RotTable import RotTable
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]\
}
def croisement_un_point(parent1, parent2):
enfant1 = RotTable()
enfant2 = RotTable()
comp = 0
point_crois= numpy.random.random_integers(0,16)
for doublet in ROT_TABLE:
if comp < point_crois:
enfant1.rot_table[doublet] = parent1.rot_table[doublet]
enfant2.rot_table[doublet] = parent2.rot_table[doublet]
else :
enfant1.rot_table[doublet] = parent2.rot_table[doublet]
enfant2.rot_table[doublet] = parent1.rot_table[doublet]
comp += 1
return enfant1, enfant2
def croisement_deux_points(parent1, parent2):
enfant1 = RotTable()
enfant2 = RotTable()
comp = 0
point_crois1= numpy.random.random_integers(0,16)
point_crois2= numpy.random.random_integers(0,16)
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]
else :
enfant1.rot_table[doublet] = parent2.rot_table[doublet]
enfant2.rot_table[doublet] = parent1.rot_table[doublet]
comp += 1
return enfant1, enfant2
\ No newline at end of file
first_plot.png

2.36 KiB

File moved
test.py 0 → 100644
import random
class Population:
def __init__(self,n):
self.indiv=[Individu(rot_table.alea) for k in range (n)]
self.n = n
def selection_duel_pondere(self,p=(self.n)//2):
newself=[]
vu={}
m=None
t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
while len(newself)<p:
while m in vu:
m=random.randrange(0,len(self))
while t in vu:
t=random.randrange(0,len(self))
x=self[m]
y=self[t]
vu.add(t)
vu.add(m)
p=uniform(0,1)
if p>x.score/(x.score+y.score):
newself.append(y)
else:
newself.append(x)
return(newself)
def selection_duel(self,p=(self.n)//2):
newself=[]
vu={}
t=None
m=None
while len(newself)<p:
while m in vu:
m=random.randrange(0,len(self))
while t in vu:
t=random.randrange(0,len(self))
x=self[m]
y=self[t]
vu.add(t)
vu.add(m)
if x.score<=y.score:
newself.append(x)
else:
newself.append(y)
return(newself)
def selection_par_rang(self, p=(self.n)//2):
liste_individus = self.indiv
n = self.n
def echanger(tableau, i, j):
tableau[i], tableau[j] = tableau[j], tableau[i]
def partitionner(tableau,debut,fin):
echanger(tableau,debut,randint(debut,fin-1))
partition=debut
for i in range(debut+1,fin):
if tableau[i] < tableau[debut]:
if tableau[i].score<tableau[debut].score:
partition+=1
echanger(tableau,i,partition)
echanger(tableau,debut,partition)
return partition
def tri_rapide_aux(tableau,debut,fin):
if debut < fin-1:
positionPivot=partitionner(tableau,debut,fin)
tri_rapide_aux(tableau,debut,positionPivot)
tri_rapide_aux(tableau,positionPivot+1,fin)
def tri_rapide(tableau):
tri_rapide_aux(tableau,0,len(tableau))
tri_rapide(liste_individus)
individus_selectionnes = []
for _ in range(p):
curseur = random()*n*(n+1)/2
# print("curseur", curseur)
j = 1
while j*(j+1)/2 < curseur :
j+=1
#on doit prendre l'individu avec le jème score
# print("individus selectionés", individus_selectionnes)
individus_selectionnes.append(liste[j-1])
def modifier_population(self, liste_individus):
self.n = len(liste_individus)
self.indiv = liste_individus
return self
self = modifier_population(self, individus_selectionnes)
def selection_proportionelle(self,p=(self.n)//2):
newself=[]
somme=0
for indiv in self:
somme=somme+indiv.score
while len(newself)<p:
m=m=random.randrange(0,len(self))
x=self[m]
p=uniform(0,1)
if p<=x.score/somme:
newself.append(x)
return(newself)
def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2):
newself=selection(self,p)
while len(newself)<self.n:
m=random.randrange(0,len(newself))
t=random.randrange(0,len(newself))
x=newself[m]
y=newself[t]
newself.append(enfant(x,y))
return(newself)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment