Example #1
0
 def applyToSelection(self, dataFunc, clustFunc):
     """
     Apply a function to the data selection depending on whether it refers
     to a FacsData object or a clustering of a FacsData object.
     
     @type dataFunc: function
     @param dataFunc: A function to apply to the FacsData object selected.
     @type clustFunc: function
     @param clustFunc: A function to apply to the clustering of the FacsData
         object selected.
     """
     data = self.getSanitizedItemSelectionData()
     
     if data is not None and data[0] is DATA_SET_ITEM:
         # determine if item is a data set or a clustering and select it
         if len(data) == 2:
             dataFunc(data[1])
         if len(data) == 3:
             clustFunc(DataStore.selectDataSet(data[1]), data[2])
Example #2
0
File: io.py Project: smdabdoub/find
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)