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

Add an entry to the command line: sol_digging to decompile each transition in...

Add an entry to the command line: sol_digging to decompile each transition in a complete solution file
parent 108149b3
......@@ -64,12 +64,30 @@ def parse_trajectories(args):
params = args_to_param(args)
params['output'] = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
solution_repr.main(
solution_repr.parse_trajectories_main(
params['output'],
params['chart_file'],
params['sol_file']
)
def sol_digging(args):
"""Convert all events for all solutions in a complete MAC file
and write them in a separate file.
This is a function to quickly search all transition attributes involved
in a solution.
"""
# Module import
import solution_repr
params = args_to_param(args)
params['output'] = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
solution_repr.sol_digging_main(
params['output'],
params['chart_file'],
params['sol_file']
)
def model_comp(args):
"""Model consistency checking.
......@@ -253,6 +271,24 @@ def main():
parser_trajectories.set_defaults(func=parse_trajectories)
# subparser: Representation of the trajectories of MACs in a complete file.
# Model file (xml : cadbiom language)
# Solution file (cam_complete)
parser_sol_digging = subparsers.add_parser(
'sol_digging',
help=sol_digging.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser_sol_digging.add_argument('chart_file',
help="bcx model file.")
parser_sol_digging.add_argument('sol_file',
help="Complete solution file or directory with solution files " + \
"(output of 'compute_macs' command).")
parser_sol_digging.add_argument('--output', action=ReadableDir,
nargs='?', default='decompiled_solutions/',
help="Output directory for decompiled solutions files.")
parser_sol_digging.set_defaults(func=sol_digging)
# subparser: Merge solutions to a csv file
# Solution file (cam)
# Output (csv)
......
......@@ -31,6 +31,8 @@ import networkx as nx
import itertools as it
import re
import json
import os
import glob
from logging import DEBUG
# Remove matplotlib dependency
# It is used on demand during the drawing of a graph
......@@ -880,13 +882,12 @@ def test_main():
def sol_digging(sol_steps, transitions):
"""Get steps and all transitions and write all data for each step in a file.
def sol_digging(decompiled_filename, sol_steps, transitions):
"""Convert all events for all solutions in a complete MAC file
and write them in a separate file.
This is an exemple to quickly search all transition attributes involved in a
complete MAC.
.. note:: Output file: output.txt
This is a function to quickly search all transition attributes involved
in a solution.
:param arg1: List of steps involved in a solution. See load_solutions().
:param arg2: A dictionnary of events as keys, and transitions as values.
......@@ -906,21 +907,23 @@ def sol_digging(sol_steps, transitions):
for trans in step_event:
# ori="JUN_nucl_gene" ext="JUN_nucl" event="_h_391"
line = 'ori="{}" ext="{}" event="{}" condition="{}"'.format(
line = 'ori="{}" ext="{}" event="{}" condition="{}"\n'.format(
trans[0],
trans[1],
trans[2]['label'].split('[')[0],
trans[2]['condition']
)
fd.write(line + '\n')
fd.write(line)
with open("output.txt", "w") as fd:
with open(decompiled_filename, 'w') as fd:
# For each sol
for sol, steps in sol_steps:
# Solution header
fd.write(sol + '\n')
# For each step
for step in steps:
for event in step:
......@@ -934,11 +937,49 @@ def sol_digging(sol_steps, transitions):
# Step separation
fd.write('\n')
# Sol separation
fd.write('\n====================================================\n')
def main(output_dir, model_file, solution_file):
def sol_digging_main(output_dir, model_file, solution_path):
"""Entry point for sol_digging
.. note:: This functions tests if the solution_path is a directory
or just a file.
"""
# Get transitions from the model
model_transitions = get_transitions(model_file)
if os.path.isfile(solution_path):
# The given path is a solution file
# Add _decomp to the solution filename
filename, file_extension = os.path.splitext(solution_file)
sol_digging(
output_dir + filename + '_decomp' + file_extension,
load_solutions(solution_file),
model_transitions
)
elif os.path.isdir(solution_path):
# The given path is a directory
solution_path = solution_path if solution_path[-1] == '/' \
else solution_path + '/'
# Decompilation of all files in the directory
for file_number, solution_file in \
enumerate(glob.glob(solution_path + '*cam_complete.txt'), 1):
# Add _decomp to the solution filename
filename, file_extension = os.path.splitext(solution_file)
sol_digging(
output_dir + filename + '_decomp' + file_extension,
load_solutions(solution_file),
model_transitions
)
LOGGER.info("Files processed: " + str(file_number))
def parse_trajectories_main(output_dir, model_file, solution_file):
"""Entry point for parse_trajectories"""
process_solutions(
......
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