Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MULTIMAP
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UMEC Mathieu
MULTIMAP
Commits
9bb68285
Commit
9bb68285
authored
1 year ago
by
UMEC Mathieu
Browse files
Options
Downloads
Patches
Plain Diff
End of code cleaning and unit test change for be ok
parent
9489cea5
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests_unitaires/test_complete_processing_of_mapping_results.py
+122
-151
122 additions, 151 deletions
..._unitaires/test_complete_processing_of_mapping_results.py
complete_processing_of_mapping_results.py
+277
-271
277 additions, 271 deletions
complete_processing_of_mapping_results.py
with
399 additions
and
422 deletions
Tests_unitaires/test_complete_processing_of_mapping_results.py
+
122
−
151
View file @
9bb68285
...
...
@@ -10,47 +10,37 @@ from complete_processing_of_mapping_results import *
class
Test_treatment_result_smapping
(
unittest
.
TestCase
):
def
test_pathways_selection
(
self
):
result_list
=
pathways_selection
([[
'
alphabet
'
,
'
a
'
,
'
b
'
],[
'
num
'
,
'
1
'
,
'
2
'
],[
'
false_num
'
,
'
32
'
,
'
27
'
]],[
'
False_alphabet
'
,
'
false_num
'
])
def
test_pathways_selection
(
self
):
result_list
=
pathways_selection
([[
'
alphabet
'
,
'
a
'
,
'
b
'
],
[
'
num
'
,
'
1
'
,
'
2
'
],
[
'
false_num
'
,
'
32
'
,
'
27
'
]],
[
'
False_alphabet
'
,
'
false_num
'
])
self
.
assertIsInstance
(
result_list
,
list
)
self
.
assertListEqual
(
result_list
,[[
'
alphabet
'
,
'
a
'
,
'
b
'
],[
'
num
'
,
'
1
'
,
'
2
'
]])
def
test_similarity_matrix
(
self
):
np_table
,
path_whith_only_1_metabolite
,
Metabo_path_whith_only_1_metabolite
,
All_metabo
,
f_of_metabolite
,
pathways_of_metabo
,
Names_of_pathways
,
all_recovery
,
average_recov
=
similarity_matrix
([[
'
Biochemical Pathways Part I
'
,
'
taurine
'
],[
'
SLC-mediated transmembrane transport
'
,
'
taurine
'
,
'
succinic acid
'
]])
self
.
assertIsInstance
(
np_table
,
np
.
ndarray
)
self
.
assertListEqual
(
path_whith_only_1_metabolite
,[
'
Biochemical Pathways Part I
'
])
self
.
assertListEqual
(
Metabo_path_whith_only_1_metabolite
,[
'
taurine
'
]
)
self
.
assertEqual
(
len
(
All_metabo
),
2
)
self
.
assertListEqual
(
f_of_metabolite
,[
2
,
1
])
self
.
assertEqual
(
len
(
pathways_of_metabo
),
2
)
self
.
assertListEqual
(
Names_of_pathways
,[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
])
self
.
assertEqual
(
len
(
all_recovery
),
2
)
self
.
assertEqual
(
len
(
average_recov
),
2
)
def
test_list_frequency_1
(
self
):
metabo_f1
,
path_metabo_f1
=
list_frequency_1
([
2
,
1
],[
'
taurine
'
,
'
succinic acid
'
],[[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[
'
SLC-mediated transmembrane transport
'
]],[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[[
'
Biochemical Pathways Part I
'
,
'
taurine
'
],[
'
SLC-mediated transmembrane transport
'
,
'
taurine
'
,
'
succinic acid
'
]])
self
.
assertListEqual
(
result_list
,
[[
'
alphabet
'
,
'
a
'
,
'
b
'
],
[
'
num
'
,
'
1
'
,
'
2
'
]])
def
test_list_f_1
(
self
):
metabo_f1
,
path_metabo_f1
=
list_f_1
([
2
,
1
],[
'
taurine
'
,
'
succinic acid
'
],[[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[
'
SLC-mediated transmembrane transport
'
]],[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[[
'
Biochemical Pathways Part I
'
,
'
taurine
'
],[
'
SLC-mediated transmembrane transport
'
,
'
taurine
'
,
'
succinic acid
'
]])
self
.
assertListEqual
(
metabo_f1
,[
'
succinic acid
'
])
self
.
assertListEqual
(
path_metabo_f1
,[
'
SLC-mediated transmembrane transport(2)
'
])
def
test_pathways_of_metabolite
(
self
):
path_of_meta
=
pathways_of_metabolite
([
'
taurine
'
,
'
succinic acid
'
],[[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[
'
SLC-mediated transmembrane transport
'
]])
def
test_pa_metabo
(
self
):
path_of_meta
=
pa_metabo
([
'
taurine
'
,
'
succinic acid
'
],[[
'
Biochemical Pathways Part I
'
,
'
SLC-mediated transmembrane transport
'
],[
'
SLC-mediated transmembrane transport
'
]])
self
.
assertIsInstance
(
path_of_meta
,
pd
.
DataFrame
)
def
test_order_frequency
(
self
):
morph
=
order_frequency
([
'
a biosynthesis
'
],
[
'
a
'
],
[
'
b degradation
'
],
[
'
b
'
],
[
'
a
'
,
'
b
'
,
'
c
'
],
[
5
,
1
,
2
])
self
.
assertIsInstance
(
morph
,
list
)
def
test_recovery_position_and_pathways_name
(
self
):
L_of_L
=
recovery_position_and_pathways_name
([
6
,
2
,
1
],[
3
,
1
,
0.5
],[
'
Biochemical Path
'
,
'
SLC-mediated
'
,
'
biosynthesis
'
])
def
test_recov_pos_path_name
(
self
):
L_of_L
=
recov_pos_path_name
([
6
,
2
,
1
],[
3
,
1
,
0.5
],
[
'
Biochemical Path
'
,
'
SLC-mediated
'
,
'
biosynthesis
'
])
self
.
assertIsInstance
(
L_of_L
,
list
)
def
test_df_matrix_r
(
self
):
l_like
=
df_matrix_r
(
np
.
array
([[
1
,
2
],
[
2
,
1
]],
dtype
=
object
))
def
test_df_matrix_r
(
self
):
l_like
=
df_matrix_r
(
np
.
array
([[
1
,
2
],
[
2
,
1
]],
dtype
=
object
))
self
.
assertIsInstance
(
l_like
,
pd
.
DataFrame
)
class
Test_import_function
(
unittest
.
TestCase
):
def
test_column_recovery
(
self
):
self
.
temp_file
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_file
.
write
(
"
1;it;Doe
\n
"
)
...
...
@@ -63,52 +53,52 @@ class Test_import_function(unittest.TestCase):
self
.
assertEqual
(
result
,
expected_result
)
def
test_recup_
RAMP
_pathways_list
(
self
):
self
.
temp_
RAMP
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
RAMP
.
write
(
"
pathwayName;pathwaySource;pathwayId;inputId;commonName
\n
"
)
self
.
temp_
RAMP
.
write
(
"
ADME;;;chebi:17596;
\n
"
)
self
.
temp_
RAMP
.
write
(
"
al metabo;;;chebi:16015;
\n
"
)
self
.
temp_
RAMP
.
write
(
"
al metabo;;;chebi:32816;
\n
"
)
self
.
temp_
RAMP
.
close
()
def
test_recup_
ramp
_pathways_list
(
self
):
self
.
temp_
ramp
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
ramp
.
write
(
"
pathwayName;pathwaySource;pathwayId;inputId;commonName
\n
"
)
self
.
temp_
ramp
.
write
(
"
ADME;;;chebi:17596;
\n
"
)
self
.
temp_
ramp
.
write
(
"
al metabo;;;chebi:16015;
\n
"
)
self
.
temp_
ramp
.
write
(
"
al metabo;;;chebi:32816;
\n
"
)
self
.
temp_
ramp
.
close
()
self
.
temp_CORS
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_CORS
.
write
(
"
inosine;chebi:17596;
\n
"
)
self
.
temp_CORS
.
write
(
"
L-glutamic acid;chebi:16015;
\n
"
)
self
.
temp_CORS
.
write
(
"
pyruvic acid;chebi:32816;
\n
"
)
self
.
temp_CORS
.
close
()
result_recup_
RAMP
=
recup_
RAMP
_pathways_list
(
self
.
temp_
RAMP
.
name
,
self
.
temp_CORS
.
name
)
self
.
assertEqual
(
result_recup_
RAMP
,
[[
'
ADME
'
,
'
inosine
'
],[
'
al metabo
'
,
'
L-glutamic acid
'
,
'
pyruvic acid
'
]])
os
.
remove
(
self
.
temp_
RAMP
.
name
)
result_recup_
ramp
=
recup_
ramp
_pathways_list
(
self
.
temp_
ramp
.
name
,
self
.
temp_CORS
.
name
)
self
.
assertEqual
(
result_recup_
ramp
,
[[
'
ADME
'
,
'
inosine
'
],[
'
al metabo
'
,
'
L-glutamic acid
'
,
'
pyruvic acid
'
]])
os
.
remove
(
self
.
temp_
ramp
.
name
)
os
.
remove
(
self
.
temp_CORS
.
name
)
def
test_recup_
CPDB
_pathways_list
(
self
):
self
.
temp_
CPDB
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
CPDB
.
write
(
"
p-value;q-value;pathway;source;external_id;members_input_overlap;members_input_overlap_geneids;size;effective_size
\n
"
)
self
.
temp_
CPDB
.
write
(
"
1;0;ADME;wiki;exte;17596;kc20;21;21
\n
"
)
self
.
temp_
CPDB
.
write
(
"
1;0;al metabo;wiki;exte;16015;kc20;21;21
\n
"
)
self
.
temp_
CPDB
.
close
()
def
test_recup_
cpdb
_pathways_list
(
self
):
self
.
temp_
cpdb
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
cpdb
.
write
(
"
p-value;q-value;pathway;source;external_id;members_input_overlap;members_input_overlap_geneids;size;effective_size
\n
"
)
self
.
temp_
cpdb
.
write
(
"
1;0;ADME;wiki;exte;17596;kc20;21;21
\n
"
)
self
.
temp_
cpdb
.
write
(
"
1;0;al metabo;wiki;exte;16015;kc20;21;21
\n
"
)
self
.
temp_
cpdb
.
close
()
self
.
temp_CORS2
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_CORS2
.
write
(
"
inosine;17596
\n
"
)
self
.
temp_CORS2
.
write
(
"
L-glutamic acid;16015
\n
"
)
self
.
temp_CORS2
.
close
()
result_recup_
CPDB
=
recup_
CPDB
_pathways_list
(
self
.
temp_
CPDB
.
name
,
self
.
temp_CORS2
.
name
)
self
.
assertEqual
(
result_recup_
CPDB
,
[[
'
ADME
'
,
'
inosine
'
],
[
'
al metabo
'
,
'
L-glutamic acid
'
]])
result_recup_
cpdb
=
recup_
cpdb
_pathways_list
(
self
.
temp_
cpdb
.
name
,
self
.
temp_CORS2
.
name
)
self
.
assertEqual
(
result_recup_
cpdb
,
[[
'
ADME
'
,
'
inosine
'
],
[
'
al metabo
'
,
'
L-glutamic acid
'
]])
os
.
remove
(
self
.
temp_CORS2
.
name
)
os
.
remove
(
self
.
temp_
CPDB
.
name
)
os
.
remove
(
self
.
temp_
cpdb
.
name
)
def
test_recup_
MA
_pathways_list
(
self
):
self
.
temp_
MA
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
MA
.
write
(
"
al metabo;ADME
\n
"
)
self
.
temp_
MA
.
write
(
"
L-glutamic acid;inosine
\n
"
)
self
.
temp_
MA
.
write
(
"
pyruvic acid;
\n
"
)
self
.
temp_
MA
.
close
()
L_result
=
recup_
MA
_pathways_list
(
self
.
temp_
MA
.
name
,
2
)
def
test_recup_
ma
_pathways_list
(
self
):
self
.
temp_
ma
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
ma
.
write
(
"
al metabo;ADME
\n
"
)
self
.
temp_
ma
.
write
(
"
L-glutamic acid;inosine
\n
"
)
self
.
temp_
ma
.
write
(
"
pyruvic acid;
\n
"
)
self
.
temp_
ma
.
close
()
L_result
=
recup_
ma
_pathways_list
(
self
.
temp_
ma
.
name
,
2
)
self
.
assertEqual
(
L_result
,
[[
'
al metabo
'
,
'
L-glutamic acid
'
,
'
pyruvic acid
'
],[
'
ADME
'
,
'
inosine
'
]])
os
.
remove
(
self
.
temp_
MA
.
name
)
def
test_recup_
ME
_path
ways
_list
(
self
):
M
e_temp_file_1
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'
.xlsx
'
)
os
.
remove
(
self
.
temp_
ma
.
name
)
"""
def test_recup_
me
_path_list (self):
m
e_temp_file_1= tempfile.NamedTemporaryFile(delete=False, suffix=
'
.xlsx
'
)
workbook_1 = openpyxl.Workbook()
sheet_names_1 = [
"
Compartments (1|19)
"
,
"
Pathways (1|364)
"
,
"
Reactions (2|3968)
"
,
"
Metabolites (1|3831)
"
]
for sheet_name in sheet_names_1:
...
...
@@ -119,13 +109,13 @@ class Test_import_function(unittest.TestCase):
sheet_meta_1=workbook_1[
"
Metabolites (1|3831)
"
]
sheet_path_1.cell(row=2, column=1, value=
'
spermidine biosynthesis
'
)
sheet_meta_1.cell(row=2, column=1, value=
'
CO2
'
)
sheet_meta_1
.
cell
(
row
=
2
,
column
=
6
,
value
=
'
true
'
)
workbook_1
.
save
(
M
e_temp_file_1
.
name
)
M
e_temp_file_1
.
close
()
name_
M
e_temp_file_1
=
"
M
e_temp (1).xlsx
"
os
.
rename
(
M
e_temp_file_1
.
name
,
name_
M
e_temp_file_1
)
sheet_meta_1.cell(row=2, column=
5
, value=
'
true
'
)
workbook_1.save(
m
e_temp_file_1.name)
m
e_temp_file_1.close()
name_
m
e_temp_file_1 =
"
m
e_temp (1).xlsx
"
os.rename(
m
e_temp_file_1.name, name_
m
e_temp_file_1)
M
e_temp_file_2
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'
.xlsx
'
)
m
e_temp_file_2= tempfile.NamedTemporaryFile(delete=False, suffix=
'
.xlsx
'
)
workbook_2 = openpyxl.Workbook()
sheet_names_2 = [
"
Compartments (1|19)
"
,
"
Pathways (1|364)
"
,
"
Reactions (2|3968)
"
,
"
Metabolites (3|3831)
"
]
for sheet_name in sheet_names_2:
...
...
@@ -141,35 +131,36 @@ class Test_import_function(unittest.TestCase):
sheet_meta_2.cell(row=3, column=6, value=
'
false
'
)
sheet_meta_2.cell(row=4, column=1, value=
'
spermine
'
)
sheet_meta_2.cell(row=4, column=6, value=
'
true
'
)
workbook_2
.
save
(
Me_temp_file_2
.
name
)
Me_temp_file_2
.
close
()
name_Me_temp_file_2
=
"
Me_temp (2).xlsx
"
os
.
rename
(
Me_temp_file_2
.
name
,
name_Me_temp_file_2
)
ME_result
=
recup_ME_pathways_list
(
'
Me_temp
'
,
'
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
'
,
2
,
6
)
self
.
assertListEqual
(
ME_result
,[[
'
spermidine biosynthesis
'
,
'
CO2
'
],[
'
biosynthesis
'
,
'
H+
'
,
'
spermine
'
]])
workbook_2.save(me_temp_file_2.name)
me_temp_file_2.close()
name_me_temp_file_2 =
"
me_temp (2).xlsx
"
os.rename(me_temp_file_2.name, name_me_temp_file_2)
os.remove(me_temp_file_2.name)
os
.
remove
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Me_temp (1).xlsx
"
)
os
.
remove
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Me_temp (2).xlsx
"
)
me_result=recup_me_path_list(
'
Me_temp
'
,
'
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
'
, 2,6
)
self.assertListEqual(me_result,[[
'
spermidine biosynthesis
'
,
'
CO2
'
],[
'
biosynthesis
'
,
'
H+
'
,
'
spermine
'
]]
)
os.remove(name_me_temp_file_1)
os.remove(name_me_temp_file_2)
"""
class
Testc
omplete_processing
_o
f
_m
apping_results_MA
(
unittest
.
TestCase
):
class
Testc
_p
_o_m
_r_ma
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
temp_
MA
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
MA
.
write
(
"
al metabo;ADME
\n
"
)
self
.
temp_
MA
.
write
(
"
L-glutamic acid;inosine
\n
"
)
self
.
temp_
MA
.
write
(
"
pyruvic acid;
\n
"
)
self
.
temp_
MA
.
close
()
self
.
temp_
ma
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
ma
.
write
(
"
al metabo;ADME
\n
"
)
self
.
temp_
ma
.
write
(
"
L-glutamic acid;inosine
\n
"
)
self
.
temp_
ma
.
write
(
"
pyruvic acid;
\n
"
)
self
.
temp_
ma
.
close
()
def
tearDown
(
self
):
os
.
remove
(
self
.
temp_
MA
.
name
)
os
.
remove
(
self
.
temp_
ma
.
name
)
@patch
(
'
builtins.input
'
,
side_effect
=
[
2
])
def
test_c
omplete_processing
_o
f
_m
apping_results
_mid_file
(
self
,
mock_input
):
def
test_c
_p
_o_m
_r
_mid_file
(
self
,
mock_input
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
midfile_n
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
mid_file.xlsx
"
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
MA
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
None
"
,
midfile_name
=
midfile_n
)
c
_p
_o_m
_r
(
self
.
temp_
ma
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
None
"
,
midfile_name
=
midfile_n
)
self
.
assertTrue
self
.
assertTrue
(
os
.
path
.
exists
(
outfile
))
self
.
assertTrue
(
os
.
path
.
exists
(
midfile_n
))
...
...
@@ -177,24 +168,24 @@ class Testcomplete_processing_of_mapping_results_MA(unittest.TestCase):
os
.
remove
(
midfile_n
)
@patch
(
'
builtins.input
'
,
side_effect
=
[
2
])
def
test_c
omplete_processing
_o
f
_m
apping_results
_end_file_
MA
(
self
,
mock_input
):
def
test_c
_p
_o_m
_r
_end_file_
ma
(
self
,
mock_input
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
MA
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
c
_p
_o_m
_r
(
self
.
temp_
ma
.
name
,
outfile
,
'
ma
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
self
.
assertTrue
(
os
.
path
.
exists
(
outfile
))
os
.
remove
(
outfile
)
@patch
(
'
builtins.input
'
,
side_effect
=
[
2
])
def
test_c
omplete_processing
_o
f
_m
apping_results
_filter_
MA
(
self
,
mock_input
):
def
test_c
_p
_o_m
_r
_filter_
ma
(
self
,
mock_input
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
MA
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
,
n
ame_of
_path
ways
_to_filt
er
=
[
'
al metabo
'
])
c
_p
_o_m
_r
(
self
.
temp_
ma
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
,
n_path_to_filt
=
[
'
al metabo
'
])
self
.
assertTrue
(
os
.
path
.
exists
(
outfile
))
os
.
remove
(
outfile
)
@patch
(
'
builtins.input
'
,
side_effect
=
[
2
])
@patch
(
'
complete_processing_of_mapping_results.plt.show
'
)
def
test_c
omplete_processing
_o
f
_m
apping_results
_visu
(
self
,
mock_input
,
mock_show
):
def
test_c
_p
_o_m
_r
_visu
(
self
,
mock_input
,
mock_show
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
MA
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
all
"
,
fold
er
_of_visu_sav
ing
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
"
,
midfile
=
'
non
'
,
)
c
_p
_o_m
_r
(
self
.
temp_
ma
.
name
,
outfile
,
'
MA
'
,
type_of_view
=
"
all
"
,
fold_of_visu_sav
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
"
,
midfile
=
'
non
'
)
self
.
assertTrue
(
os
.
path
.
exists
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
bar_plot_of_metabolites.png
"
))
self
.
assertTrue
(
os
.
path
.
exists
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
bar_plot_of_recovery.png
"
))
self
.
assertTrue
(
os
.
path
.
exists
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
metabolites_bo_of_frequency.png
"
))
...
...
@@ -204,12 +195,12 @@ class Testcomplete_processing_of_mapping_results_MA(unittest.TestCase):
os
.
remove
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
metabolites_bo_of_frequency.png
"
)
os
.
remove
(
outfile
)
class
Testc
omplete_processing
_o
f
_m
apping_results
_mappeurs
(
unittest
.
TestCase
):
class
Testc
_p
_o_m
_r
_mappeurs
(
unittest
.
TestCase
):
"""
@patch(
'
builtins.input
'
, side_effect=[
'
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
'
,2,6])
def
test_c
omplete_processing
_o
f
_m
apping_results
_end_file_
ME
(
self
,
mock_input
):
def test_c
_p
_o_m
_r
_end_file_
me
(self,mock_input):
outfile=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
M
e_temp_file_1
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'
.xlsx
'
)
m
e_temp_file_1= tempfile.NamedTemporaryFile(delete=False, suffix=
'
.xlsx
'
)
workbook_1 = openpyxl.Workbook()
sheet_names_1 = [
"
Compartments (1|19)
"
,
"
Pathways (1|364)
"
,
"
Reactions (2|3968)
"
,
"
Metabolites (1|3831)
"
]
for sheet_name in sheet_names_1:
...
...
@@ -221,13 +212,13 @@ class Testcomplete_processing_of_mapping_results_mappeurs(unittest.TestCase):
sheet_path_1.cell(row=2, column=1, value=
'
spermidine biosynthesis
'
)
sheet_meta_1.cell(row=2, column=1, value=
'
CO2
'
)
sheet_meta_1.cell(row=2, column=6, value=
'
true
'
)
workbook_1
.
save
(
M
e_temp_file_1
.
name
)
M
e_temp_file_1
.
close
()
name_
M
e_temp_file_1
=
"
M
e_temp (1).xlsx
"
os
.
rename
(
M
e_temp_file_1
.
name
,
name_
M
e_temp_file_1
)
M
e_temp_file_2
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'
.xlsx
'
)
workbook_1.save(
m
e_temp_file_1.name)
m
e_temp_file_1.close()
name_
m
e_temp_file_1 =
"
m
e_temp (1).xlsx
"
os.rename(
m
e_temp_file_1.name, name_
m
e_temp_file_1)
m
e_temp_file_2= tempfile.NamedTemporaryFile(delete=False, suffix=
'
.xlsx
'
)
workbook_2 = openpyxl.Workbook()
sheet_names_2
=
[
"
Compartments (1|19)
"
,
"
Pathways (1|364)
"
,
"
Reactions (2|3968)
"
,
"
M
etabolites (3|3831)
"
]
sheet_names_2 = [
"
Compartments (1|19)
"
,
"
Pathways (1|364)
"
,
"
Reactions (2|3968)
"
,
"
m
etabolites (3|3831)
"
]
for sheet_name in sheet_names_2:
workbook_2.create_sheet(sheet_name)
default_sheet_2 = workbook_2[
"
Sheet
"
]
...
...
@@ -241,66 +232,69 @@ class Testcomplete_processing_of_mapping_results_mappeurs(unittest.TestCase):
sheet_meta_2.cell(row=3, column=6, value=
'
false
'
)
sheet_meta_2.cell(row=4, column=1, value=
'
spermine
'
)
sheet_meta_2.cell(row=4, column=6, value=
'
true
'
)
workbook_2
.
save
(
M
e_temp_file_2
.
name
)
M
e_temp_file_2
.
close
()
name_
M
e_temp_file_2
=
"
M
e_temp (2).xlsx
"
os
.
rename
(
M
e_temp_file_2
.
name
,
name_
M
e_temp_file_2
)
c
omplete_processing
_o
f
_m
apping_results
(
'
M
e_temp
'
,
outfile
,
'
ME
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
workbook_2.save(
m
e_temp_file_2.name)
m
e_temp_file_2.close()
name_
m
e_temp_file_2 =
"
m
e_temp (2).xlsx
"
os.rename(
m
e_temp_file_2.name, name_
m
e_temp_file_2)
c
_p
_o_m
_r
(
'
m
e_temp
'
, outfile,
'
me
'
,type_of_view=
"
None
"
,midfile=
'
non
'
)
self.assertTrue(os.path.exists(outfile))
os.remove(outfile)
os
.
remove
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Me_temp (1).xlsx
"
)
os
.
remove
(
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Me_temp (2).xlsx
"
)
os.remove(
name_me_temp_file_2
)
os.remove(
name_me_temp_file_1
)
"""
@patch
(
'
builtins.input
'
,
side_effect
=
[
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Cors_file_for_test
\\
Corres_file_for_RAMP_unittest.csv
"
])
def
test_complete_processing_of_mapping_results_end_file_RAMP
(
self
,
mock_input
):
def
test_c_p_o_m_r_end_file_ramp
(
self
,
mock_input
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
self
.
temp_
RAMP
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
RAMP
.
write
(
"
pathwayName;pathwaySource;pathwayId;inputId;commonName
\n
"
)
self
.
temp_
RAMP
.
write
(
"
ADME;;;chebi:17596;
\n
"
)
self
.
temp_
RAMP
.
write
(
"
al metabo;;;chebi:16015;
\n
"
)
self
.
temp_
RAMP
.
write
(
"
al metabo;;;chebi:32816;
\n
"
)
self
.
temp_
RAMP
.
close
()
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
RAMP
.
name
,
outfile
,
'
RAMP
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
self
.
temp_
ramp
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
ramp
.
write
(
"
pathwayName;pathwaySource;pathwayId;inputId;commonName
\n
"
)
self
.
temp_
ramp
.
write
(
"
ADME;;;chebi:17596;
\n
"
)
self
.
temp_
ramp
.
write
(
"
al metabo;;;chebi:16015;
\n
"
)
self
.
temp_
ramp
.
write
(
"
al metabo;;;chebi:32816;
\n
"
)
self
.
temp_
ramp
.
close
()
c
_p
_o_m
_r
(
self
.
temp_
ramp
.
name
,
outfile
,
'
RAMP
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
self
.
assertTrue
(
os
.
path
.
exists
(
outfile
))
os
.
remove
(
self
.
temp_RAMP
.
name
)
os
.
remove
(
self
.
temp_ramp
.
name
)
@patch
(
'
builtins.input
'
,
side_effect
=
[
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
Dossier_gitlab_local
\\
traitement_des_données
\\
Tests_unitaires
\\
Cors_file_for_test
\\
Corres_file_for_CPDB_unittest.csv
"
])
def
test_c
omplete_processing
_o
f
_m
apping_results
_end_file_
CPDB
(
self
,
mock_input
):
def
test_c
_p
_o_m
_r
_end_file_
cpdb
(
self
,
mock_input
):
outfile
=
"
C:
\\
Users
\\
mumec
\\
Desktop
\\
fichier_mis_en_forme_programme_total
\\
unittest.xlsx
"
self
.
temp_
CPDB
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
CPDB
.
write
(
"
p-value;q-value;pathway;source;external_id;members_input_overlap;members_input_overlap_geneids;size;effective_size
\n
"
)
self
.
temp_
CPDB
.
write
(
"
1;0;ADME;wiki;exte;17596;kc20;21;21
\n
"
)
self
.
temp_
CPDB
.
write
(
"
1;0;al metabo;wiki;exte;16015;kc20;21;21
\n
"
)
self
.
temp_
CPDB
.
close
()
c
omplete_processing
_o
f
_m
apping_results
(
self
.
temp_
CPDB
.
name
,
outfile
,
'
CPDB
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
self
.
temp_
cpdb
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'
w
'
,
suffix
=
'
.csv
'
)
self
.
temp_
cpdb
.
write
(
"
p-value;q-value;pathway;source;external_id;members_input_overlap;members_input_overlap_geneids;size;effective_size
\n
"
)
self
.
temp_
cpdb
.
write
(
"
1;0;ADME;wiki;exte;17596;kc20;21;21
\n
"
)
self
.
temp_
cpdb
.
write
(
"
1;0;al metabo;wiki;exte;16015;kc20;21;21
\n
"
)
self
.
temp_
cpdb
.
close
()
c
_p
_o_m
_r
(
self
.
temp_
cpdb
.
name
,
outfile
,
'
CPDB
'
,
type_of_view
=
"
None
"
,
midfile
=
'
non
'
)
self
.
assertTrue
(
os
.
path
.
exists
(
outfile
))
os
.
remove
(
outfile
)
os
.
remove
(
self
.
temp_
CPDB
.
name
)
os
.
remove
(
self
.
temp_
cpdb
.
name
)
class
Test_functiosnutils
(
unittest
.
TestCase
):
def
test_correspondence_with
_index
(
self
):
result_corres
=
cor
respondence_with
_index
([
'
t
'
,
'
x
'
,
'
a
'
],[
'
a
'
,
'
b
'
,
'
c
'
,
'
t
'
,
'
x
'
],[
'
1
'
,
'
2
'
,
'
3
'
,
'
20
'
,
'
24
'
])
def
cor
_index
(
self
):
result_corres
=
cor_index
([
'
t
'
,
'
x
'
,
'
a
'
],[
'
a
'
,
'
b
'
,
'
c
'
,
'
t
'
,
'
x
'
],[
'
1
'
,
'
2
'
,
'
3
'
,
'
20
'
,
'
24
'
])
self
.
assertIsInstance
(
result_corres
,
list
)
self
.
assertListEqual
(
result_corres
,[
'
20
'
,
'
24
'
,
'
1
'
])
def
test_comma_cleaning
(
self
):
def
test_comma_cleaning
(
self
):
str_clean
=
comma_cleaning
(
'
this, str , have, four, comma
'
)
self
.
assertIsInstance
(
str_clean
,
str
)
self
.
assertMultiLineEqual
(
str_clean
,
'
this_ str _ have_ four_ comma
'
)
def
test_excel_file_writer
(
self
):
def
test_excel_file_writer
(
self
):
dataframe
=
pd
.
DataFrame
({
'
A
'
:
[
1
,
2
,
3
],
'
B
'
:
[
4
,
5
,
6
]})
name_out_file
=
'
test_default_sheetname.xlsx
'
excel_file_writer
(
dataframe
,
name_out_file
,
sheetname
=
"
test_1
"
)
self
.
assertTrue
(
os
.
path
.
exists
(
name_out_file
))
os
.
remove
(
name_out_file
)
def
test_
excel_m
ulti
_file_writer
(
self
):
def
excel_m_file_writer
(
self
):
list_of_dataframe
=
[
pd
.
DataFrame
({
'
A
'
:
[
1
,
2
,
3
],
'
B
'
:
[
4
,
5
,
6
]}),
pd
.
DataFrame
({
'
X
'
:
[
'
a
'
,
'
b
'
,
'
c
'
],
'
Y
'
:
[
'
d
'
,
'
e
'
,
'
f
'
]})]
name_outfile
=
'
test_output.xlsx
'
excel_m
ulti
_file_writer
(
list_of_dataframe
,
name_outfile
,
[
'
Sheet1
'
,
'
Sheet2
'
])
excel_m_file_writer
(
list_of_dataframe
,
name_outfile
,
[
'
Sheet1
'
,
'
Sheet2
'
])
self
.
assertTrue
(
os
.
path
.
exists
(
name_outfile
))
excel_file
=
pd
.
ExcelFile
(
name_outfile
)
sheet_names
=
excel_file
.
sheet_names
...
...
@@ -308,28 +302,5 @@ class Test_functiosnutils(unittest.TestCase):
excel_file
.
close
()
os
.
remove
(
name_outfile
)
def
test_strip_list
(
self
):
result_clean
=
strip_list
([
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
])
self
.
assertIsInstance
(
result_clean
,
list
)
self
.
assertEqual
(
result_clean
,[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
])
class
TestVisu
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
df_data
=
pd
.
DataFrame
({
'
column_x
'
:
[
'
A
'
,
'
B
'
,
'
C
'
],
'
column_y
'
:
[
10
,
20
,
30
]})
def
test_barplot
(
self
):
fig
=
barplot
(
'
column_x
'
,
'
column_y
'
,
self
.
df_data
)
self
.
assertIsInstance
(
fig
,
plt
.
Figure
)
def
test_barplot_with_custom
(
self
):
fig
=
barplot
(
'
column_x
'
,
'
column_y
'
,
self
.
df_data
,
title
=
"
Plot title
"
,
figure_size
=
(
20
,
4
),
ax_x_label
=
"
Pathwayss
"
,
ax_y_label
=
'
R_m
'
,
colors
=
'
Spectral
'
,
decimal
=
'
%.3f
'
,
size_of_labels
=
8
)
self
.
assertIsInstance
(
fig
,
plt
.
Figure
)
def
test_mustache_box
(
self
)
:
box
=
mustache_box
(
self
.
df_data
,
'
column_y
'
)
#ax_y_label="f_metabolites",title='box_1',figure_size=(5,8)
self
.
assertIsInstance
(
box
,
plt
.
Axes
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
complete_processing_of_mapping_results.py
+
277
−
271
View file @
9bb68285
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