Esempio n. 1
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)
Esempio n. 2
0
File: io.py Progetto: 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)