Exemplo n.º 1
0
 def __init__(self, parent):
     wx.Dialog.__init__(self, parent, wx.ID_ANY, 'Cluster Center Chooser', size=(550, 550))
     self.CenterOnParent()
     
     self.centers = []
     
     # set up the plotting panel
     self.dataPanel = CenterChooserPanel(self, self.OnClick)
     (self.dataSelectors, self.selectorSizer) = customsizers.ChannelSelectorSizer(self)
     
     if DataStore.getCurrentIndex() is not None:
         self.dataPanel.addData(DataStore.getCurrentIndex())
         
         # filter the list of labels to include only user-selected ones
         selDims = DataStore.getCurrentDataSet().selDims
         labels = [DataStore.getCurrentDataSet().labels[i] for i in selDims]
         customsizers.populateSelectors(self.dataSelectors, labels, selDims)        
         self.dataPanel.updateAxes((selDims[0],selDims[1]))
     
     # main sizer
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.sizer.Add(self.dataPanel, True, wx.EXPAND | wx.BOTTOM | wx.TOP, -20)
     self.sizer.AddSpacer(20)
     self.sizer.Add(self.selectorSizer, False, wx.EXPAND | wx.TOP, 20)
     self.sizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), False, wx.EXPAND)
     
     self.SetSizer(self.sizer)
     self.SetBackgroundColour("white")
Exemplo n.º 2
0
 def OnCluster(self, event):
     """
     Handles all clustering requests.
     
     Clustering requests are handled in the following method:
         1. Passes the requested clustering method to 
            L{cluster.dialogs.ClusterOptionsDialog.showDialog} method 
         2. Passes the data and the returned method options to L{cluster.methods.cluster}
         3. Passes the returned cluster membership list to the FacsPlotPanel for display
     """
     dlg = cDlgs.getClusterDialog(event.GetId(), self)
     if dlg.ShowModal() == wx.ID_OK:
         if (DataStore.getCurrentDataSet() is not None):
             self.statusbar.SetStatusText('Running %s clustering...' % cMthds.methods[event.GetId()][1], 0)
             fcs = DataStore.getCurrentDataSet()
             data = fcs.data
             # Remove columns from analysis as specified by the user
             if len(fcs.selDims) > 0:
                 data = dh.filterData(data, fcs.selDims)
             clusterIDs, msg = cMthds.cluster(event.GetId(), data, **dlg.getMethodArgs())
             DataStore.addClustering(event.GetId(), clusterIDs, dlg.getMethodArgs())
             clusteringIndex = DataStore.getCurrentDataSet().clustering.keys()[-1]
             self.statusbar.SetStatusText(msg, 0)
             if (dlg.isApplyChecked()):
                 if self.facsPlotPanel.SelectedSubplotIndex is not None:
                     self.facsPlotPanel.CurrentSubplot = dv.Subplot(self.facsPlotPanel.SelectedSubplotIndex, 
                                                                    DataStore.getCurrentIndex(), clusteringIndex)
                     self.facsPlotPanel.draw()
                 else:
                     self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex(), clusteringIndex)
             self.treeCtrlPanel.updateTree()
     dlg.Destroy()
Exemplo n.º 3
0
 def AddChosenCenter(self, point):
     cbxSelected = self._GetSelectedAxes()
     dims = DataStore.getCurrentDataSet().labels
     if (DataStore.getCurrentDataSet().selDims):
         dims = DataStore.getCurrentDataSet().selDims
     retPoint = [0 for i in dims] 
     for i in range(len(cbxSelected)):
         retPoint[cbxSelected[i]] = point[i]
     
     self.centers.append(retPoint)
     self.dataPanel.addCenter(retPoint)
Exemplo n.º 4
0
def isolateClusters(selection, datasetName):
    """
    Create a new data set from a selection of clusters.
    
    @type selection: list
    @var selection: The indices of the clusters to be merged.
    @type datasetName: str
    @var datasetName: The display name for the new data set.
    """
    if (len(selection) > 0):
        currFCData = DataStore.getCurrentDataSet()
        if (datasetName == ""):
            datasetName = currFCData.displayname
        clusters = separate(currFCData.data, currFCData.getCurrentClustering())
        # merge selected clusters
        newData = dh.mergeData(selection, clusters)
        # assign new data set to the store
        newFCData = FacsData('', currFCData.labels, newData, parent=currFCData.ID)
        newFCData.displayname = datasetName
        newFCData.selDims = currFCData.selDims
        
        # add basic text annotations
        textAnn = {'parent': currFCData.displayname}
        textAnn['events'] = len(newFCData.data)
        newFCData.annotations['text'] = textAnn
        
        DataStore.add(newFCData)
Exemplo n.º 5
0
 def addSubplot(self):
     cds = DataStore.getCurrentDataSet()
     if cds is None:
         return
     
     try:
         clusteringIndex = cds.clustering.keys()[-1]
     except IndexError:
         self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex())
     else:
         self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex(), clusteringIndex)
Exemplo n.º 6
0
    def OnLoadState(self, event):
        from data.io import loadState
        
        if len(DataStore.getData()) > 0:
            dlgWarn = wx.MessageDialog(self, 'This action may overwrite currently loaded datasets and/or plots.\n\nContinue anyway?', 'Warning', 
                                   wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING)
            if dlgWarn.ShowModal() == wx.ID_NO:
                dlgWarn.Destroy()
                return
            dlgWarn.Destroy()

        formats = "FIND Project File (*.find)|*.find"
        dlg = wx.FileDialog(self, "Select saved project", self.dirname, "", formats, wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            try:
                loadState(dlg.Directory, dlg.Filename)
            except error.ProjectLoadingError:
                return
            # Load all Figures with Subplot instances from the stored dicts
            for fID in FigureStore.getFigures():
                fig = FigureStore.get(fID)
                splots = []
                for plot in fig.subplots:
                    s = dv.Subplot()
                    s.load(plot)
                    s.parent = self.facsPlotPanel.figure
                    splots.append(s)
                fig.subplots = splots
            
            currFigure = FigureStore.getSelectedFigure()
            self.facsPlotPanel.subplots = currFigure.subplots
            self.facsPlotPanel.SelectedSubplotIndex = currFigure.selectedSubplot
            self.facsPlotPanel.updateAxes(currFigure.axes, False)
            self.facsPlotPanel.updateSubplotGrid(currFigure.grid[0], currFigure.grid[1], True)
            self.chkLinked.Value = self.facsPlotPanel.CurrentSubplotLinked
            labels = DataStore.getCurrentDataSet().labels if DataStore.getCurrentDataSet() is not None else []
            self.updateAxesList(labels, currFigure.axes)
            self.treeCtrlPanel.updateTree()
            self.statusbar.SetStatusText("Project loaded from %s" % dlg.Path, 0)
        
        dlg.Destroy()
Exemplo n.º 7
0
 def OnAnalyze(self, event):
     """
     Handles all requests for analysis methods; built-in and plugins.
     
     Currently, analysis methods expect data, a list of dimensions
     available to use in analysis, and a window ref in order to 
     display a subwindow/dialog with results or options.
     
     Analysis methods are expected to return data and/or a status
     message. Currently returned data is only used when called from
     code, not from the menu; which this method represents.
     """
     if (DataStore.getCurrentDataSet() is not None):
             strID = aMthds.strID(event.GetId())
             self.statusbar.SetStatusText('Running %s...' % aMthds.AvailableMethods()[strID][2], 0)
             fcs = DataStore.getCurrentDataSet()
             data = fcs.data
             # Remove columns from analysis as specified by the user
             if len(fcs.selDims) > 0:
                 data = dh.filterData(data, fcs.selDims)
             args = {'parentWindow': self}
             _, msg = aMthds.getMethod(strID)(data, **args)
             self.statusbar.SetStatusText(msg, 0)
Exemplo n.º 8
0
 def OnExport(self, event):
     if DataStore.getCurrentIndex() is None:
         wx.MessageBox("Please load a dataset before attempting to export",
                       "Data Missing", wx.OK | wx.ICON_ERROR)
         return
     
     format = io.getMethod(event.GetId())().FileType
     dlg = wx.FileDialog(self, "Save File", "", "", 
                         format, 
                         wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.FD_CHANGE_DIR)
     if dlg.ShowModal() == wx.ID_OK:
         io.exportDataFile(event.GetId(), dlg.Path, DataStore.getCurrentDataSet(), window=self)
     
     dlg.Destroy()
Exemplo n.º 9
0
 def OnEditChannelNames(self, event):
     """
     Allow users to modify the descriptors for each channel (dimension)
     """
     fcData = DataStore.getCurrentDataSet()
     if fcData is not None:
         dgridDlg = displayDialogs.SampleDataDisplayDialog(self, fcData.data[0:10,:], 
                                                           fcData.labels, 'Edit Channel Labels',
                                                           False, False)
         if (dgridDlg.ShowModal() == wx.ID_OK):
             # reassign FacsData instance labels
             for fcd in DataStore.getData().values():
                 labels = [item[1] for item in sorted(dgridDlg.ColumnLabels.iteritems(), key=itemgetter(0))]
                 fcd.labels = labels
             # update channel selection cbxs
             self.updateAxesList(labels, self.facsPlotPanel.SelectedAxes)
             # refresh plot window
             self.facsPlotPanel.draw()
             
         dgridDlg.Destroy()
     else:
         wx.MessageBox("There are no data currently loaded.", "Error", wx.OK | wx.ICON_ERROR)
Exemplo n.º 10
0
    def OnOpen(self, event):
        """
        Opens a FACS data file, parses it, and updates the FacsPlotPanel instance.
        """
        # retrieve the I/O methods for inputting files
        inputMethods = [m[2]() for m in io.AvailableMethods().values()]
        formats = '|'.join([m.FileType for m in inputMethods if io.FILE_INPUT in m.register()])
        allLabels = []
        allColArr = []
        allDims   = []
        fColsMoved = False
        numLoaded = 0
        
        # keep track of the common number of dimensions for datasets
        numDims = DataStore.getCurrentDataSet()
        if numDims is not None:
            numDims = len(numDims.labels)
        
        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", formats, 
                            wx.FD_OPEN|wx.FD_MULTIPLE|wx.FD_CHANGE_DIR)
        if dlg.ShowModal() == wx.ID_OK:
            #TODO: move to data.io module?
            # process each file selected
            for n, path in enumerate(dlg.Paths):
                self.statusbar.SetStatusText('loading: ' + path, 0)
                try:
                    (labels, data, annotations) = io.loadDataFile(path, window=self)
                except TypeError:
                    # if there was an error loading the file, 
                    # loadDataFile should return None, so skip this file
                    continue
                
                # make sure the new file matches dimensions of loaded files
                if numDims is None:
                    numDims = len(labels)
                elif len(labels) != numDims:
                    wx.MessageBox("Error loading file: %s\n\nThe number of channels does not match those in currently loaded datasets. \n\nThis file will not be loaded." % dlg.Filenames[n],
                                  "File Error", wx.OK | wx.ICON_ERROR)
                    continue
                    
                
                # Give the user a brief preview of the data (10 rows) and allow
                # column rearrangement and renaming
                if (not allLabels):
                    dgridDlg = displayDialogs.SampleDataDisplayDialog(self, data[0:10,:], labels)
                    if (dgridDlg.ShowModal() == wx.ID_OK):
                        ca = dgridDlg.ColumnArrangement
                        lbls = dgridDlg.ColumnLabels
                        # Reassign the column labels
                        labels = [lbls[i] for i in ca]
                        
                        if dgridDlg.ApplyToAll:
                            allLabels = list(labels)
                            allColArr = list(ca)
                        
                        # Rearrange the data columns
                        if (dgridDlg.ColumnsMoved):
                            fColsMoved = True
                            data = dh.reorderColumns(data, ca)
                    else:
                        dgridDlg.Destroy()
                        continue
                    dgridDlg.Destroy()
                else:
                    labels = list(allLabels)
                    if fColsMoved:
                        data = dh.reorderColumns(data, allColArr)
                    
                # update the DataStore
                DataStore.add(FacsData(dlg.Filenames[n], labels, data, annotations=annotations))
                numLoaded += 1
                if n == 0:
                    self.updateAxesList(labels)
                    
                if (not allDims):
                    # Allow the user to choose columns for use in analysis
                    dimDlg = displayDialogs.DimensionExclusionDialog(self, labels)
                    dimDlg.Size=(dimDlg.Size[0]*.75, dimDlg.Size[1]*.8)
                    if (dimDlg.ShowModal() == wx.ID_OK):
                        DataStore.getCurrentDataSet().selDims = dimDlg.SelectedDimensions
                        if (dimDlg.ApplyToAll):
                            allDims = list(dimDlg.SelectedDimensions)
                    dimDlg.Destroy()
                else:
                    DataStore.getCurrentDataSet().selDims = list(allDims)

                # update the panel
                self.facsPlotPanel.updateAxes([0,1])
                if (len(self.facsPlotPanel.subplots) == 0 or len(dlg.Paths) > 1):
                    self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex())
        
            # Create an n/2 x 2 grid for the n selected data files
            if (numLoaded > 1):
                self.facsPlotPanel.updateSubplotGrid(int(math.ceil(numLoaded/2.0)), 2)
            self.statusbar.SetStatusText('All data files loaded.')
            
            if FigureStore.isEmpty():
                fig = Figure('Default', self.facsPlotPanel.subplots, 1,
                             self.facsPlotPanel.Grid, 
                             self.facsPlotPanel.SelectedAxes)
                FigureStore.add(fig)
            self.treeCtrlPanel.updateTree()
            
        dlg.Destroy()