def OnAddFigure(self, event): if len(DataStore.getData()) == 0: return nameDlg = displayDialogs.EditNameDialog(self, '') if (nameDlg.ShowModal() == wx.ID_OK): newFig = Figure(nameDlg.Text, [dv.Subplot()], 1, (1,1), (0,1)) currFig = FigureStore.getSelectedFigure() FigureStore.add(newFig) dv.switchFigures(self.facsPlotPanel, currFig, newFig) self.facsPlotPanel.subplots = [] self.addSubplot() self.treeCtrlPanel.updateTree() nameDlg.Destroy()
def loadState(dir, filename): """ Restore the system state as stored to disk. @type dir: string @param path: The directory under which the the saved system state is stored @type filename: str @param filename: The name of the saved project file (.find) @rtype: tuple @return: A list of subplot settings (dicts) retrieved from the file, The index of the currently selected subplot, The currently selected axes, The number of rows and columns in the figure (grid size) """ store = shelve.open(os.path.join(dir, filename)) #store = dbopen(os.path.join(dir, filename)) datakeys = store['data'] try: bindata = np.load(os.path.join(dir,store['binfile'])) except IOError: bindata = None except BadZipfile: wx.MessageBox('The file \'%s\' may have become corrupted. Project loading has been cancelled' % store['binfile'], 'Data Loading Error', wx.OK|wx.ICON_ERROR) raise ProjectLoadingError('BadZipfile: %s' % os.path.join(dir,store['binfile'])) # Parse data sets for dID in datakeys: dStr = 'data-%s' % dID dsett = store[dStr] ann = dsett['annotations'] if 'annotations' in dsett else {} ana = dsett['analysis'] if 'analysis' in dsett else {} fdata = FacsData(dsett['filename'], dsett['labels'], bindata[dStr], annotations=ann, analysis=ana, parent=dsett['parent']) fdata.displayname = dsett['displayname'] fdata.ID = dsett['ID'] fdata.children = dsett['children'] fdata.selDims = dsett['selDims'] fdata.nodeExpanded = dsett['nodeExpanded'] # Parse clusterings for cID in dsett['clustering']: cStr = 'clust-%i-%i' % (dID, cID) csett = store[cStr] clusterIDs = bindata[cStr] fdata.addClustering(csett['method'], clusterIDs, csett['opts'], cID) fdata.clusteringSelDims[cID] = csett['clusteringSelDims'] fdata.infoExpanded[cID] = csett['infoExpanded'] DataStore.add(fdata) DataStore.selectDataSet(store['current-data']) # Figures if 'figures' in store: for fStr in store['figures']: fDict = store[fStr] splots = [] for pStr in fDict['subplots']: splots.append(store[pStr]) fDict['subplots'] = splots f = Figure() f.load(fDict) FigureStore.add(f) # handle older save files w/o Figure support else: # load the saved subplots into a new 'Default' Figure plots = [] for pStr in store['plots']: plots.append(store[pStr]) defFig = Figure('Default', plots, store['current-subplot'], store['grid'], store['selected-axes']) FigureStore.add(defFig) if 'current-figure' in store: FigureStore.setSelectedFigure(store['current-figure']) else: FigureStore.setSelectedFigure(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()