Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
2174ab50
Commit
2174ab50
authored
Aug 28, 2019
by
VIGNET Pierre
Browse files
Ensure the creation of directories given to argparse
parent
08a118f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/cadbiom_cmd.py
View file @
2174ab50
...
...
@@ -42,8 +42,7 @@ def solutions_search(args):
# Module import
import
solution_search
params
=
args_to_param
(
args
)
solution_search
.
solutions_search
(
params
)
# !
solution_search
.
solutions_search
(
args
)
# !
def
solutions_sort
(
args
):
...
...
@@ -53,8 +52,7 @@ def solutions_sort(args):
# Module import
import
solution_sort
params
=
args_to_param
(
args
)
solution_sort
.
solutions_sort
(
params
[
'path'
])
solution_sort
.
solutions_sort
(
args
[
'path'
])
def
solutions_2_graph
(
args
):
...
...
@@ -67,11 +65,10 @@ def solutions_2_graph(args):
# Module import
import
solution_sort
params
=
args_to_param
(
args
)
solution_sort
.
solutions_2_graph
(
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'chart_file'
],
p
ar
am
s
[
'path'
]
ar
g
s
[
'output'
],
ar
g
s
[
'chart_file'
],
ar
g
s
[
'path'
]
)
...
...
@@ -86,12 +83,11 @@ def solutions_2_json(args):
# Module import
import
solution_sort
params
=
args_to_param
(
args
)
solution_sort
.
solutions_2_json
(
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'chart_file'
],
p
ar
am
s
[
'path'
],
conditions
=
not
p
ar
am
s
[
'no_conditions'
],
# Reverse the param...
ar
g
s
[
'output'
],
ar
g
s
[
'chart_file'
],
ar
g
s
[
'path'
],
conditions
=
not
ar
g
s
[
'no_conditions'
],
# Reverse the param...
)
...
...
@@ -106,11 +102,10 @@ def json_2_interaction_graph(args):
# Module import
import
interaction_graph
params
=
args_to_param
(
args
)
interaction_graph
.
json_2_interaction_graph
(
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'molecules_of_interest'
],
p
ar
am
s
[
'path'
],
ar
g
s
[
'output'
],
ar
g
s
[
'molecules_of_interest'
],
ar
g
s
[
'path'
],
)
...
...
@@ -124,11 +119,10 @@ def solutions_2_common_graph(args):
# Module import
import
solution_sort
params
=
args_to_param
(
args
)
solution_sort
.
solutions_2_common_graph
(
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'chart_file'
],
p
ar
am
s
[
'path'
]
ar
g
s
[
'output'
],
ar
g
s
[
'chart_file'
],
ar
g
s
[
'path'
]
)
...
...
@@ -139,12 +133,11 @@ def solutions_2_occcurrences_matrix(args):
# Module import
import
solution_sort
params
=
args_to_param
(
args
)
solution_sort
.
solutions_2_occcurrences_matrix
(
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'chart_file'
],
p
ar
am
s
[
'path'
],
transposed
=
p
ar
am
s
[
'transpose_csv'
]
ar
g
s
[
'output'
],
ar
g
s
[
'chart_file'
],
ar
g
s
[
'path'
],
transposed
=
ar
g
s
[
'transpose_csv'
]
)
...
...
@@ -157,8 +150,7 @@ def identifiers_mapping(args):
# Module import
import
solution_repr
params
=
args_to_param
(
args
)
solution_repr
.
identifiers_mapping
(
**
params
)
solution_repr
.
identifiers_mapping
(
**
args
)
def
model_comparison
(
args
):
...
...
@@ -170,15 +162,14 @@ def model_comparison(args):
# Module import
import
solution_repr
params
=
args_to_param
(
args
)
params
[
'output'
]
=
params
[
'output'
]
if
params
[
'output'
][
-
1
]
==
'/'
\
else
params
[
'output'
]
+
'/'
args
[
'output'
]
=
args
[
'output'
]
if
args
[
'output'
][
-
1
]
==
'/'
\
else
args
[
'output'
]
+
'/'
solution_repr
.
graph_isomorph_test
(
p
ar
am
s
[
'model_file_1'
],
p
ar
am
s
[
'model_file_2'
],
p
ar
am
s
[
'output'
],
p
ar
am
s
[
'graphs'
],
p
ar
am
s
[
'json'
],
ar
g
s
[
'model_file_1'
],
ar
g
s
[
'model_file_2'
],
ar
g
s
[
'output'
],
ar
g
s
[
'graphs'
],
ar
g
s
[
'json'
],
)
...
...
@@ -189,11 +180,9 @@ def model_info(args):
# Module import
import
solution_repr
params
=
args_to_param
(
args
)
params
[
'output_dir'
]
=
params
[
'output'
]
if
params
[
'output'
][
-
1
]
==
'/'
\
else
params
[
'output'
]
+
'/'
solution_repr
.
model_info
(
**
params
)
args
[
'output_dir'
]
=
args
[
'output'
]
if
args
[
'output'
][
-
1
]
==
'/'
\
else
args
[
'output'
]
+
'/'
solution_repr
.
model_info
(
**
args
)
def
model_graph
(
args
):
...
...
@@ -205,10 +194,9 @@ def model_graph(args):
# Module import
import
solution_repr
params
=
args_to_param
(
args
)
params
[
'output_dir'
]
=
params
[
'output'
]
if
params
[
'output'
][
-
1
]
==
'/'
\
else
params
[
'output'
]
+
'/'
solution_repr
.
model_graph
(
**
params
)
args
[
'output_dir'
]
=
args
[
'output'
]
if
args
[
'output'
][
-
1
]
==
'/'
\
else
args
[
'output'
]
+
'/'
solution_repr
.
model_graph
(
**
args
)
def
merge_macs
(
args
):
...
...
@@ -216,9 +204,8 @@ def merge_macs(args):
# Module import
import
solution_merge
params
=
args_to_param
(
args
)
solution_merge
.
merge_macs_to_csv
(
params
[
'solutions_directory'
],
params
[
'output'
])
solution_merge
.
merge_macs_to_csv
(
args
[
'solutions_directory'
],
args
[
'output'
])
def
args_to_param
(
args
):
...
...
@@ -226,6 +213,18 @@ def args_to_param(args):
return
{
k
:
v
for
k
,
v
in
vars
(
args
).
items
()
if
k
!=
'func'
}
def
ensure_dir_presence
(
path
):
"""Test write mode and eventually create the given directory"""
if
not
os
.
path
.
isdir
(
path
):
LOGGER
.
info
(
"Creation of the directory <{}>"
.
format
(
path
))
os
.
mkdir
(
path
)
if
not
os
.
access
(
path
,
os
.
W_OK
):
LOGGER
.
error
(
"<{}> is not writable"
.
format
(
path
))
exit
()
class
ReadableFile
(
argparse
.
Action
):
"""
http://stackoverflow.com/questions/11415570/directory-path-types-with-argparse
...
...
@@ -235,18 +234,14 @@ class ReadableFile(argparse.Action):
prospective_file
=
values
if
not
os
.
path
.
isfile
(
prospective_file
):
raise
argparse
.
ArgumentTypeError
(
"readable_file:{0} is not a valid path"
.
format
(
prospective_file
)
)
LOGGER
.
error
(
"readable_file:<{}> is not a valid file"
.
format
(
prospective_file
))
exit
()
if
os
.
access
(
prospective_file
,
os
.
R_OK
):
setattr
(
namespace
,
self
.
dest
,
prospective_file
)
else
:
raise
argparse
.
ArgumentTypeError
(
"readable_file:{0} is not a readable file"
.
format
(
prospective_file
)
)
LOGGER
.
error
(
"readable_file:<{}> is not a readable file"
.
format
(
prospective_file
))
exit
()
class
ReadableDir
(
argparse
.
Action
):
...
...
@@ -258,18 +253,14 @@ class ReadableDir(argparse.Action):
prospective_dir
=
values
if
not
os
.
path
.
isdir
(
prospective_dir
):
raise
argparse
.
ArgumentTypeError
(
"readable_dir:{0} is not a valid path"
.
format
(
prospective_dir
)
)
LOGGER
.
error
(
"readable_dir:<{}> is not a valid path"
.
format
(
prospective_dir
))
exit
()
if
os
.
access
(
prospective_dir
,
os
.
R_OK
):
setattr
(
namespace
,
self
.
dest
,
prospective_dir
)
else
:
raise
argparse
.
ArgumentTypeError
(
"readable_dir:{0} is not a readable dir"
.
format
(
prospective_dir
)
)
LOGGER
.
error
(
"readable_dir:<{}> is not a readable dir"
.
format
(
prospective_dir
))
exit
()
def
main
():
...
...
@@ -494,7 +485,7 @@ def main():
parser_model_comparison
.
set_defaults
(
func
=
model_comparison
)
# subparser: Model info
s
# subparser: Model info
# 1 model
parser_model_info
=
subparsers
.
add_parser
(
'model_info'
,
...
...
@@ -568,5 +559,13 @@ def main():
# Set log level
cm
.
log_level
(
vars
(
args
)[
'verbose'
])
# launch associated command
args
.
func
(
args
)
# Take argparse arguments and put them in a standard dict
params
=
args_to_param
(
args
)
# Ultimate check of the presence of the directories
know_directory_variables
=
(
"output"
,
"path"
,
"solutions_directory"
)
[
ensure_dir_presence
(
params
[
var
])
for
var
in
know_directory_variables
if
params
.
get
(
var
,
None
)]
# Launch associated command
args
.
func
(
params
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment