Commit 31f139a7 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Improve args parse; Add repr & sort methods for solutions

parent 9d0d1456
......@@ -8,6 +8,7 @@ import re
import os
from functools import partial
import sys
import itertools as it
# Multiprocessing
from concurrent.futures import ProcessPoolExecutor, as_completed
......@@ -21,6 +22,10 @@ from cadbiom.models.clause_constraints.mcl.MCLAnalyser import MCLAnalyser
from cadbiom.models.clause_constraints.mcl.MCLQuery import MCLSimpleQuery
import cadbiom.commons as cm
# Module imports
import solution_sort
import solution_repr
LOGGER = cm.logger()
......@@ -114,6 +119,8 @@ def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_fil
:param arg7: Formula: Property that the solver looks for.
:param arg8: Formula: Original property (constraint) for the solver.
:param arg9: Formula: ???
:param arg10: If set to True (not default), search allways macs with
less or equal steps than previous, by limiting steps.
:type arg1: <str>
:type arg2: <str>
:type arg3: <str>
......@@ -123,6 +130,7 @@ def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_fil
:type arg7: <str>
:type arg8: <str>
:type arg9: <str>
:type arg10: <boolean>
.. todo: handle these QUERY PARAMETERS... from GUI program
......@@ -267,11 +275,11 @@ def find_mac(mcla,
with open(cam_complete_file, 'a') as file:
# Save MAC
next_mac = next_mac_object.activated_frontier
# Save MAC (in alphabetic order...)
next_mac = sorted(next_mac_object.activated_frontier)
LOGGER.debug(final_prop + ":: Save next MAC: {}".format(next_mac))
with open(cam_file, 'a') as file:
file.write('\t'.join(next_mac) + '\n')
file.write(' '.join(next_mac) + '\n')
# Save min steps
min_step = mcla.unfolder.get_current_step() - 1 # Magic number !
......@@ -320,7 +328,7 @@ def detect_model_type(mclanalyser, filepath):
def main(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_file,
steps, final_prop, start_prop, inv_prop):
steps, final_prop, start_prop, inv_prop, all_macs):
LOGGER.debug("Params: start: {}, inv: {}, final: {}".format(start_prop,
......@@ -411,6 +419,39 @@ def main(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_file
return 1
def compute_combinations(final_properties):
"""Return all combinations of final properties.
.. note:: (in case of input_file and combinations set).
:param: List of final properties.
:type: <list>
:return: List of str. Each str is a combination of final_properties linked
by a logical 'and'.
Ex: ('TGFB1', 'COL1A1'), ('TGFB1', 'decorin')
gives: [u'TGFB1 and COL1A1', u'TGFB1 and decorin']
:rtype: <list <str>>
all_combinations = list()
for i in range(1, len(final_properties) + 1):
[' and '.join(comb) for comb in it.combinations(final_properties, i)]
# Unpack combinations
all_combinations = [comb for comb in it.chain(*all_combinations)]
LOGGER.debug("Combinations: {}, Length: {}".format(
)"Number of computed combinations: " + \
return all_combinations
def launch_researchs(args):
"""Parse arguments and launch Cadbiom search of MACs
(Minimal Activation Conditions).
......@@ -435,6 +476,12 @@ def launch_researchs(args):
final_properties = [prop for prop in g if prop != '']
if params['combinations']:
# If input_file is set, we can compute all combinations of
# final_properties. default: False
final_properties = compute_combinations(final_properties)
LOGGER.debug("Final properties: " + str(final_properties))
def update_params(prop):
......@@ -531,6 +578,23 @@ def compute_macs(params):
def launch_sort(args):
"""Parse a solution file and sort all frontier places in alphabetical order.
params = args_to_param(args)
def parse_trajectories(args):
"""Parse a complete solution file and make a representation of trajectories.
.. note:: Requires the model file.
params = args_to_param(args)
def args_to_param(args):
"""Return argparse namespace as a dict {variable name: value}"""
return {k: v for k, v in vars(args).items() if k != 'func'}
......@@ -591,7 +655,7 @@ if __name__ == "__main__":
# Subparsers
subparsers = parser.add_subparsers(title='subcommands')
# PS: nargs='?' = optional
# subparser: Compute macs
# steps = 10
# final_prop = "P"
......@@ -605,9 +669,12 @@ if __name__ == "__main__":
group = parser_input_file.add_mutually_exclusive_group()
group.add_argument('final_prop', nargs='?')
group.add_argument('--input_file', action=ReadableFile, nargs='?')
# If input_file is set, we can compute all combinations of given elements
# default: False
parser_input_file.add_argument('--combinations', action='store_true')
parser_input_file.add_argument('--steps', type=int, nargs='?', default=10)
# all_macs to Fals by default
# all_macs to False by default
parser_input_file.add_argument('--all_macs', action='store_true')
parser_input_file.add_argument('--start_prop', nargs='?', default=None)
parser_input_file.add_argument('--inv_prop', nargs='?', default=None)
......@@ -615,6 +682,25 @@ if __name__ == "__main__":
# subparser: Sort solutions in alphabetical order in place
# Solution file (complete or not)
parser_solutions_sort = subparsers.add_parser('sort_solutions',
# subparser: Representation of the trajectories of MACs in a complete file.
# Model file (xml : cadbiom language)
# Solution file (complete)
parser_trajectories = subparsers.add_parser('parse_trajectories',
# get program args and launch associated command
args = parser.parse_args()
# Set log level
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