Skip to content
Snippets Groups Projects
Commit 713f9351 authored by Ayât Chergui's avatar Ayât Chergui
Browse files

tp1 plus ou moins fini

parent 637d5f61
No related branches found
No related tags found
No related merge requests found
...@@ -41,34 +41,32 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3): ...@@ -41,34 +41,32 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3):
l = len(set_kmer_courant) l = len(set_kmer_courant)
tableau_principal = [-1] * (gamma * l) tableau_principal = [-1] * (gamma * l)
for kmer in set_kmer_courant: for kmer in set_kmer_courant:
pass # compléter index = abs(hash(kmer)) % (gamma*l)
# hacher le k-mer (attention, hash() peut rendre des entiers signés, nous voulons des entiers positifs) if tableau_principal[index]!= -1:
# récupérer l'adresse collision.add(kmer)
# si le tableau principal est déjà rempli à l'adresse: else :
# mettre le kmer dans collision() tableau_principal[index] = index
#sinon, écrire le hash à l'adresse dans le tableau principal
tableaux.append(tableau_principal) # expliquer tableaux.append(tableau_principal) # expliquer
set_kmer_courant = collision.copy() # expliquer set_kmer_courant = collision.copy() # expliquer
collision = set() # expliquer collision = set() # expliquer je pense que c'est pour éliminer les collisoin de même valeurs
# Construction de la MPHF # Construction de la MPHF
mphf = [] mphf = []
grand_tableau = [] grand_tableau = []
for tableau in tableaux: for tableau in tableaux:
grand_tableau.extend(tableau) # expliquer grand_tableau.extend(tableau) # expliquer elle va ajouté toute les valeurs du tableau
rangs = [] rangs = []
max_rang = 0 max_rang = 0
i = 0 i = 0
for kmer in set_kmer: for kmer in set_kmer:
pass # compléter: hacher = abs(hash(kmer))
# hacher le kmer if hacher in grand_tableau :
# si le hash est dans le grand_tableau index = grand_tableau.index(hacher)
# récupérer son index rangs.append(grand_tableau[:index].count(hacher))
# récupérer son rang (utiliser la fonction count()) mphf.append([hacher, rangs[-1]])
# ajouter à la mphf [h, rang] max_rang = max(rangs)
# mettre à jour max_rang
for kmer in set_kmer_courant: #gestion des collisions: expliquer les 3 lignes du dessous for kmer in set_kmer_courant: #gestion des collisions: expliquer les 3 lignes du dessous
max_rang += 1 max_rang += 1
...@@ -98,35 +96,39 @@ def get_hash_mphf(mphf, kmer): ...@@ -98,35 +96,39 @@ def get_hash_mphf(mphf, kmer):
>>> 0 <= hash_mphf < n >>> 0 <= hash_mphf < n
True True
""" """
pass # TODO modifier hacher = abs(hash(kmer))
for h, rang in mphf :
if h == hacher :
return rang
def create_hash_table(set_kmer, n): def create_hash_table(set_kmer, n):
""" """
Crée une table de hachage à partir d'un ensemble de k-mers et d'une mphf Crée une table de hachage à partir d'un ensemble de k-mers et d'une mphf
Parameters:
set_kmer (set): Ensemble de k-mers.
n (int): Taille de la table de hachage.
Returns: Parameters:
list: Table de hachage créée à partir des k-mers set_kmer (set): Ensemble de k-mers.
mphf: la mphf n (int): Taille de la table de hachage.
Examples: Returns:
>>> set_kmer = {'ATCG', 'TGCA', 'GCTA'} list: Table de hachage créée à partir des k-mers
>>> n = 10 mphf: la mphf
>>> tableau = create_hash_table(set_kmer, n)
>>> len(tableau) == n
True
>>> all(kmer in tableau for kmer in set_kmer)
True
"""
pass # TODO modifier
# créer la mphf pour les kmers
# initialiser un tableau de taille n (une liste)
# écrire les kmers aux adresses du tableau données par la mphf
# retourner le tableau et la mphf
Examples:
>>> set_kmer = {'ATCG', 'TGCA', 'GCTA'}
>>> n = 10
>>> tableau = create_hash_table(set_kmer, n)
>>> len(tableau) == n
True
>>> all(kmer in tableau for kmer in set_kmer)
True
"""
mphf = construction_mphf(set_kmer, n)
tableau = n*[None]
for i in set_kmer:
hacher = get_hash_mphf(mphf, i)
if hacher :
tableau[hacher] = i
return tableau, mphf
...@@ -166,4 +168,4 @@ def compare_taille(n_max, fichier_sortie): ...@@ -166,4 +168,4 @@ def compare_taille(n_max, fichier_sortie):
plt.close() plt.close()
# dé-commenter quand vous êtes prêts, expliquer les résultats # dé-commenter quand vous êtes prêts, expliquer les résultats
#compare_taille(10000,"mphf.png") compare_taille(10000,"mphf.png")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment