Beispiel #1
0
    def activated(self):
        # add an import plugin
        plugin = ImportPlugin()
        wi = WorkflowItem(task=self)
        wi.operation = plugin.get_operation()

        self.model.workflow.append(wi)
        self.model.selected = wi

        # if we're debugging, add a few data bits
        if self.debug:
            from cytoflow import Tube

            wi.operation.conditions["Dox"] = "log"

            tube1 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                         conditions={"Dox": 0.1})

            tube2 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                         conditions={"Dox": 1.0})

            wi.operation.tubes.append(tube1)
            wi.operation.tubes.append(tube2)

            self.add_operation(
                'edu.mit.synbio.cytoflowgui.op_plugins.threshold')
            self.model.selected.operation.channel = "Y2-A"
            self.model.selected.operation.threshold = 2000
            self.model.selected.operation.name = "T"
Beispiel #2
0
    def activated(self):
        # add an import plugin
        plugin = ImportPlugin()
        wi = WorkflowItem(task = self)
        wi.operation = plugin.get_operation()

        self.model.workflow.append(wi)
        self.model.selected = wi
        
        # if we're debugging, add a few data bits
        if self.debug:
            from cytoflow import Tube
                     
            wi.operation.conditions["Dox"] = "log"
        
            tube1 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                         conditions = {"Dox" : 0.1})
        
            tube2 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                         conditions = {"Dox" : 1.0})
        
            wi.operation.tubes.append(tube1)
            wi.operation.tubes.append(tube2)
                        
            self.add_operation('edu.mit.synbio.cytoflowgui.op_plugins.hlog')
            self.model.selected.operation.channels = ["V2-A", "Y2-A"]
            self.model.selected.operation.name = "H"
              
            self.add_operation('edu.mit.synbio.cytoflowgui.op_plugins.threshold')
            self.model.selected.operation.channel = "Y2-A"
            self.model.selected.operation.threshold = 2000
            self.model.selected.operation.name = "T"        
Beispiel #3
0
    def setUp(self):
        super().setUp()

        plugin = ImportPlugin()
        op = plugin.get_operation()

        from cytoflow import Tube

        self.cwd = os.path.dirname(os.path.abspath(__file__))

        tube = Tube(file=self.cwd + "/../../cytoflow/tests/data/tasbe/rby.fcs")
        op.tubes = [tube]

        wi = WorkflowItem(operation=op,
                          status="waiting",
                          view_error="Not yet plotted")
        self.workflow.workflow.append(wi)

        op.do_estimate = True
        self.workflow.wi_waitfor(wi, 'status', 'valid')
        self.assertTrue(
            self.workflow.remote_eval("self.workflow[0].result is not None"))

        plugin = ThresholdPlugin()
        op = plugin.get_operation()

        op.name = "Morpho"
        op.channel = "FSC-A"
        op.threshold = 100000

        wi = WorkflowItem(operation=op, status='waiting')
        self.workflow.workflow.append(wi)
        self.workflow.selected = wi
        self.workflow.wi_waitfor(wi, 'status', 'valid')
Beispiel #4
0
 def activated(self):
     # add an import plugin
     import_op = ImportPlugin().get_operation()
     
     # if we're debugging, add a few data bits
     if self.debug:
         from cytoflow import Tube
                  
         import_op.conditions["Dox"] = "float"
         import_op.conditions["Replicate"] = "int"
     
         tube1 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                      conditions = {"Dox" : 1.0, "Replicate" : 1})
     
         tube2 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                      conditions = {"Dox" : 10.0, "Replicate" : 1})
         
         tube3 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs",
                      conditions = {"Dox" : 1.0, "Replicate" : 2})
     
         tube4 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs",
                      conditions = {"Dox" : 10.0, "Replicate" : 2})
     
         import_op.tubes = [tube1, tube2, tube3, tube4]
         
     self.model.add_operation(import_op)      
Beispiel #5
0
    def on_new(self):
        self.model.workflow = []

        # add an import plugin
        plugin = ImportPlugin()
        wi = WorkflowItem(task=self)
        wi.operation = plugin.get_operation()

        self.model.workflow.append(wi)
        self.model.selected = wi
Beispiel #6
0
    def on_new(self):
        self.model.workflow = []
        
        # add an import plugin
        plugin = ImportPlugin()
        wi = WorkflowItem(task = self)
        wi.operation = plugin.get_operation()

        self.model.workflow.append(wi)
        self.model.selected = wi
Beispiel #7
0
    def setUp(self):
        WorkflowTest.setUp(self)
        
        plugin = ImportPlugin()
        op = plugin.get_operation()

        from cytoflow import Tube
             
        self.cwd = os.path.dirname(os.path.abspath(__file__))
     
        tube = Tube(file = self.cwd + "/../../cytoflow/tests/data/tasbe/rby.fcs")
        op.tubes = [tube]
        
        wi = WorkflowItem(operation = op,
                          view_error = "Not yet plotted") 
        self.workflow.workflow.append(wi)
        self.assertTrue(wait_for(wi, 'status', lambda v: v == 'valid', 5))
        self.assertTrue(self.workflow.remote_eval("self.workflow[0].result is not None"))
Beispiel #8
0
    def setUp(self):
        WorkflowTest.setUp(self)
        
        plugin = ImportPlugin()
        op = plugin.get_operation()

        from cytoflow import Tube
        
        op.conditions = {"Dox" : "float", "Well" : "category"}
     
        self.cwd = os.path.dirname(os.path.abspath(__file__))
     
        tube1 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                     conditions = {"Dox" : 0.0, "Well" : 'A'})
     
        tube2 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                     conditions = {"Dox" : 10.0, "Well" : 'A'})

        tube3 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_A7.fcs",
                     conditions = {"Dox" : 100.0, "Well" : 'A'})
         
        tube4 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs",
                     conditions = {"Dox" : 0.0, "Well" : 'B'})
     
        tube5 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs",
                     conditions = {"Dox" : 10.0, "Well" : 'B'})

        tube6 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_C7.fcs",
                     conditions = {"Dox" : 100.0, "Well" : 'B'})
     
        op.tubes = [tube1, tube2, tube3, tube4, tube5, tube6]
        
        wi = WorkflowItem(operation = op,
                          view_error = "Not yet plotted") 
        self.workflow.workflow.append(wi)
        self.assertTrue(wait_for(wi, 'status', lambda v: v == 'valid', 5))
        self.assertTrue(self.workflow.remote_eval("self.workflow[0].result is not None"))
Beispiel #9
0
    def activated(self):
        # add the import op
        self.add_operation(ImportPlugin().id)
        self.model.selected = self.model.workflow[0]

        # if we're debugging, add a few data bits
        if self.model.debug:
            from cytoflow import Tube

            import_op = self.model.workflow[0].operation
            import_op.conditions = {"Dox": "float", "Well": "category"}
            #             import_op.conditions["Dox"] = "float"
            #             import_op.conditions["Well"] = "category"

            tube1 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                         conditions={
                             "Dox": 0.0,
                             "Well": 'A'
                         })

            tube2 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                         conditions={
                             "Dox": 10.0,
                             "Well": 'A'
                         })

            tube3 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs",
                         conditions={
                             "Dox": 0.0,
                             "Well": 'B'
                         })

            tube4 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs",
                         conditions={
                             "Dox": 10.0,
                             "Well": 'B'
                         })

            import_op.tubes = [tube1, tube2, tube3, tube4]

#             self.add_operation(ChannelStatisticPlugin().id)
#             stat_op = self.model.workflow[1].operation
#             stat_op.name = "Test"
#             stat_op.channel = "Y2-A"
#             stat_op.statistic_name = "Geom.Mean"
#             stat_op.by = ["Dox", "Well"]
#             self.model.selected = self.model.workflow[1]

        self.model.modified = False
Beispiel #10
0
    def activated(self):
        
        # if we're coming back from the TASBE task, re-load the saved
        # workflow
        if self.model.backup_workflow:
            self.model.workflow = self.model.backup_workflow
            self.model.backup_workflow = []
            return
        
        # else, set up a new workflow
        
        # add the import op
        if not self.model.workflow:
            self.add_operation(ImportPlugin().id) 
            self.model.selected = self.model.workflow[0]
        
        # if we're debugging, add a few data bits
        if self.model.debug:
            from cytoflow import Tube
                        
            import_op = self.model.workflow[0].operation
            import_op.conditions = {"Dox" : "float", "Well" : "category"}
         
            tube1 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                         conditions = {"Dox" : 0.0, "Well" : 'A'})
         
            tube2 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                         conditions = {"Dox" : 10.0, "Well" : 'A'})
             
            tube3 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs",
                         conditions = {"Dox" : 0.0, "Well" : 'B'})
         
            tube4 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs",
                         conditions = {"Dox" : 10.0, "Well" : 'B'})
         
            import_op.tubes = [tube1, tube2, tube3, tube4]
            
#             from cytoflowgui.op_plugins import ChannelStatisticPlugin

#             self.add_operation(ChannelStatisticPlugin().id)
#             stat_op = self.model.workflow[1].operation
#             stat_op.name = "Test"
#             stat_op.channel = "Y2-A"
#             stat_op.statistic_name = "Geom.Mean"
#             stat_op.by = ["Dox", "Well"]
#             self.model.selected = self.model.workflow[1]
                    
        self.model.modified = False
Beispiel #11
0
 def activated(self):
     
     # if we're coming back from the TASBE task, re-load the saved
     # workflow
     if self.model.backup_workflow:
         self.model.workflow = self.model.backup_workflow
         self.model.backup_workflow = []
         return
     
     # else, set up a new workflow
     # add the import op
     if not self.model.workflow:
         self.add_operation(ImportPlugin().id) 
         self.model.selected = self.model.workflow[0]
                 
     self.model.modified = False
Beispiel #12
0
    def on_new(self):
        if self.model.modified:
            ret = confirm(
                parent=None,
                message=
                "Are you sure you want to discard the current workflow?",
                title="Clear workflow?")

            if ret != YES:
                return

        # clear the workflow
        self.model.workflow = []

        # add the import op
        self.add_operation(ImportPlugin().id)

        # and select the operation
        self.model.selected = self.model.workflow[0]
Beispiel #13
0
def run_gui():
    import os, sys
    try:
        # if we're running as a one-click from a MacOS app,
        # we need to reset the working directory
        os.chdir(sys._MEIPASS)
    except:
        # if we're not running as a one-click, fail gracefully
        pass

    # take care of the 3 places in the cytoflow module that
    # need different behavior in a GUI
    import cytoflow
    cytoflow.RUNNING_IN_GUI = True

    # this is ridiculous, but here's the situation.  Qt5 now uses Chromium
    # as their web renderer.  Chromium needs OpenGL.  if you don't
    # initialize OpoenGL here, things crash on some platforms.

    # so now i guess we depend on opengl too.

    from OpenGL import GL  # @UnresolvedImport @UnusedImport

    # check that we're using the right Qt API
    from pyface.qt import qt_api

    cmd_line = " ".join(sys.argv)

    if qt_api == "pyside":
        print("Cytoflow uses PyQT; but it is trying to use PySide instead.")
        print(" - Make sure PyQT is installed.")
        print(
            " - If both are installed, and you don't need both, uninstall PySide."
        )
        print(" - If you must have both installed, select PyQT by setting the")
        print("   environment variable QT_API to \"pyqt5\"")
        print("   * eg, on Linux, type on the command line:")
        print("     QT_API=\"pyqt5\" " + cmd_line)
        print("   * on Windows, try: ")
        print("     setx QT_API \"pyqt5\"")

        sys.exit(1)

    # parse args
    parser = argparse.ArgumentParser(description='Cytoflow GUI')
    parser.add_argument("--debug", action='store_true')
    parser.add_argument("filename", nargs='?', default="")

    args = parser.parse_args()

    # start the remote process

    remote_process, remote_connection, queue_listener = start_remote_process()

    # getting real tired of the matplotlib deprecation warnings
    import warnings
    warnings.filterwarnings('ignore', '.*is deprecated and replaced with.*')

    # if we're frozen, add _MEIPASS to the pyface search path for icons etc
    if getattr(sys, 'frozen', False):
        from pyface.resource_manager import resource_manager
        resource_manager.extra_paths.append(sys._MEIPASS)  # @UndefinedVariable

    # these three lines stop pkg_resources from trying to load resources
    # from the __main__ module, which is frozen (and thus not loadable.)
    from pyface.image_resource import ImageResource
    icon = ImageResource('icon')
    icon.search_path = []

    # monkey patch the resource manager to use SVGs for icons
    import pyface.resource.resource_manager
    pyface.resource.resource_manager.ResourceManager.IMAGE_EXTENSIONS.append(
        '.svg')

    # monkey patch checklist editor to stop lowercasing
    import traitsui.qt4.check_list_editor  # @UnusedImport
    traitsui.qt4.check_list_editor.capitalize = lambda s: s

    # define and install a message handler for Qt errors
    from traits.api import push_exception_handler

    def QtMsgHandler(msg_type, msg_context, msg_string):
        # Convert Qt msg type to logging level
        log_level = [
            logging.DEBUG, logging.WARN, logging.ERROR, logging.FATAL
        ][int(msg_type)]
        logging.log(log_level, 'Qt message: ' + msg_string)

    from pyface.qt.QtCore import qInstallMessageHandler  # @UnresolvedImport
    qInstallMessageHandler(QtMsgHandler)

    # install a global (gui) error handler for traits notifications
    push_exception_handler(handler=log_notification_handler,
                           reraise_exceptions=False,
                           main=True)

    sys.excepthook = log_excepthook

    # Import, then load, the envisage plugins

    from envisage.core_plugin import CorePlugin
    from envisage.ui.tasks.tasks_plugin import TasksPlugin

    from cytoflowgui.flow_task import FlowTaskPlugin
    from cytoflowgui.tasbe_task import TASBETaskPlugin
    from cytoflowgui.export_task import ExportFigurePlugin
    from cytoflowgui.cytoflow_application import CytoflowApplication
    from cytoflowgui.op_plugins import (
        ImportPlugin, ThresholdPlugin, RangePlugin, QuadPlugin, Range2DPlugin,
        PolygonPlugin, BinningPlugin, GaussianMixture1DPlugin,
        GaussianMixture2DPlugin, BleedthroughLinearPlugin,
        BeadCalibrationPlugin, AutofluorescencePlugin, ColorTranslationPlugin,
        TasbePlugin, ChannelStatisticPlugin, TransformStatisticPlugin,
        RatioPlugin, DensityGatePlugin, FlowPeaksPlugin, KMeansPlugin,
        PCAPlugin)

    from cytoflowgui.view_plugins import (
        HistogramPlugin, Histogram2DPlugin, ScatterplotPlugin, BarChartPlugin,
        Stats1DPlugin, Kde1DPlugin, Kde2DPlugin, ViolinPlotPlugin, TablePlugin,
        Stats2DPlugin, DensityPlugin, ParallelCoordinatesPlugin, RadvizPlugin)

    plugins = [
        CorePlugin(),
        TasksPlugin(),
        FlowTaskPlugin(),
        TASBETaskPlugin(),
        ExportFigurePlugin()
    ]

    # ordered as we want them to show up in the toolbar
    view_plugins = [
        HistogramPlugin(),
        ScatterplotPlugin(),
        Histogram2DPlugin(),
        DensityPlugin(),
        Kde1DPlugin(),
        Kde2DPlugin(),
        RadvizPlugin(),
        ParallelCoordinatesPlugin(),
        ViolinPlotPlugin(),
        BarChartPlugin(),
        Stats1DPlugin(),
        Stats2DPlugin(),
        TablePlugin()
    ]

    plugins.extend(view_plugins)

    op_plugins = [
        ImportPlugin(),
        ThresholdPlugin(),
        RangePlugin(),
        QuadPlugin(),
        Range2DPlugin(),
        PolygonPlugin(),
        RatioPlugin(),
        ChannelStatisticPlugin(),
        TransformStatisticPlugin(),
        BinningPlugin(),
        GaussianMixture1DPlugin(),
        GaussianMixture2DPlugin(),
        DensityGatePlugin(),
        KMeansPlugin(),
        FlowPeaksPlugin(),
        PCAPlugin(),
        AutofluorescencePlugin(),
        BleedthroughLinearPlugin(),
        BeadCalibrationPlugin(),
        ColorTranslationPlugin(),
        TasbePlugin()
    ]

    plugins.extend(op_plugins)

    # start the app

    app = CytoflowApplication(id='edu.mit.synbio.cytoflow',
                              plugins=plugins,
                              icon=icon,
                              remote_process=remote_process,
                              remote_connection=remote_connection,
                              filename=args.filename,
                              debug=args.debug)

    from pyface.qt import QtGui
    QtGui.QApplication.instance().setStyle(
        QtGui.QStyleFactory.create('Fusion'))

    app.run()

    remote_process.join()
    queue_listener.stop()
    logging.shutdown()
Beispiel #14
0
    def setUp(self):
        super().setUp()

        import_plugin = ImportPlugin()
        import_op = import_plugin.get_operation()

        from cytoflow import Tube

        import_op.conditions = {
            "Dox": "float",
            "IP": "float",
            "Well": "category"
        }

        self.cwd = os.path.dirname(os.path.abspath(__file__))

        tube1 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs",
                     conditions={
                         "Dox": 1.0,
                         "IP": 1.0,
                         "Well": 'A'
                     })

        tube2 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs",
                     conditions={
                         "Dox": 1.0,
                         "IP": 10.0,
                         "Well": 'B'
                     })

        tube3 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/YFP_Well_A7.fcs",
                     conditions={
                         "Dox": 10.0,
                         "IP": 1.0,
                         "Well": 'A'
                     })

        tube4 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs",
                     conditions={
                         "Dox": 10.0,
                         "IP": 10.0,
                         "Well": 'B'
                     })

        tube5 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs",
                     conditions={
                         "Dox": 100.0,
                         "IP": 1.0,
                         "Well": 'A'
                     })

        tube6 = Tube(file=self.cwd +
                     "/../../cytoflow/tests/data/Plate01/YFP_Well_C7.fcs",
                     conditions={
                         "Dox": 100.0,
                         "IP": 100.0,
                         "Well": 'B'
                     })

        import_op.tubes = [tube1, tube2, tube3, tube4, tube5, tube6]

        wi = WorkflowItem(operation=import_op,
                          status="waiting",
                          view_error="Not yet plotted")
        self.workflow.workflow.append(wi)

        import_op.do_estimate = True
        self.workflow.wi_waitfor(wi, 'status', 'valid')
        self.assertTrue(
            self.workflow.remote_eval("self.workflow[0].result is not None"))

        stats_plugin = ChannelStatisticPlugin()

        stats_op_1 = stats_plugin.get_operation()
        stats_op_1.name = "MeanByDoxIP"
        stats_op_1.channel = "Y2-A"
        stats_op_1.statistic_name = "Geom.Mean"
        stats_op_1.by = ['Dox', 'IP']
        stats_op_1.subset_list.append(
            CategorySubset(name="Well", values=['A', 'B']))
        stats_op_1.subset_list.append(
            RangeSubset(name="Dox", values=[1.0, 10.0, 100.0]))
        stats_op_1.subset_list.append(
            RangeSubset(name="IP", values=[1.0, 10.0]))

        stats_wi_1 = WorkflowItem(operation=stats_op_1,
                                  status="waiting",
                                  view_error="Not yet plotted")
        self.workflow.workflow.append(stats_wi_1)
        self.workflow.wi_waitfor(stats_wi_1, 'status', 'valid')

        stats_op_2 = stats_plugin.get_operation()
        stats_op_2.name = "SDByDoxIP"
        stats_op_2.channel = "Y2-A"
        stats_op_2.statistic_name = "Geom.SD"
        stats_op_2.by = ['Dox', 'IP']
        stats_op_2.subset_list.append(
            CategorySubset(name="Well", values=['A', 'B']))
        stats_op_2.subset_list.append(
            RangeSubset(name="Dox", values=[1.0, 10.0, 100.0]))
        stats_op_2.subset_list.append(
            RangeSubset(name="IP", values=[1.0, 10.0]))

        stats_wi_2 = WorkflowItem(operation=stats_op_2,
                                  status="waiting",
                                  view_error="Not yet plotted")
        self.workflow.workflow.append(stats_wi_2)
        self.workflow.selected = stats_wi_2
        self.workflow.wi_waitfor(stats_wi_2, 'status', 'valid')
Beispiel #15
0
def run_gui():
    debug = ("--debug" in sys.argv)

    remote_process, remote_connection = start_remote_process(debug)

    import matplotlib

    # We want matplotlib to use our backend
    matplotlib.use('module://cytoflowgui.matplotlib_backend')

    # getting real tired of the matplotlib deprecation warnings
    import warnings
    warnings.filterwarnings('ignore', '.*is deprecated and replaced with.*')

    from traits.api import push_exception_handler

    def QtMsgHandler(msg_type, msg_string):
        # Convert Qt msg type to logging level
        log_level = [
            logging.DEBUG, logging.WARN, logging.ERROR, logging.FATAL
        ][int(msg_type)]
        logging.log(log_level, 'Qt message: ' + msg_string.decode('utf-8'))

    ## monkey-patch envisage for a py3k bug.  this is fixed in envisage HEAD,
    ## so check for version
    import envisage
    if envisage.__version__ == '4.6.0':
        import pickle
        from envisage.ui.tasks.tasks_application import TasksApplication, TasksApplicationState
        logger = logging.getLogger(__name__)
        logger.info("Monkey-patching envisage 4.6.0")

        def _envisage_load_state(self):
            """ Loads saved application state, if possible.
            """
            state = TasksApplicationState()
            filename = os.path.join(self.state_location, 'application_memento')
            if os.path.exists(filename):
                # Attempt to unpickle the saved application state.
                try:
                    with open(filename, 'rb') as f:
                        restored_state = pickle.load(f)
                    if state.version == restored_state.version:
                        state = restored_state
                    else:
                        logger.warn('Discarding outdated application layout')
                except:
                    # If anything goes wrong, log the error and continue.
                    logger.exception('Restoring application layout from %s',
                                     filename)

            self._state = state

        def _envisage_save_state(self):
            """ Saves the application state.
            """
            # Grab the current window layouts.
            window_layouts = [w.get_window_layout() for w in self.windows]
            self._state.previous_window_layouts = window_layouts

            # Attempt to pickle the application state.
            filename = os.path.join(self.state_location, 'application_memento')
            try:
                with open(filename, 'wb') as f:
                    pickle.dump(self._state, f)
            except:
                # If anything goes wrong, log the error and continue.
                logger.exception('Saving application layout')

        TasksApplication._load_state = _envisage_load_state
        TasksApplication._save_state = _envisage_save_state

    from envisage.core_plugin import CorePlugin
    from envisage.ui.tasks.tasks_plugin import TasksPlugin
    from pyface.image_resource import ImageResource

    from cytoflowgui.flow_task import FlowTaskPlugin
    from cytoflowgui.cytoflow_application import CytoflowApplication
    from cytoflowgui.op_plugins import (
        ImportPlugin,
        ThresholdPlugin,
        RangePlugin,
        QuadPlugin,
        Range2DPlugin,
        PolygonPlugin,
        BinningPlugin,
        GaussianMixture1DPlugin,
        GaussianMixture2DPlugin,
        BleedthroughLinearPlugin,  #BleedthroughPiecewisePlugin,
        BeadCalibrationPlugin,
        AutofluorescencePlugin,
        ColorTranslationPlugin,
        TasbePlugin,
        ChannelStatisticPlugin,
        TransformStatisticPlugin,
        RatioPlugin)

    from cytoflowgui.view_plugins import (
        HistogramPlugin,
        Histogram2DPlugin,
        ScatterplotPlugin,
        BarChartPlugin,
        Stats1DPlugin,
        Kde1DPlugin,  #Kde2DPlugin,
        ViolinPlotPlugin,
        TablePlugin,
        Stats2DPlugin)
    #    assert(multiprocessing.get_start_method() == "spawn")

    from cytoflow.utility.custom_traits import Removed, Deprecated
    Removed.gui = True
    Deprecated.gui = True

    from pyface.qt import qt_api

    cmd_line = " ".join(sys.argv)

    if qt_api == "pyside":
        print("Cytoflow uses PyQT; but it is trying to use PySide instead.")
        print(" - Make sure PyQT is installed.")
        print(
            " - If both are installed, and you don't need both, uninstall PySide."
        )
        print(" - If you must have both installed, select PyQT by setting the")
        print("   environment variable QT_API to \"pyqt\"")
        print("   * eg, on Linux, type on the command line:")
        print("     QT_API=\"pyqt\" " + cmd_line)
        print("   * on Windows, try: ")
        print("     setx QT_API \"pyqt\"")

        sys.exit(1)

    from pyface.qt.QtCore import qInstallMsgHandler
    qInstallMsgHandler(QtMsgHandler)

    # if we're frozen, add _MEIPASS to the pyface search path for icons etc
    if getattr(sys, 'frozen', False):
        from pyface.resource_manager import resource_manager
        resource_manager.extra_paths.append(sys._MEIPASS)  # @UndefinedVariable

    # install a global (gui) error handler for traits notifications
    push_exception_handler(handler=log_notification_handler,
                           reraise_exceptions=debug,
                           main=True)

    sys.excepthook = log_excepthook

    plugins = [
        CorePlugin(),
        TasksPlugin(),
        FlowTaskPlugin(debug=debug, remote_connection=remote_connection)
    ]

    # reverse of the order on the toolbar
    view_plugins = [
        TablePlugin(),
        Stats2DPlugin(),
        Stats1DPlugin(),
        BarChartPlugin(),
        ViolinPlotPlugin(),
        #                     Kde2DPlugin(),    # disabled until we can make it faster
        Kde1DPlugin(),
        Histogram2DPlugin(),
        ScatterplotPlugin(),
        HistogramPlugin()
    ]

    plugins.extend(view_plugins)

    op_plugins = [
        RatioPlugin(),
        TransformStatisticPlugin(),
        ChannelStatisticPlugin(),
        TasbePlugin(),
        ColorTranslationPlugin(),
        AutofluorescencePlugin(),
        BeadCalibrationPlugin(),
        #                   BleedthroughPiecewisePlugin(),
        BleedthroughLinearPlugin(),
        GaussianMixture2DPlugin(),
        GaussianMixture1DPlugin(),
        BinningPlugin(),
        PolygonPlugin(),
        QuadPlugin(),
        Range2DPlugin(),
        RangePlugin(),
        ThresholdPlugin(),
        ImportPlugin()
    ]

    plugins.extend(op_plugins)

    # these two lines stop pkg_resources from trying to load resources
    # from the __main__ module, which is frozen (and thus not loadable.)
    icon = ImageResource('icon')
    icon.search_path = []

    app = CytoflowApplication(id='edu.mit.synbio.cytoflow',
                              plugins=plugins,
                              icon=icon,
                              debug=debug)
    app.run()
    remote_process.join()
    logging.shutdown()
Beispiel #16
0
def run_gui():
    debug = ("--debug" in sys.argv)

    remote_process, remote_connection = start_remote_process()

    # We want matplotlib to use our backend .... in both the GUI and the
    # remote process

    import matplotlib
    matplotlib.use('module://cytoflowgui.matplotlib_backend')

    # getting real tired of the matplotlib deprecation warnings
    import warnings
    warnings.filterwarnings('ignore', '.*is deprecated and replaced with.*')

    from traits.api import push_exception_handler

    def QtMsgHandler(msg_type, msg_string):
        # Convert Qt msg type to logging level
        log_level = [
            logging.DEBUG, logging.WARN, logging.ERROR, logging.FATAL
        ][int(msg_type)]
        logging.log(log_level, 'Qt message: ' + msg_string.decode('utf-8'))

    from envisage.core_plugin import CorePlugin
    from envisage.ui.tasks.tasks_plugin import TasksPlugin
    from pyface.image_resource import ImageResource

    from cytoflowgui.flow_task import FlowTaskPlugin
    from cytoflowgui.tasbe_task import TASBETaskPlugin
    from cytoflowgui.export_task import ExportFigurePlugin
    from cytoflowgui.cytoflow_application import CytoflowApplication
    from cytoflowgui.op_plugins import (
        ImportPlugin, ThresholdPlugin, RangePlugin, QuadPlugin, Range2DPlugin,
        PolygonPlugin, BinningPlugin, GaussianMixture1DPlugin,
        GaussianMixture2DPlugin, BleedthroughLinearPlugin,
        BleedthroughPiecewisePlugin, BeadCalibrationPlugin,
        AutofluorescencePlugin, ColorTranslationPlugin, TasbePlugin,
        ChannelStatisticPlugin, TransformStatisticPlugin, RatioPlugin,
        DensityGatePlugin, FlowPeaksPlugin, KMeansPlugin, PCAPlugin)

    from cytoflowgui.view_plugins import (
        HistogramPlugin, Histogram2DPlugin, ScatterplotPlugin, BarChartPlugin,
        Stats1DPlugin, Kde1DPlugin, Kde2DPlugin, ViolinPlotPlugin, TablePlugin,
        Stats2DPlugin, DensityPlugin, ParallelCoordinatesPlugin, RadvizPlugin)

    from cytoflow.utility.custom_traits import Removed, Deprecated
    Removed.gui = True
    Deprecated.gui = True

    from pyface.qt import qt_api

    cmd_line = " ".join(sys.argv)

    if qt_api == "pyside":
        print("Cytoflow uses PyQT; but it is trying to use PySide instead.")
        print(" - Make sure PyQT is installed.")
        print(
            " - If both are installed, and you don't need both, uninstall PySide."
        )
        print(" - If you must have both installed, select PyQT by setting the")
        print("   environment variable QT_API to \"pyqt\"")
        print("   * eg, on Linux, type on the command line:")
        print("     QT_API=\"pyqt\" " + cmd_line)
        print("   * on Windows, try: ")
        print("     setx QT_API \"pyqt\"")

        sys.exit(1)

    from pyface.qt.QtCore import qInstallMsgHandler  # @UnresolvedImport
    qInstallMsgHandler(QtMsgHandler)

    # if we're frozen, add _MEIPASS to the pyface search path for icons etc
    if getattr(sys, 'frozen', False):
        from pyface.resource_manager import resource_manager
        resource_manager.extra_paths.append(sys._MEIPASS)  # @UndefinedVariable

    # install a global (gui) error handler for traits notifications
    push_exception_handler(handler=log_notification_handler,
                           reraise_exceptions=False,
                           main=True)

    sys.excepthook = log_excepthook

    plugins = [
        CorePlugin(),
        TasksPlugin(),
        FlowTaskPlugin(),
        TASBETaskPlugin(),
        ExportFigurePlugin()
    ]

    # reverse of the order on the toolbar
    view_plugins = [
        TablePlugin(),
        Stats2DPlugin(),
        Stats1DPlugin(),
        BarChartPlugin(),
        ViolinPlotPlugin(),
        Kde2DPlugin(),
        RadvizPlugin(),
        ParallelCoordinatesPlugin(),
        Kde1DPlugin(),
        DensityPlugin(),
        Histogram2DPlugin(),
        ScatterplotPlugin(),
        HistogramPlugin()
    ]

    plugins.extend(view_plugins)

    op_plugins = [
        RatioPlugin(),
        PCAPlugin(),
        KMeansPlugin(),
        FlowPeaksPlugin(),
        DensityGatePlugin(),
        TransformStatisticPlugin(),
        ChannelStatisticPlugin(),
        TasbePlugin(),
        ColorTranslationPlugin(),
        AutofluorescencePlugin(),
        BeadCalibrationPlugin(),
        #                   BleedthroughPiecewisePlugin(),
        BleedthroughLinearPlugin(),
        GaussianMixture2DPlugin(),
        GaussianMixture1DPlugin(),
        BinningPlugin(),
        PolygonPlugin(),
        QuadPlugin(),
        Range2DPlugin(),
        RangePlugin(),
        ThresholdPlugin(),
        ImportPlugin()
    ]

    plugins.extend(op_plugins)

    # these two lines stop pkg_resources from trying to load resources
    # from the __main__ module, which is frozen (and thus not loadable.)
    icon = ImageResource('icon')
    icon.search_path = []

    app = CytoflowApplication(id='edu.mit.synbio.cytoflow',
                              plugins=plugins,
                              icon=icon,
                              remote_connection=remote_connection,
                              debug=debug)
    app.run()
    remote_process.join()
    logging.shutdown()