Example #1
0
    def importCoordinates(self, fileName, addCoordinate):
        if exists(fileName):
            ext = getExt(fileName)
            
            if ext == ".json":
                jsonPosDict = loadJson(fileName)
                
                if jsonPosDict.has_key("boxes"):
                    boxes = jsonPosDict["boxes"]

                    for box in boxes:
                        x, y = box[:2]
                        coord = Coordinate()
                        coord.setPosition(x, y)
                        addCoordinate(coord)
                        
            elif ext == ".box":
                md = MetaData()
                md.readPlain(fileName, "xcoor ycoor particleSize")
                size = md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject())
                if size is None:
                    print ">>> WARNING: Error parsing coordinate file: %s" % fileName
                    print "             Skipping this file."
                else:
                    half = size / 2
                    for objId in md:
                        x = md.getValue(MDL_XCOOR, objId)
                        y = md.getValue(MDL_YCOOR, objId)
                        coord = Coordinate()
                        coord.setPosition(x+half, y+half)
                        addCoordinate(coord)
            else:
                raise Exception('Unknown extension "%s" to import Eman coordinates' % ext)
Example #2
0
    def importCoordinates(self, fileName, addCoordinate):

        if exists(fileName):
            ext = getExt(fileName)
            if ext == ".json":
                print "importando un json"
                jsonPosDict = loadJson(fileName)

                if jsonPosDict.has_key("boxes"):
                    boxes = jsonPosDict["boxes"]

                    for box in boxes:
                        x, y = box[:2]
                        coord = Coordinate()
                        coord.setPosition(x, y)
                        addCoordinate(coord)
            elif ext == ".box":
                md = MetaData()
                md.readPlain(fileName, 'xcoor ycoor xSize ySize')
                for objId in md:
                    x = md.getValue(MDL_XCOOR, objId)
                    y = md.getValue(MDL_YCOOR, objId)
                    coord = Coordinate()
                    coord.setPosition(x, y)
                    addCoordinate(coord)
            else:
                print "importando un queseyo"
Example #3
0
def convertBinaryFiles(imgSet, outputDir, extension='mrcs'):
    """ Convert binary images files to a format read by Relion.
    Params:
        imgSet: input image set to be converted.
        outputDir: where to put the converted file(s)
    Return:
        A dictionary with old-file as key and new-file as value
        If empty, not conversion was done.
    """
    filesDict = {}
    ih = em.ImageHandler()
    # This approach can be extended when
    # converting from a binary file format that
    # is not read from Relion
    def createBinaryLink(fn):
        """ Just create a link named .mrcs to Relion understand 
        that it is a binary stack file and not a volume.
        """
        newFn = join(outputDir, replaceBaseExt(fn, extension))
        createLink(fn, newFn)
        return newFn
        
    def convertStack(fn):
        """ Convert from a format that is not read by Relion
        to an spider stack.
        """
        newFn = join(outputDir, replaceBaseExt(fn, 'stk'))
        ih.convertStack(fn, newFn)
        return newFn
        
    ext = getExt(imgSet.getFirstItem().getFileName())[1:] # remove dot in extension
    
    print "extension = ", extension
    print "ext = ", ext
    
    if ext == extension:
        mapFunc = createBinaryLink
    elif ext == 'mrc' and extension == 'mrcs':
        mapFunc = createBinaryLink
    elif ext.endswith('.hdf'): # assume eman .hdf format
        mapFunc = convertStack
    else:
        mapFunc = None
        
    if mapFunc is not None:
        for fn in imgSet.getFiles():
            filesDict[fn] = mapFunc(fn) # convert and map new filename

    return filesDict
Example #4
0
    def _warnings(self):
        warnings = []
        firstMic = self.inputMicrographs.get().getFirstItem()
        fnLower = firstMic.getFileName().lower()

        ext = getExt(fnLower)

        if ext in ['.tif', '.dm3'] and not self.invertY.get():
            warnings.append(
                'We have seen a flip in Y when using %s files in EMAN2' % ext)
            warnings.append(
                'The generated coordinates may or may not be valid in Scipion.'
            )
            warnings.append(
                'TIP: Activate "Invert Y coordinates" if you find it wrong.')
        return warnings
Example #5
0
    def _insertAllSteps(self):

        self._params = {}
        # diameter must be passed in Armstrongs and therefore should be converted
        self._params['diam'] = self.diameter.get() * self.getInputMicrographs().getSamplingRate()
        # self._params['num-slices'] = self.numberSizes.get()
        # self._params['size-range'] = self.sizeRange.get()
        self._params['apix'] = self.inputMicrographs.get().getSamplingRate()
        self._params['thresh'] = self.threshold.get()
        # self._params['max-thresh'] = self.maxThreshold.get()
        # self._params['max-area'] = self.maxArea.get()
        # self._params['max-peaks'] = self.maxPeaks.get()

        args = ""
        for par, val in self._params.iteritems():
            args += " --%s=%s" % (par, str(val))

        if self.invert:
            args += " --invert"

        args += " " + self.extraParams.get('')

        deps = [] # Store all steps ids, final step createOutput depends on all of them

        ih = ImageHandler()

        for mic in self.inputMicrographs.get():
            # Create micrograph folder
            micName = mic.getFileName()
            micDir = self._getTmpPath(removeBaseExt(micName))
            makePath(micDir)

            # If needed convert micrograph to mrc format, otherwise link it
            if getExt(micName) != ".mrc":
                fnMicBase = replaceBaseExt(micName, 'mrc')
                inputMic = join(micDir, fnMicBase)
                ih.convert(mic.getLocation(), inputMic)
            else:
                inputMic = join(micDir, basename(micName))
                createLink(micName, inputMic)

            # Insert step to execute program
            stepId = self._insertFunctionStep('executeDogpickerStep', inputMic, args)
            deps.append(stepId)


        self._insertFinalSteps(deps)
    def _insertAllSteps(self):

        self._params = {}
        # diameter must be passed in Angstrongs and therefore should be converted
        self._params['diam'] = self.diameter.get() * self.getInputMicrographs().getSamplingRate()
        # self._params['num-slices'] = self.numberSizes.get()
        # self._params['size-range'] = self.sizeRange.get()
        self._params['apix'] = self.inputMicrographs.get().getSamplingRate()
        self._params['thresh'] = self.threshold.get()
        # self._params['max-thresh'] = self.maxThreshold.get()
        # self._params['max-area'] = self.maxArea.get()
        # self._params['max-peaks'] = self.maxPeaks.get()

        args = ""
        for par, val in self._params.iteritems():
            args += " --%s=%s" % (par, str(val))

        if self.invert:
            args += " --invert"

        args += " " + self.extraParams.get('')

        deps = [] # Store all steps ids, final step createOutput depends on all of them

        ih = ImageHandler()

        for mic in self.inputMicrographs.get():
            # Create micrograph folder
            micName = mic.getFileName()
            micDir = self._getTmpPath(removeBaseExt(micName))
            makePath(micDir)

            # If needed convert micrograph to mrc format, otherwise link it
            if getExt(micName) != ".mrc":
                fnMicBase = replaceBaseExt(micName, 'mrc')
                inputMic = join(micDir, fnMicBase)
                ih.convert(mic.getLocation(), inputMic)
            else:
                inputMic = join(micDir, basename(micName))
                createLink(micName, inputMic)

            # Insert step to execute program
            stepId = self._insertFunctionStep('executeDogpickerStep', inputMic, args)
            deps.append(stepId)


        self._insertFinalSteps(deps)
Example #7
0
def convertBinaryFiles(imgSet, outputDir, extension='mrcs'):
    """ Convert binary images files to a format read by Relion.
    Params:
        imgSet: input image set to be converted.
        outputDir: where to put the converted file(s)
    Return:
        A dictionary with old-file as key and new-file as value
        If empty, not conversion was done.
    """
    filesDict = {}
    ih = em.ImageHandler()
    
    def getUniqueFileName(fn, extension):
        """ Get an unique file for either link or convert files.
        It is possible that the base name overlap if they come
        from different runs. (like partices.mrcs after relion preprocess)
        """
        newFn = join(outputDir, replaceBaseExt(fn, extension))
        newRoot = removeExt(newFn)
        
        values = filesDict.values()
        counter = 1
        
        while newFn in values:
            counter += 1
            newFn = '%s_%05d.%s' % (newRoot, counter, extension)
            
        return newFn

    def createBinaryLink(fn):
        """ Just create a link named .mrcs to Relion understand 
        that it is a binary stack file and not a volume.
        """
        newFn = getUniqueFileName(fn, extension)
        createLink(fn, newFn)
        return newFn
        
    def convertStack(fn):
        """ Convert from a format that is not read by Relion
        to an spider stack.
        """
        newFn = getUniqueFileName(fn, 'stk')
        ih.convertStack(fn, newFn)
        return newFn
        
    ext = getExt(imgSet.getFirstItem().getFileName())[1:] # remove dot in extension
    
    if ext == extension:
        mapFunc = createBinaryLink
        print "convertBinaryFiles: creating soft links."
    elif ext == 'mrc' and extension == 'mrcs':
        mapFunc = createBinaryLink
        print "convertBinaryFiles: creating soft links (mrcs -> mrc)."
    elif ext.endswith('hdf'): # assume eman .hdf format
        mapFunc = convertStack
        print "convertBinaryFiles: converting stacks. (%s -> %s)" % (extension, ext)
    else:
        mapFunc = None
        
    if mapFunc is not None:
        for fn in imgSet.getFiles():
            newFn = mapFunc(fn) # convert or link 
            filesDict[fn] = newFn # map new filename
            print "   %s -> %s" % (newFn, fn)

    return filesDict
Example #8
0
def convertBinaryFiles(imgSet, outputDir, extension='mrcs'):
    """ Convert binary images files to a format read by Relion.
    Params:
        imgSet: input image set to be converted.
        outputDir: where to put the converted file(s)
    Return:
        A dictionary with old-file as key and new-file as value
        If empty, not conversion was done.
    """
    filesDict = {}
    ih = em.ImageHandler()

    def getUniqueFileName(fn, extension):
        """ Get an unique file for either link or convert files.
        It is possible that the base name overlap if they come
        from different runs. (like partices.mrcs after relion preprocess)
        """
        newFn = join(outputDir, replaceBaseExt(fn, extension))
        newRoot = removeExt(newFn)

        values = filesDict.values()
        counter = 1

        while newFn in values:
            counter += 1
            newFn = '%s_%05d.%s' % (newRoot, counter, extension)

        return newFn

    def createBinaryLink(fn):
        """ Just create a link named .mrcs to Relion understand 
        that it is a binary stack file and not a volume.
        """
        newFn = getUniqueFileName(fn, extension)
        createLink(fn, newFn)
        return newFn

    def convertStack(fn):
        """ Convert from a format that is not read by Relion
        to an spider stack.
        """
        newFn = getUniqueFileName(fn, 'stk')
        ih.convertStack(fn, newFn)
        return newFn

    ext = getExt(
        imgSet.getFirstItem().getFileName())[1:]  # remove dot in extension

    if ext == extension:
        mapFunc = createBinaryLink
        print "convertBinaryFiles: creating soft links."
    elif ext == 'mrc' and extension == 'mrcs':
        mapFunc = createBinaryLink
        print "convertBinaryFiles: creating soft links (mrcs -> mrc)."
    elif ext.endswith('hdf'):  # assume eman .hdf format
        mapFunc = convertStack
        print "convertBinaryFiles: converting stacks. (%s -> %s)" % (extension,
                                                                     ext)
    else:
        mapFunc = None

    if mapFunc is not None:
        for fn in imgSet.getFiles():
            newFn = mapFunc(fn)  # convert or link
            filesDict[fn] = newFn  # map new filename
            print "   %s -> %s" % (newFn, fn)

    return filesDict