Ejemplo n.º 1
0
 def validate(self):
     errors = []
     mdIn = mdFirstRow(self.InputFile)
     if not mdIn.containsLabel(str2Label(self.InputFileLabel)):
         errors.append(self.InputFile + " does not contain the label " + self.InputFileLabel)
     
     mdSubset = mdFirstRow(self.SubsetFile)
     if not mdSubset.containsLabel(str2Label(self.SubsetFileLabel)):
         errors.append(self.SubsetFile+" does not contain the label " + sself.SubsetFileLabel)
     return errors
Ejemplo n.º 2
0
    def run(self):
        from xmipp import MetaData, str2Label
        from protlib_gui_figure import XmippPlotter

        md = MetaData(self.getParam('-i'))
        if self.checkParam('--xlabel'):
            xlabel = self.getParam('--xlabel')
            mdLabelX = str2Label(xlabel)
        else:
            xlabel = ""
            mdLabelX = None

        if self.checkParam('--xtitle'):
            xlabel = self.getParam('--xtitle')
        ylabels = self.getParam('--ylabel').split()
        if self.checkParam('--ytitle'):
            ylabel = self.getParam('--ytitle')
        else:
            ylabel = ylabels[0]

        colors, lenColors = self.getList('--colors',
                                         ['g', 'b', 'r', 'y', 'c', 'm', 'k'])
        markers, lenMarkers = self.getList('--markers')
        styles, lenStyles = self.getList('--style')

        if self.checkParam('--nbins'):
            nBins = self.getIntParam('--nbins')
        else:
            nBins = None

        title = self.getParam('--title')
        xplotter = XmippPlotter()
        xplotter.createSubPlot(title, xlabel, ylabel)

        for i, l in enumerate(ylabels):
            c = colors[i % lenColors]
            m = markers[i % lenMarkers]
            if m == "none":
                m = None
            s = styles[i % lenStyles]
            if s == "none":
                s = None
            xplotter.plotMd(md,
                            mdLabelX,
                            str2Label(l),
                            color=c,
                            marker=m,
                            linestyle=s,
                            nbins=nBins)  # if nbins is present do an histogram

        legendLocation = self.getParam('--legend')
        if legendLocation != 'none':
            xplotter.showLegend(ylabels, loc=legendLocation.replace('_', ' '))
        xplotter.show()
Ejemplo n.º 3
0
def createSubset(log, inputFile, inputFileLabel, subsetFile, subsetFileLabel, outputFile):
    mdInputFile  = MetaData(inputFile)
    mdSubsetFile = MetaData(subsetFile)
    mdOutputFile = MetaData()
    print inputFile, inputFileLabel, subsetFile, subsetFileLabel, outputFile
    mdOutputFile.join2(  mdInputFile
                       , mdSubsetFile
                       , str2Label(inputFileLabel)
                       , str2Label(subsetFileLabel)
                       , INNER_JOIN)
    mdOutputFile.write(outputFile)
Ejemplo n.º 4
0
 def run(self):        
     from xmipp import MetaData, str2Label
     from protlib_gui_figure import XmippPlotter        
     
     md = MetaData(self.getParam('-i'))
     if self.checkParam('--xlabel'):
         xlabel = self.getParam('--xlabel')
         mdLabelX = str2Label(xlabel)
     else:
         xlabel = ""
         mdLabelX = None
         
     if self.checkParam('--xtitle'):
         xlabel = self.getParam('--xtitle')
     ylabels = self.getParam('--ylabel').split()
     if self.checkParam('--ytitle'):
         ylabel = self.getParam('--ytitle')
     else:
         ylabel = ylabels[0]
     
     colors, lenColors = self.getList('--colors', ['g', 'b', 'r', 'y', 'c', 'm', 'k'])
     markers, lenMarkers = self.getList('--markers')
     styles, lenStyles = self.getList('--style')
     
     if self.checkParam('--nbins'):
         nBins = self.getIntParam('--nbins')
     else:
         nBins = None
         
     
     title = self.getParam('--title')
     xplotter = XmippPlotter()
     xplotter.createSubPlot(title, xlabel, ylabel)
     
     for i, l in enumerate(ylabels):
         c = colors[i % lenColors]
         m = markers[i % lenMarkers]
         if m == "none":
             m = None
         s = styles[i % lenStyles]
         if s == "none":
             s = None
         xplotter.plotMd(md, mdLabelX, str2Label(l), color=c, marker=m, linestyle=s, nbins=nBins)#if nbins is present do an histogram
     
     legendLocation = self.getParam('--legend')
     if legendLocation != 'none':
         xplotter.showLegend(ylabels, loc=legendLocation.replace('_', ' '))
     xplotter.show()
Ejemplo n.º 5
0
def createMetaDataFromPattern(pattern, isStack=False, label="image"):
    ''' Create a metadata from files matching pattern'''
    import glob
    files = glob.glob(pattern)
    files.sort()

    label = xmipp.str2Label(label)  #Check for label value

    mD = xmipp.MetaData()
    inFile = xmipp.FileName()

    nSize = 1
    for file in files:
        fileAux = file
        if isStack:
            if file.endswith(".mrc"):
                fileAux = file + ":mrcs"
            x, x, x, nSize = xmipp.getImageSize(fileAux)
        if nSize != 1:
            counter = 1
            for jj in range(nSize):
                inFile.compose(counter, fileAux)
                objId = mD.addObject()
                mD.setValue(label, inFile, objId)
                mD.setValue(xmipp.MDL_ENABLED, 1, objId)
                counter += 1
        else:
            objId = mD.addObject()
            mD.setValue(label, fileAux, objId)
            mD.setValue(xmipp.MDL_ENABLED, 1, objId)
    return mD
Ejemplo n.º 6
0
 def setValue(self, label, value):
     """args: this list should contains tuples with 
     MetaData Label and the desired value"""
     # Allow setValue using the label string
     if isinstance(label, basestring):
         label = xmipp.str2Label(label)
     self._labelDict[label] = value
Ejemplo n.º 7
0
 def setValue(self, label, value):
     """args: this list should contains tuples with 
     MetaData Label and the desired value"""
     # Allow setValue using the label string
     if isinstance(label, basestring):
         label = str2Label(label)
     self._labelDict[label] = value
Ejemplo n.º 8
0
def createMetaDataFromPattern(pattern, isStack=False, label="image"):
    ''' Create a metadata from files matching pattern'''
    import glob
    files = glob.glob(pattern)
    files.sort()

    from xmipp import MetaData, FileName, getImageSize, MDL_ENABLED, str2Label
    label = str2Label(label) #Check for label value
    
    mD = MetaData()
    inFile = FileName()
    
    nSize = 1
    for file in files:
        fileAux=file
        if isStack:
            if file.endswith(".mrc"):
                fileAux=file+":mrcs"
            x, x, x, nSize = getImageSize(fileAux)
        if nSize != 1:
            counter = 1
            for jj in range(nSize):
                inFile.compose(counter, fileAux)
                objId = mD.addObject()
                mD.setValue(label, inFile, objId)
                mD.setValue(MDL_ENABLED, 1, objId)
                counter += 1
        else:
            objId = mD.addObject()
            mD.setValue(label, fileAux, objId)
            mD.setValue(MDL_ENABLED, 1, objId)
    return mD
Ejemplo n.º 9
0
    def _convertTableToMd(self, table):
        colLabels = [(col.getName(), xmipp.str2Label(col.getName())) for col in table.iterColumns()]
        md = xmipp.MetaData()

        for row in table.iterRows():
            objId = md.addObject()
            for col, label in colLabels:
                if col != "id":
                    value = getattr(row, col)
                    md.setValue(label, value, objId)

        return md
Ejemplo n.º 10
0
    def _convertTableToMd(self, table):
        colLabels = [(col.getName(), xmipp.str2Label(col.getName()))
                     for col in table.iterColumns()]
        md = xmipp.MetaData()

        for row in table.iterRows():
            objId = md.addObject()
            for col, label in colLabels:
                if col != 'id':
                    value = getattr(row, col)
                    md.setValue(label, value, objId)

        return md
Ejemplo n.º 11
0
 def getValue(self, label, default=None):
     """ Return the value of the row for a given label. """
     # Allow getValue using the label string
     if isinstance(label, basestring):
         label = xmipp.str2Label(label)
     return self._labelDict.get(label, default)
Ejemplo n.º 12
0
 def containsLabel(self, label):
     # Allow getValue using the label string
     if isinstance(label, basestring):
         label = xmipp.str2Label(label)
     return label in self._labelDict
Ejemplo n.º 13
0
 def getValue(self, label, default=None):
     """ Return the value of the row for a given label. """
     # Allow getValue using the label string
     if isinstance(label, basestring):
         label = str2Label(label)
     return self._labelDict.get(label, default)
Ejemplo n.º 14
0
 def containsLabel(self, label):
     # Allow getValue using the label string
     if isinstance(label, basestring):
         label = str2Label(label)
     return label in self._labelDict