Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP2_Sania_Ayat_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
Ayat Chergui
TP2_Sania_Ayat_SD
Commits
713f9351
Commit
713f9351
authored
2 months ago
by
Ayât Chergui
Browse files
Options
Downloads
Patches
Plain Diff
tp1 plus ou moins fini
parent
637d5f61
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
TP2_hachage/tp_2_miso_mphf.py
+42
-40
42 additions, 40 deletions
TP2_hachage/tp_2_miso_mphf.py
with
42 additions
and
40 deletions
TP2_hachage/tp_2_miso_mphf.py
+
42
−
40
View file @
713f9351
...
...
@@ -41,34 +41,32 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3):
l
=
len
(
set_kmer_courant
)
tableau_principal
=
[
-
1
]
*
(
gamma
*
l
)
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)
# récupérer l'adresse
# si le tableau principal est déjà rempli à l'adresse:
# mettre le kmer dans collision()
#sinon, écrire le hash à l'adresse dans le tableau principal
index
=
abs
(
hash
(
kmer
))
%
(
gamma
*
l
)
if
tableau_principal
[
index
]
!=
-
1
:
collision
.
add
(
kmer
)
else
:
tableau_principal
[
index
]
=
index
tableaux
.
append
(
tableau_principal
)
# 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
mphf
=
[]
grand_tableau
=
[]
for
tableau
in
tableaux
:
grand_tableau
.
extend
(
tableau
)
# expliquer
grand_tableau
.
extend
(
tableau
)
# expliquer
elle va ajouté toute les valeurs du tableau
rangs
=
[]
max_rang
=
0
i
=
0
for
kmer
in
set_kmer
:
pass
# compléter:
# hacher le kmer
# si le hash est dans le grand_tableau
# récupérer son index
# récupérer son rang (utiliser la fonction count())
# ajouter à la mphf [h, rang]
# mettre à jour max_rang
hacher
=
abs
(
hash
(
kmer
))
if
hacher
in
grand_tableau
:
index
=
grand_tableau
.
index
(
hacher
)
rangs
.
append
(
grand_tableau
[:
index
].
count
(
hacher
))
mphf
.
append
([
hacher
,
rangs
[
-
1
]])
max_rang
=
max
(
rangs
)
for
kmer
in
set_kmer_courant
:
#gestion des collisions: expliquer les 3 lignes du dessous
max_rang
+=
1
...
...
@@ -98,35 +96,39 @@ def get_hash_mphf(mphf, kmer):
>>>
0
<=
hash_mphf
<
n
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
):
"""
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.
"""
Crée une table de hachage à partir d
'
un ensemble de k-mers et d
'
une mphf
Return
s:
list: Table de hachage créée à partir
de
s
k-mers
mphf: la mphf
Parameter
s:
set_kmer (set): Ensemble
de k-mers
.
n (int): Taille de la table de hachage.
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
"""
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
Returns:
list: Table de hachage créée à partir des k-mers
mphf: 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):
plt
.
close
()
# dé-commenter quand vous êtes prêts, expliquer les résultats
#
compare_taille(10000,"mphf.png")
compare_taille
(
10000
,
"
mphf.png
"
)
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