Commit 5519e351 authored by VIGNET Pierre's avatar VIGNET Pierre

Add BioPAX support with biopax2cadbiom project

parent ecafd253
......@@ -40,14 +40,21 @@
<child>
<widget class="GtkMenuItem" id="Import_cadbiom">
<property name="visible">True</property>
<property name="label" translatable="yes">import from Cadbiom file</property>
<property name="label" translatable="yes">Import from Cadbiom file</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="Import_BioPAX">
<property name="visible">True</property>
<property name="label" translatable="yes">Import from BioPAX data on triplestore</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="Import_PID">
<property name="visible">True</property>
<property name="label" translatable="yes">import from PID XML file</property>
<property name="label" translatable="yes">Import from PID XML file</property>
<property name="use_underline">True</property>
</widget>
</child>
......
......@@ -43,7 +43,7 @@ Small widgets for Cadbiom gui
"""
import gtk
import re
import traceback
from utils.listDisplay import ToggleList
from cadbiom.models.guard_transitions.analyser.ana_visitors import FrontierVisitor
from utils.warn import cancel_warn
......@@ -349,7 +349,7 @@ class LegendWindow(object):
if self.win:
self.win.destroy()
class ImportParam(object):
class ImportPIDParam(object):
"""
Widget for model importing
"""
......@@ -471,3 +471,192 @@ class ImportParam(object):
self.on_destroy(None)
class ImportBioPAXParams(object):
"""On a fait quoi des and/or ??????
Widget for model importing
"""
def __init__(self, chart, parent):
self.charter = chart
try:
from biopax2cadbiom.commons import SPARQL_PATH
except ImportError:
d_err = DisplayError(
None, "biopax2cadbiom module is missing.",
"biopax2cadbiom project is required to perform this task.\n" + \
"Please install it via the usual command:\n" + \
"pip install biopax2cadbiom"
)
d_err.main_window.set_modal(True)
d_err.main_window.set_transient_for(parent)
return
# Init class variables (settings of the window)
self.cadbiom_file = ''
self.convert_full_graph = True
self.graph_uris = list()
self.full_compartments_names = True
self.blacklist_file = None
self.triplestore_url = SPARQL_PATH
self.remove_strongly_connected_components = True
# window creation
template = pkg_resources.resource_filename(
__name__,
"chart_glade/import_BioPAX_parameters.glade"
)
self.wtree = gtk.glade.XML(template)
self.main_window = self.wtree.get_widget("window1")
self.main_window.set_title("Import window")
self.main_window.set_resizable(True)
self.main_window.set_position(gtk.WIN_POS_CENTER)
# Set modal mode for the window (above all windows & block inputs)
self.main_window.set_modal(True)
self.main_window.set_transient_for(parent)
if (self.main_window):
self.main_window.connect("destroy", self.on_destroy)
# Init interface
# Triplestore
# Graphs URIs
self.wtree.get_widget('text_graphs_uris').set_text(
"http://reactome.org/mycobacterium"
)
# 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
self.wtree.get_widget('checkbox_convert_full_graph').set_active(False)
self.wtree.get_widget('checkbox_full_compartment_names').set_active(True)
self.wtree.get_widget('checkbox_remove_scc').set_active(True)
# Connect buttons
# Files
self.wtree.get_widget("button_blacklist").connect(
"clicked", self.on_import_blacklist_file
)
self.wtree.get_widget("button_output").connect(
"clicked", self.on_set_output_file
)
self.wtree.get_widget("button_make_model").connect(
"clicked", self.import_BioPAX_data
)
# Display
self.main_window.show_all()
def on_import_blacklist_file(self, widget):
"""
Choose blacklist file of entities
"""
fch = FileChooser("Choose the blacklist file", "txt files", "*.txt")
fch.do_action(self.set_blacklist_file)
def on_set_output_file(self, widget):
"""
Choose output model file
"""
fch = FileChooser("Choose the output file name", "bcx files", "*.bcx")
fch.do_action(self.set_output_file)
def set_blacklist_file(self, file):
self.blacklist_file = file
def set_output_file(self, file):
self.cadbiom_file = file
def import_BioPAX_data(self, widget):
"""
Import from BioPAX data on triplestore
"""
from biopax2cadbiom import biopax_converter
# Return if output file is not set
if self.cadbiom_file == '':
red = gtk.gdk.color_parse("red")
self.wtree.get_widget("button_output").modify_bg(
gtk.STATE_NORMAL, red)
return
# Get parameters
# List of graphs URIs
self.graph_uris = \
self.wtree.get_widget('text_graphs_uris').get_text().split(',')
# Triplestore URL
self.triplestore_url = \
self.wtree.get_widget('text_triplestore_url').get_text()
# BioPAX level
biopax2 = self.wtree.get_widget('radio_biopax_level2').get_active()
self.graph_uris.append(
'http://biopax.org/lvl2' if biopax2 else 'http://biopax.org/lvl3'
)
# BioPAX convertion
self.convert_full_graph = \
self.wtree.get_widget('checkbox_convert_full_graph').get_active()
self.full_compartments_names = \
self.wtree.get_widget('checkbox_full_compartment_names').get_active()
self.remove_strongly_connected_components = \
self.wtree.get_widget('checkbox_remove_scc').get_active()
green = gtk.gdk.color_parse("green")
self.wtree.get_widget("button_make_model").modify_bg(
gtk.STATE_NORMAL, green)
self.wtree.get_widget("button_make_model").set_label(
"Make model. Please wait...")
# Do the magick
# Build parameters for biopax2cadbiom
params = {
'cadbiomFile': self.cadbiom_file,
'convertFullGraph': self.convert_full_graph,
'listOfGraphUri': self.graph_uris,
'pickleBackup': False,
'pickleDir': '', # don't care, because pickleBackup = False
'fullCompartmentsNames': self.full_compartments_names,
'blacklist': self.blacklist_file,
'triplestore': self.triplestore_url,
'checkbox_remove_scc': self.remove_strongly_connected_components,
}
try:
model = biopax_converter.main(params)
model.modified = False # ?????
self.charter.add_edit_mvc(model.name, model)
self.destroy()
except Exception as e:
d_err = DisplayError(
None, "Biopax2cadbiom",
"Biopax2cadbiom exception: " + \
e.__class__.__name__ + ". Please check logs.\n" + \
traceback.format_exc()
)
d_err.main_window.set_modal(True)
def on_destroy(self, widget):
"""
standard destroy callback
"""
if self.main_window:
self.main_window.destroy()
def destroy(self):
"""
for parents
"""
self.on_destroy(None)
......@@ -62,7 +62,7 @@ from chart_simulator.chart_simul_controler import \
ChartSimulControler, DisplayError
from chart_checker.chart_checker_controler import ChartChecker
from chart_misc_widgets import SearchManager, SearchFrontier, \
LegendWindow, ImportParam
LegendWindow, ImportPIDParam, ImportBioPAXParams
from cadbiom_gui.gt_gui.chart_static.chart_stat_controler import ChartStatControler
from cadbiom.models.guard_transitions.chart_model import ChartModel
......@@ -125,6 +125,8 @@ class Charter(object):
menu_item.connect("activate", self.new_charts)
menu_item = self.wtree.get_widget("Import_cadbiom")
menu_item.connect("activate", self.choose_xml_file)
menu_item = self.wtree.get_widget("Import_BioPAX")
menu_item.connect("activate", self.choose_BioPAX_file)
menu_item = self.wtree.get_widget("Import_PID")
menu_item.connect("activate", self.choose_pid_file)
menu_item = self.wtree.get_widget("Import_CadLang")
......@@ -590,7 +592,13 @@ class Charter(object):
"""
open a window to search xml file coming from PID database
"""
ImportParam(self)
ImportPIDParam(self)
def choose_BioPAX_file(self, widget):
"""
open a window to import BioPAX data from a triplestore
"""
ImportBioPAXParams(self, self.main_window)
def export_to_lang(self, widget):
"""
......
......@@ -32,7 +32,7 @@
# Standard imports
from setuptools import setup, find_packages
__PACKAGE_VERSION__ = "0.1.1"
__PACKAGE_VERSION__ = "0.2.0"
__LIBRARY_VERSION__ = "0.1.0"
setup(
......
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