1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| from Matrice_Cout import *
from Levenshtein import *
from copy import *
compteur = 0
def Alignement(x, y, i, j, T, L):
"""Prend en entrée les deux séquences à aligner,
la matrice des couts,
et la position actuelle dans la matrice des couts
(ligne i, colonne j)
Sortie: liste de listes des alignements optimaux des séquences"""
"""if i != 1:
if j != 1:
if T[i, j] == T[i-1,j-1] + Sub(x[i-2], y[j-2]):
Alignement(x, y, i-1, j-1, T)
elif T[i, j] == T[i-1, j] + Del(x[i-2]):
Alignement(x, y, i-1, j, T)
else:
Alignement(x, y, i, j-1, T)
else:
Alignement(x, y, i-1, 1, T)
else:
if j != 1:
Alignement(x, y, 1, j-1, T)"""
c = [0]*3
#Copie de L
M = deepcopy(L)
if i != 1:
if j != 1:
if T.getitem(i, j) == T.getitem(i-1,j-1) + Sub(x[i-2], y[j-2]):
c[0] = 1
L = M + [[x[i-2], y[j-2]]]
Alignement(x, y, i-1, j-1, T, L)
print L
print "ok1"
elif T.getitem(i, j) == T.getitem(i-1, j) + Del(x[i-2]):
c[1] = 1
if sum(c) == 1:
L = M + [[x[i-2], '-']]
Alignement(x, y, i-1, j, T, L)
print L
else:
compteur += 1
L[compteur] = M + [[x[i-2], '-']]
Alignement(x, y, i-1, j, T, L[compteur])
print L[compteur]
else:
c[2] = 1
if sum(c) == 1:
L = M + [['-', y[j-2]]]
Alignement(x, y, i, j-1, T, L)
print L
print "ok2"
elif sum(c) == 2:
compteur += 1
L[compteur] = M + [['-', y[j-2]]]
Alignement(x, y, i, j-1, T, L[compteur])
print L[compteur]
print "ok3"
else:
compteur += 1
L[compteur] = M + [['-', y[j-2]]]
Alignement(x, y, i, j-1, T, L[compteur])
print L[compteur]
else:
L = M + [[x[i-2], '-']]
Alignement(x, y, i-1, 1, T, L)
print L
else:
if j != 1:
L = M + [['-', y[j-2]]]
Alignement(x, y, 1, j-1, T, L)
print L
return M
if __name__ == "__main__":
seq1 = 'YWCQPGK'
seq2 = 'LAWYQQKPGKA'
m = len(seq1)
n = len(seq2)
T = Matrice_cout(seq1, seq2)
L = Alignement(seq1, seq2, m+1, n+1, T, [])
print L |
Partager