Commit f634e2bd authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Rename sol_digging to get_json_solutions; improve arguments readability

parent 6585ba85
......@@ -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_main(
solution_repr.traj_2_json(
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 directory for decompiled solutions files.")
parser_sol_digging.add_argument('--no_conditions', action='store_true',
help="Directory 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
......
......@@ -489,8 +489,8 @@ def test_main():
print(transitions)
def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
"""Entry point for sol_digging
def traj_2_json(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"),
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment