Commit e7f7cb50 authored by VIGNET Pierre's avatar VIGNET Pierre

Model corrections is now in cadbiom library

parent 24ea3db8
......@@ -48,6 +48,9 @@ from utils.listDisplay import ToggleList
from cadbiom.models.guard_transitions.analyser.ana_visitors import FrontierVisitor
from utils.warn import cancel_warn
from cadbiom.models.guard_transitions.chart_model import ChartModel
from cadbiom.models.guard_transitions.analyser import model_corrections
from cadbiom.models.guard_transitions.translators.chart_xml import \
MakeModelFromXmlFile
from utils.fileHandling import FileChooser
from utils.reporter import CompilReporter
......@@ -526,7 +529,8 @@ class ImportBioPAXParams(object):
"http://reactome.org/mycobacterium"
)
# Triplestore URL
self.wtree.get_widget('text_triplestore_url').set_text(self.triplestore_url)
self.wtree.get_widget('text_triplestore_url').set_text(
self.triplestore_url)
# BioPAX level
self.wtree.get_widget('radio_biopax_level3').set_active(True)
# BioPAX options
......@@ -627,11 +631,18 @@ class ImportBioPAXParams(object):
'fullCompartmentsNames': self.full_compartments_names,
'blacklist': self.blacklist_file,
'triplestore': self.triplestore_url,
'checkbox_remove_scc': self.remove_strongly_connected_components,
'no_scc_fix': True, # StartNodes are added here
}
try:
model = biopax_converter.main(params)
# StartNodes are added here, (not in biopax2cadbiom)
# so we can load the model in memory
biopax_converter.main(params)
if self.remove_strongly_connected_components:
model = model_corrections.add_start_nodes(self.cadbiom_file)
else:
model = MakeModelFromXmlFile(self.cadbiom_file).get_model()
model.modified = False # ?????
self.charter.add_edit_mvc(model.name, model)
......
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 IRISA, Jean Coquet, Pierre Vignet
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Contributor(s): Jean Coquet, Pierre Vignet
"""
This module is used to bring some corrections to Cadbiom model processed before.
- Removing of Strongly Connected Components
(cycles of disabled places that can never be activated by the solver)
"""
from __future__ import unicode_literals
from __future__ import print_function
# Standard imports
import os
# Custom imports
from cadbiom.models.guard_transitions.analyser.static_analysis \
import StaticAnalyzer
from cadbiom.models.guard_transitions.translators.chart_xml \
import XmlVisitor
import cadbiom.commons as cm
LOGGER = cm.logger()
class ErrorRep(object):
# Cf class CompilReporter(object):
# gt_gui/utils/reporter.py
def __init__(self):
self.context = ""
self.error = False
def display(self, mess):
self.error = True
LOGGER.error(">> Context: {}; {}".format(self.context, mess))
exit()
def display_info(self, mess):
LOGGER.error("-- Context: {}; {}".format(self.context, mess))
exit()
def set_context(self, cont):
self.context = cont
def add_start_nodes(filePath):
"""Handle Strongly Connected Components (SCC) by adding Start Nodes
.. note:: Only 1 start node in each SCC is sufficient to suppress it
from the model.
.. note:: We use cadbiom API to add Start Nodes and write a new model.
.. note:: Save the model with "_without_scc" suffix in filename
:param: File path.
:type: <str>
:return: The model loaded by StaticAnalyzer
:rtype: <ChartModel>
"""
# Build StaticAnalyzer with Error Reporter
staticanalyser = StaticAnalyzer(ErrorRep())
staticanalyser.build_from_chart_file(filePath)
# Get Strongly Connected Components
sccs = staticanalyser.get_frontier_scc()
LOGGER.info("{} SCC found: {}".format(len(sccs), sccs))
LOGGER.info("Before adding start nodes: " + staticanalyser.get_statistics())
# Lexicographic sort of nodes in each Strongly Connected Components
g = (scc for scc in sccs if len(scc) != 0)
for scc in g:
scc.sort(key=str.lower)
# Mark the first node as a frontier
LOGGER.debug("SCC {}; first lexicographic node selected:{}".format(
scc, scc[0]))
staticanalyser.model.mark_as_frontier(scc[0])
# Save the model with "_without_scc" suffix in filename
xml = XmlVisitor(staticanalyser.model)
filename, file_extension = os.path.splitext(filePath)
mfile = open(filename + "_without_scc" + file_extension, 'w')
mfile.write(xml.return_xml())
mfile.close()
return staticanalyser.model
......@@ -35,7 +35,7 @@ from distutils import sysconfig
from setuptools import setup, Extension, find_packages
from setuptools.command.test import test as TestCommand
__PACKAGE_VERSION__ = "0.1.1"
__PACKAGE_VERSION__ = "0.1.2"
__LIBRARY_VERSION__ = "0.1.0"
################################################################################
......
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