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
f634e2bd
Commit
f634e2bd
authored
Oct 25, 2018
by
VIGNET Pierre
Browse files
Rename sol_digging to get_json_solutions; improve arguments readability
parent
6585ba85
Changes
3
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/cadbiom_cmd.py
View file @
f634e2bd
...
...
@@ -73,8 +73,9 @@ def traj_2_graph(args):
)
def
traj_2_json
(
args
):
"""Convert all events for all solutions in a complete MAC file
and write them in a separate file in the JSON format.
"""Create a JSON formated file containing all data from complete MAC files
(frontier places/boundaries and decompiled steps with their respective
events).
This is a function to quickly search all transition attributes involved
in a solution.
...
...
@@ -85,10 +86,10 @@ def traj_2_json(args):
params
=
args_to_param
(
args
)
params
[
'output'
]
=
params
[
'output'
]
if
params
[
'output'
][
-
1
]
==
'/'
\
else
params
[
'output'
]
+
'/'
solution_repr
.
sol_digging_mai
n
(
solution_repr
.
traj_2_jso
n
(
params
[
'output'
],
params
[
'chart_file'
],
params
[
'
sol_file
'
],
params
[
'
path
'
],
conditions
=
not
params
[
'no_conditions'
],
# Inv the param...
)
...
...
@@ -287,23 +288,23 @@ def main():
# subparser: Decompilation of trajectories of MACs in a complete file/dir.
# Model file (xml : cadbiom language)
# Solution file (cam_complete)
parser_
sol_digging
=
subparsers
.
add_parser
(
parser_
traj_2_json
=
subparsers
.
add_parser
(
'traj_2_json'
,
help
=
traj_2_json
.
__doc__
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser_
sol_digging
.
add_argument
(
'chart_file'
,
parser_
traj_2_json
.
add_argument
(
'chart_file'
,
help
=
"bcx model file."
)
parser_
sol_digging
.
add_argument
(
'
sol_file
'
,
parser_
traj_2_json
.
add_argument
(
'
path
'
,
help
=
"Complete solution file or directory with solution files "
+
\
"(
output of
'compute_macs' command
)
."
)
parser_
sol_digging
.
add_argument
(
'--output'
,
action
=
ReadableDir
,
"(
*cam_complete.txt files) generated with the
'compute_macs' command."
)
parser_
traj_2_json
.
add_argument
(
'--output'
,
action
=
ReadableDir
,
nargs
=
'?'
,
default
=
'decompiled_solutions/'
,
help
=
"
Output d
irectory for
decompiled solutions
files."
)
parser_
sol_digging
.
add_argument
(
'--no_conditions'
,
action
=
'store_true'
,
help
=
"
D
irectory for
newly created
files."
)
parser_
traj_2_json
.
add_argument
(
'--no_conditions'
,
action
=
'store_true'
,
help
=
"Don't export conditions of transitions. This allows "
+
\
"to have only places/entities that are used inside trajectories; "
+
\
"thus, inhibitors nodes are not present in the json file"
)
parser_
sol_digging
.
set_defaults
(
func
=
traj_2_json
)
parser_
traj_2_json
.
set_defaults
(
func
=
traj_2_json
)
# subparser: Merge solutions to a csv file
...
...
command_line/cadbiom_cmd/solution_repr.py
View file @
f634e2bd
...
...
@@ -489,8 +489,8 @@ def test_main():
print
(
transitions
)
def
sol_digging_mai
n
(
output_dir
,
model_file
,
solution_path
,
conditions
=
True
):
"""Entry point for
sol_digging
def
traj_2_jso
n
(
output_dir
,
model_file
,
solution_path
,
conditions
=
True
):
"""Entry point for
traj_2_json
.. note:: This functions tests if the solution_path is a directory
or just a file.
...
...
@@ -501,6 +501,7 @@ def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
with
open
(
decompiled_filename
,
'w'
)
as
f_d
:
json
.
dump
(
decomp_solutions
,
f_d
,
sort_keys
=
True
,
indent
=
4
)
# Get transitions from the model
model_transitions
=
get_transitions_from_model_file
(
model_file
)
...
...
@@ -509,7 +510,7 @@ def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
# Add _decomp to the solution filename
filename
=
os
.
path
.
basename
(
os
.
path
.
splitext
(
solution_path
)[
0
])
decompiled_filename
=
output_dir
+
filename
+
'_decomp.txt'
decomp_solutions
=
sol_digging
(
decomp_solutions
=
get_json_solutions
(
load_solutions
(
solution_path
),
model_transitions
,
conditions
=
conditions
,
...
...
@@ -528,7 +529,7 @@ def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
# Add _decomp to the solution filename
filename
=
os
.
path
.
basename
(
os
.
path
.
splitext
(
solution_file
)[
0
])
decompiled_filename
=
output_dir
+
filename
+
'_decomp.txt'
decomp_solutions
=
sol_digging
(
decomp_solutions
=
get_json_solutions
(
load_solutions
(
solution_file
),
model_transitions
,
conditions
=
conditions
,
...
...
@@ -1026,11 +1027,11 @@ if __name__ == "__main__":
# print(g)
# exit()
sol_digging
(
load_solutions
(
LOG_DIR
+
"../run/pid_and_clock_no_perm_p21corrected_start_SRP9_complete.txt"
),
get_json_solutions
(
load_solutions
(
LOG_DIR
+
"../run/pid_and_clock_no_perm_p21corrected_start_SRP9_complete.txt"
),
get_transitions_from_model_file
(
BIO_MOLDELS_DIR
+
"Whole NCI-PID database translated into CADBIOM formalism(and).bcx"
))
exit
()
sol_digging
(
load_solutions
(
LOG_DIR
+
"sols_new_solver.txt"
),
get_json_solutions
(
load_solutions
(
LOG_DIR
+
"sols_new_solver.txt"
),
get_transitions_from_model_file
(
BIO_MOLDELS_DIR
+
"mini_test_publi.bcx"
))
exit
()
process_solutions
(
load_solutions
(
LOG_DIR
+
"sols_new_solver.txt"
),
...
...
command_line/cadbiom_cmd/tools/solutions.py
View file @
f634e2bd
...
...
@@ -36,8 +36,11 @@ import cadbiom.commons as cm
LOGGER
=
cm
.
logger
()
## Handle *cam_complete.txt files ##############################################
def
load_solutions
(
file
):
"""Open a file with many solution/MACs and yield them.
"""Open a file with many solution/MACs (*cam_complete.txt files)
and yield them.
:Example:
...
...
@@ -104,7 +107,7 @@ def load_solutions(file):
yield
sol
,
sol_steps
[
sol
]
def
sol_digging
(
sol_steps
,
transitions
,
conditions
=
True
):
def
get_json_solutions
(
sol_steps
,
transitions
,
conditions
=
True
):
"""Convert all events for all solutions in a complete MAC file
and write them in a separate file in the JSON format.
...
...
@@ -118,7 +121,7 @@ def sol_digging(sol_steps, transitions, conditions=True):
>>> from tools.models import get_transitions
>>> # Get transitions from the model
>>> model_transitions = get_transitions('model.bcx')
>>> decomp_solutions =
sol_digging
(
>>> decomp_solutions =
get_json_solutions
(
... load_solutions('./solution_cam_complete.txt'),
... model_transitions,
... conditions=True,
...
...
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