Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP2_sd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julianne Cocq
TP2_sd
Commits
6e6fa735
Commit
6e6fa735
authored
2 months ago
by
Soltane Maxime
Browse files
Options
Downloads
Patches
Plain Diff
construction_mphf
parent
9dfae198
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tp_2_miso_mphf.py
+36
-17
36 additions, 17 deletions
tp_2_miso_mphf.py
with
36 additions
and
17 deletions
tp_2_miso_mphf.py
+
36
−
17
View file @
6e6fa735
...
...
@@ -49,44 +49,64 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3):
tableau_principal
=
[
-
1
]
*
(
gamma
*
l
)
# on parcourt la liste de k_mers
for
kmer
in
set_kmer_courant
:
pass
# compléter
# hacher le k-mer (attention, hash() peut rendre des entiers signés, nous voulons des entiers positifs)
h
=
abs
(
hash
(
kmer
))
# récupérer l'adresse
adresse
=
None
# récupérer l'adresse
/ % = modulo -> ça garantit que la valeur est forcément ajoutée à un endroit du tableau
adresse
=
h
%
len
(
tableau_principal
)
# si le tableau principal est déjà rempli à l'adresse:
if
adresse
:
if
tableau_principal
[
adresse
]
!=
-
1
:
# mettre le kmer dans collision()
collision
.
add
(
h
)
#sinon, écrire le hash à l'adresse dans le tableau principal
else
:
tableau_principal
[
adresse
]
=
h
tableaux
.
append
(
tableau_principal
)
# expliquer
set_kmer_courant
=
collision
.
copy
()
# expliquer
collision
=
set
()
# expliquer
# Ici, tableaux correspond à la structure qui contient les tableaux des différents niveaux
tableaux
.
append
(
tableau_principal
)
# On incorpore à set_kmer_courant, l'ensemble des kmers n'ayant pas été ajouté au tableau principal à cause d'une collision
set_kmer_courant
=
collision
.
copy
()
# On réinitialise collision pour le niveau suivant
collision
=
set
()
# Construction de la MPHF
# On initialise une liste vide qui contiendra la table de hashage finale
mphf
=
[]
# On initialise un tableau vide
grand_tableau
=
[]
# On parcours tous les tableaux dans tableaux (tableaux étant une liste de listes)
for
tableau
in
tableaux
:
grand_tableau
.
extend
(
tableau
)
# expliquer
# On fusionne tous les tableaux un même tableau
grand_tableau
.
extend
(
tableau
)
# on initialise une variable rang qui contiendra les rangs des kmers
rangs
=
[]
# On initialise le rang maximal par 0
max_rang
=
0
#
i
=
0
# On parcours tous les kmers dans set_kmer
for
kmer
in
set_kmer
:
pass
# compléter:
# hacher le kmer
h2
=
abs
(
hash
(
kmer
))
# si le hash est dans le grand_tableau
if
h
in
grand_tableau
:
# récupérer son index
index
=
grand_tableau
[
h
]
# récupérer son rang (utiliser la fonction count())
c
=
grand_tableau
[
0
:
index
].
count
(
-
1
)
rang
=
index
-
c
# ajouter à la mphf [h, rang]
mphf
.
append
((
h
,
rang
))
# mettre à jour max_rang
max_rang
+=
1
for
kmer
in
set_kmer_courant
:
#gestion des collisions: expliquer les 3 lignes du dessous
# On parcourt la liste des kmers restant suite aux collisions
for
kmer
in
set_kmer_courant
:
# On aggrandit max_rang pour chaque valeur ajoutée
max_rang
+=
1
# On attribue une valeur de hashage au kmer
h
=
abs
(
hash
(
kmer
))
# On l'ajoute à la fin du tableau final
mphf
.
append
([
h
,
max_rang
])
return
mphf
...
...
@@ -115,12 +135,8 @@ def get_hash_mphf(mphf, kmer):
pass
# TODO modifier
def
create_hash_table
(
set_kmer
,
n
):
"""
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.
"""
for _ in range(len(index)):
c = grand_tableau.count(-1)chage.
Returns:
list: Table de hachage créée à partir des k-mers
...
...
@@ -181,3 +197,6 @@ def compare_taille(n_max, fichier_sortie):
# dé-commenter quand vous êtes prêts, expliquer les résultats
#compare_taille(10000,"mphf.png")
import
doctest
doctest
.
testmod
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment