Example #1
0
    def on_actionAddToExperimentalData_triggered(self):
        '''
        Adds the currently displayed data and adds it to the experimental data.
        This is usually only useful if you want to want to use simulation results (which can then be perturbed)
        as input for other tools like parameter value estimation.
        '''
        logging.info("Adding current data to Experimental Data...")
        dataService = DataService()
        expDataSet = DataSet(None)
        expDataSet.setId("Pseudo-Experimental Data")
        expDataSet.setType(services.dataservice.EXPERIMENTAL)
        expDataSet.setSelected(True)
        first = True
        for key, list in self.data.items():
            for oldItem in list:
                item = oldItem.copy()

                if type(item.getId()) != str:
                    logging.debug(
                        "TableWidgetController.on_actionAddToExperimentalData_triggered(): Encountered item with non-string as id: %s. Skipping."
                        % str(item.getId()))
                    continue
                #                item.setId(item.getId() + "_syn")
                item.setType(datamanagement.entitydata.TYPE_EXPERIMENTAL)
                item.setAssociatedDataSet(expDataSet)
                expDataSet.data[
                    key] = item  # TODO: Handle mutliple EntityData objects correctly
                if first:
                    expDataSet.dataDescriptors = item.dataDescriptors[:]
                    expDataSet.dataDescriptorUnit = item.dataDescriptorUnit
                    first = False
        dataService.add_data(expDataSet)
Example #2
0
    def __init__(self, parent, parkinController):
        super(DataImportWidget, self).__init__(parent)
        self.setupUi(self)

        self.currentExpDataFilename = None
        self.dataService = DataService()
        self.parkinController = parkinController
Example #3
0
    def on_button_FromData_clicked(self):
        try:
            dataService = DataService()
            expData = dataService.get_experimental_data()
            timepointSet = set()
            if expData:
                for dataSet in expData.values():
                    if not dataSet.isSelected():
                        continue
                    if dataSet.dataDescriptors:
                        for dataDescriptor in dataSet.dataDescriptors:
                            timepointSet.add(float(dataDescriptor))
                    for entityData in dataSet.getData().values():
                        if not entityData.isSelected():
                            continue
                        if entityData.dataDescriptors:
                            for dataDescriptor in entityData.dataDescriptors:
                                timepointSet.add(float(dataDescriptor))
            self.timepoints = list(timepointSet)
            self.timepoints.sort()
            timepointsStr = str(self.timepoints).replace(
                ",", " ").strip("[").strip("]")

            if not timepointsStr:
                timepointsStr = "No timepoint data."

            self.plainTextEdit_Timepoints.clear()
            self.plainTextEdit_Timepoints.insertPlainText(timepointsStr)
        except Exception, e:
            logging.error("Could not get timepoints from data. Error: %s" % e)
Example #4
0
 def _initialize(self):
     self.dataService = DataService()
     self.experimentalData = None
     self.simulationData = None
     self.dataSourceTableModel = None
     self.dataSourceIDs = []
     self.allData = None
     self.dataSources = None
 def _initialize(self):
     self.dataService = DataService()
     self.experimentalData = None
     self.simulationData = None
     self.dataSourceTableModel = None
     #        self.dataSourceTableView = QTableView(None)
     #        self.DataIndexToDataID = {}
     self.dataSourceIDs = []
     self.allData = None
     self.dataSources = None
Example #6
0
    def on_buttonSaveAs_clicked(self):
        logging.debug("Saving data. Displaying file chooser...")
        file_choices = "Tab-Delimited Text File *.txt (*.txt)"

        path = unicode(
            QFileDialog.getSaveFileName(self, 'Save file', '',
                                        file_choices)[0])

        if not path.endswith(".txt"):
            path += ".txt"

        if path:
            if not self.dataService:
                self.dataService = DataService()

            id = self.data.getId()
            self.dataService.save_data_as_csv(id, path)
            logging.info("Saved data to %s" % path)
Example #7
0
    def __init__(self, args, parent=None):
        """
        This initialization does a lot of stuff. :)

        * State variables are set up
        * Views are created and tied to UI parts (e.g. Docks)
        * Logging is set up
        * Services (StatusBar, Data, ...) are started
        * Necessary slots are connected

        """
        super(BioParkinController, self).__init__(parent)

        #locale.setlocale(locale.LC_ALL, 'de_DE')
        #        locale.setlocale(locale.LC_ALL, 'deu_deu')

        self.startTime = time.localtime()


        # set file logger
        self.rotatingFileHandler = logging.handlers.RotatingFileHandler(_LOG_FILENAME,
                                                       maxBytes=1000000,
                                                       backupCount=5)
        self.rotatingFileHandler.setFormatter(logging.Formatter("%(asctime)s | %(levelname)s | %(message)s"))
        self.logger = logging.getLogger() #gets root logger
        self.logger.addHandler(self.rotatingFileHandler)

        # Status bar logger
        self.statusBarLoggingHandler = StatusBarLoggingHandler()
        self.statusBarLoggingHandler.setLevel(logging.INFO) # only log on info level
        self.logger.addHandler(self.statusBarLoggingHandler)


        # set GUI logger
        #        self.loggingView = QtLoggingView(self)
        #        loggingHandler = QtLoggingHandler(self.loggingView)
        #        loggingHandler.setLevel(logging.INFO)
        #        self.logger.addHandler(loggingHandler)

        # filling log dock area (was set up in QtDesigner)
        #        self._logDockWidget.setWidget(self.loggingView)
        #        self._logDockWidget.hide()


        # parse command line arguments
        parser = OptionParser()
        parser.add_option("-d", "--debug",
                  action="store_true", dest=OPTION_DEBUG, default=False,
                  help="Include debugging information in console and file log")
        self.options, args = parser.parse_args()

        self.optionsService = OptionsService()
        self.optionsService.setDebug(self.options.debug)

        # set logging options
        if self.options.debug:
            self.logger.setLevel(logging.DEBUG)
            self.rotatingFileHandler.setLevel(logging.DEBUG)
            logging.info("Debug logging active.")
        else:
            self.logger.setLevel(logging.INFO)
            self.rotatingFileHandler.setLevel(logging.INFO)
            logging.info("Debug logging not active.")

        logging.debug("Starting BioPARKIN... %s" % self.startTime)

        ##### LOGGING #####
        logging.info("BioPARKIN started (version %s)" % BioParkinController.__version__)
        logging.info("Command line arguments: %s" % args)
        logging.info("Python version: %s" % sys.version)
#        logging.info("SIP version: %s" % sip.SIP_VERSION_STR)
        #logging.info("PyQt version: %s" % PYQT_VERSION_STR)
        logging.info("PySide version: %s" % PySide.__version__)
        logging.info("libSBML version: %s" % LIBSBML_VERSION_STRING)
        logging.info("Matplotlib version: %s" % matplotlib.__version__)
#        logging.info("NetworkX version: %s" % networkx.__version__)
        logging.info("Python Image Library version: %s" % Image.VERSION)






        self.setupUi(self)
        self._mdiArea.hide()
        self.setWindowTitle("BioPARKIN v%s" % BioParkinController.__version__)

        # restore previous settings
        settings = QSettings()
        try:
            self.recentFiles = settings.value("RecentFiles", [])

            # handles the case if only one file is in the "list" in Linux (it's retrieved as unicode string in this case)
            if type(self.recentFiles) is str or type(self.recentFiles) is unicode:
                self.recentFiles = [self.recentFiles]
                
            logging.info("Recently opened files: %s" % self.recentFiles)
        except:
            logging.warning("Can't access list of recently opened files. Resetting the list.")
            self.recentFiles = []

        self.updateFileMenu()
        self.aboutDialog = None

        geometry = settings.value("Geometry")
        if geometry:
            self.restoreGeometry(geometry)

        state = settings.value("MainWindow/State")
        if state:
            self.restoreState(state)


        self.ModelControllers = {}
#        self.SubWindowToModelControllers = {}
#        self.NetworkWindowCount = 0
#        self.ActiveNetworkWindow = None
        self.ActiveModelController = None
#        self.networkSubWindows = {}

        self.integrator = None
        self.odeViewer = None

        self.ModelView = ModelView(self.masterDetailSplitter, self)
        self.ModelTreeView = SBMLEntityWidget(self.masterDetailSplitter)
        self.EntityTableView = EntityTableView(self.masterDetailSplitter)
#        self.masterDetailSplitter.widget(0).destroy()
#        logging.debug("1st Child of Splitter: %s" % self.masterDetailSplitter.widget(0))

        self.mainWindowViews = [self.ModelTreeView, self.EntityTableView]   #used to iterate over Views



        # set up Data Service and Data Viewer
        datahandling.parkinController = self
        self.dataService = DataService()


        # debugging#############
        BASE_PATH = reduce(lambda l, r: l + os.path.sep + r,
                           os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[:-1])
        #BASE_PATH = os.path.dirname(os.path.realpath(__file__))

        # add ../../templates (relative to the file (!) and not to the CWD)
        dataPath = os.path.join(BASE_PATH, "data")
        #######################

        self.SimulationWorkbenchController = SimulationWorkbenchController(parent=None, parkinController=self)
        self.mainTabWidget.addTab(self.SimulationWorkbenchController, "Workbench")




        # hook up status bar with progress service (that threads can connect to)
        self.statusBarService = StatusBarService(self.statusBar()) # first time, service is instantiated => give statusBar reference!
#        self.statusBarService.setStatusBar(self.statusBar())
        self.progressBarService = ProgressBarService(self, self.statusBarService)

        self.statusBarLoggingHandler.setStatusBar(self.statusBarService)

        self.warningsService = WarningService.getInstance()
        self.warningsDialog = WarningsDialog(self, self.actionShow_Warnings, self.warningsService)


        # register signals

#        self.connect(self._mdiArea, SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.on_networkwindow_raised)
        self.activeModelChanged.connect(self.on_activeModelChanged)
#        self.activeModelChanged.connect(self.selectNetworkView) # put into own method -> easier to put in own class later
        self.modelClosed.connect(self.on_modelClosed)
#        self.modelClosed.connect(self.closeNetworkWindow) # put into own method -> easier to put in own class later
        self.menuFile.aboutToShow.connect(self.updateFileMenu)


        # for debugging
        self.dummyThread = None

        try:    # try to set correct taskbar icon in Windows 7
            myappid = 'ZIB.BioPARKIN' # arbitrary string
            ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
        except:
            pass
Example #8
0
    def __init__(self, parent=None):
        '''
        Creates a data model from the data (so that changes in the data
        are reflected in the View).
        
        '''
        super(DataViewingController, self).__init__(parent)
        self.setupUi(self)

        self.dataService = DataService()
        experimentalData = self.dataService.get_experimental_data()
        simulationData = self.dataService.get_simulation_data()

        #data = ordereddict()
        self.data = OrderedDict()
        if simulationData is not None and len(simulationData) > 0:
            self.simulationData = simulationData
            for (sbmlEntity, entityData) in self.simulationData.items():
                #sbmlRef = entityData.sbmlEntity
                dataTuple = (entityData, None)
                self.data[sbmlEntity] = dataTuple
        else:
            self.simulationData = None

        if experimentalData is not None:
            self.experimentalData = experimentalData
            for (sbmlEntity, entityData) in experimentalData.items():
                #sbmlRef = entityData.sbmlEntity
                if sbmlEntity in self.data:
                    dataTuple = self.data[sbmlEntity]
                    dataTuple = (dataTuple[0], entityData)
                    self.data[sbmlEntity] = dataTuple
                else:
                    dataTuple = (entityData, None)
                    self.data[sbmlEntity] = dataTuple
        else:
            self.experimentalData = None

        if self.experimentalData or self.simulationData:
            self.dataModel = SourcesTableModel(
                combinedData=self.data
                #experimentalData = self.experimentalData,
                #simulationData = self.simulationData
            )
            self.connect(self.dataModel,
                         SIGNAL("dataChanged(QModelIndex, QModelIndex)"),
                         self.update_plots)

        #self.data = []  # create single list with all data entities
#        for item in self.experimentalData:
#            self.data.append(item)
#        for item in self.simulationData:
#            if item in self.data:
#                continue
#            self.data.append(item)

        self.populate_sources_table()

        #        self.plotWindows = {}
        #        self.flatListOfPlotWidgets = []
        self.existingPlotWindows = {}
        self.update_plots()  # testing