Commit 02467e01 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Add a model comparison functionality for the command line

parent a9d98e92
......@@ -2,6 +2,8 @@ CADBIOM (Computer Aided Design of Biological Models) is an open source modelling
Based on Guarded transition semantic, it gives a formal framework to help the modelling of
biological systems such as cell signaling network.
Official website: [](http://cadbiom.genouest.org/)
# Installation
......@@ -128,6 +130,10 @@ The gui package exposes the command `cadbiom` to the current context.
model file.
merge_cams Merge solutions to a csv file. .. note:: CSV file:
<Final property formula>;<cam>
model_comp Model consistency checking. Check if the 2 given
models have the same topology, nodes & edges
attributes/roles. .. note:: You can export a graphml
file for the 2 models.
### compute_macs:
......@@ -189,6 +195,19 @@ The gui package exposes the command `cadbiom` to the current context.
solutions_directory
### model_comp:
usage: cadbiom_cmd model_comp [-h] [--make_graphs] model_file_1 model_file_2
positional arguments:
model_file_1
model_file_2
optional arguments:
-h, --help show this help message and exit
--make_graphs
## Graphical User Interface
Usage:
......
......@@ -76,6 +76,25 @@ def parse_trajectories(args):
solution_repr.main(params['chart_file'], params['sol_file'])
def model_comp(args):
"""Model consistency checking.
Check if the 2 given models have the same topology,
nodes & edges attributes/roles.
.. note:: You can export a graphml file for the 2 models.
"""
# Module import
import solution_repr
params = args_to_param(args)
solution_repr.graph_isomorph_test(
params['model_file_1'],
params['model_file_2'],
params['make_graphs'],
)
def merge_cams(args):
"""Merge solutions to a csv file.
......@@ -201,7 +220,7 @@ def main():
# Solution file (cam)
# Output (csv)
parser_merge_cams = subparsers.add_parser('merge_cams',
help=merge_cams.__doc__)
help=merge_cams.__doc__)
parser_merge_cams.add_argument('solutions_directory', nargs='?',
default='result/')
parser_merge_cams.add_argument('--output', nargs='?',
......@@ -209,6 +228,17 @@ def main():
parser_merge_cams.set_defaults(func=merge_cams)
# subparser: Model comparison
# 2 models
parser_model_comparison = subparsers.add_parser('model_comp',
help=model_comp.__doc__)
parser_model_comparison.add_argument('model_file_1')
parser_model_comparison.add_argument('model_file_2')
# Export graphs for the 2 models; default: false
parser_model_comparison.add_argument('--make_graphs', action='store_true')
parser_model_comparison.set_defaults(func=model_comp)
# get program args and launch associated command
args = parser.parse_args()
......
......@@ -200,6 +200,29 @@ def get_transitions(file):
return dict(transitions)
def get_frontier_places(transitions):
"""Return frontier places of a model (deducted from its transitions).
:param arg1: Model's transitions.
{u'h00': [('Ax', 'n1', {u'label': u'h00[]'}),]
:type arg1: <dict>
keys: names of events
values: list of transitions as tuples (with in/output, and label).
:return: Set of frontier places.
:rtype: <set>
"""
# Get transitions in events
g = tuple(trans for event in transitions.values() for trans in event)
# Get input nodes & output nodes
input_places = {trans[0] for trans in g}
output_places = {trans[1] for trans in g}
# Get all places that are not in transitions in the "output" place
return input_places - output_places
def rec(tree, inhibitors_nodes):
"""
......@@ -553,7 +576,7 @@ def draw_graph(solution, solution_index, G,
:param arg6: Edges between transition node and nodes in condition
:param arg7: Normal transitions without condition
:type arg1: <str>
:type arg2: <int>
:type arg2: <int> or <str>
:type arg3: <networkx.classes.digraph.DiGraph>
:type arg4: <list>
:type arg5: <list>
......@@ -767,8 +790,7 @@ def sol_digging(sol_steps, transitions):
def main(model_file, solution_file):
"""
"""
"""Entry point for parse_trajectories"""
process_solutions(
load_solutions(solution_file),
......@@ -776,6 +798,58 @@ def main(model_file, solution_file):
)
def graph_isomorph_test(model_file_1, model_file_2, make_graphs=False):
"""Entry point for model consistency checking.
This functions checks if the 2 given models have the same topology,
nodes & edges attributes/roles.
.. note:: cf graphmatcher
https://networkx.github.io/documentation/development/reference/generated/networkx.algorithms.isomorphism.categorical_edge_match.html
:param arg1: File for the model 1.
:param arg2: File for the model 2.
:type arg1: <str>
:type arg2: <str>
"""
import networkx.algorithms.isomorphism as iso
# Load transitions in the models
# Transitions structure format:
# {u'h00': [('Ax', 'n1', {u'label': u'h00[]'}),]
transitions_1 = get_transitions(model_file_1)
transitions_2 = get_transitions(model_file_2)
# Get all frontier places in the models
# (places that are never in output position in all transitions)
front_places_1 = " ".join(get_frontier_places(transitions_1))
front_places_2 = " ".join(get_frontier_places(transitions_2))
# Build graphs & get networkx object
# We give all events in the model as a list of steps
# So we simulate a cadbiom solution (with all events in the model).
res_1 = build_graph(front_places_1, [transitions_1.keys()], transitions_1)
G1 = res_1[0]
res_2 = build_graph(front_places_2, [transitions_2.keys()], transitions_2)
G2 = res_2[0]
# Draw graph
if make_graphs:
draw_graph(front_places_1, "first", *res_1)
draw_graph(front_places_2, "second", *res_2)
# Checking
LOGGER.info("Topology checking: " +
str(nx.is_isomorphic(G1, G2)))
nm = iso.categorical_node_match('color', 'grey')
LOGGER.info("Nodes checking: " +
str(nx.is_isomorphic(G1, G2, node_match=nm)))
em = iso.categorical_edge_match('color', '')
LOGGER.info("Edges checking: " +
str(nx.is_isomorphic(G1, G2, edge_match=em)))
if __name__ == "__main__":
# cond = "((((CXCL10_CXCR3_intToMb and not(CCL11_CXCR3_intToMb)))or((CXCL10_CXCR3_intToMb and not(CXCL13_CXCR3_intToMb))))or(CXCL9_11_CXCR3_active_intToMb))or(CXCL4_CXCR3_intToMb)"
# cond = "((((A and not(B)))or((A and not(C))))or(D))or(E)"
......
......@@ -2,6 +2,8 @@ CADBIOM (Computer Aided Design of Biological Models) is an open source modelling
Based on Guarded transition semantic, it gives a formal framework to help the modelling of
biological systems such as cell signaling network.
Official website: [](http://cadbiom.genouest.org/)
# Installation
......@@ -128,6 +130,10 @@ The gui package exposes the command `cadbiom` to the current context.
model file.
merge_cams Merge solutions to a csv file. .. note:: CSV file:
<Final property formula>;<cam>
model_comp Model consistency checking. Check if the 2 given
models have the same topology, nodes & edges
attributes/roles. .. note:: You can export a graphml
file for the 2 models.
### compute_macs:
......@@ -189,6 +195,19 @@ The gui package exposes the command `cadbiom` to the current context.
solutions_directory
### model_comp:
usage: cadbiom_cmd model_comp [-h] [--make_graphs] model_file_1 model_file_2
positional arguments:
model_file_1
model_file_2
optional arguments:
-h, --help show this help message and exit
--make_graphs
## Graphical User Interface
Usage:
......
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