Ejemplo n.º 1
0
def getEnviron():
    """ Setup the environment variables needed to launch Bsoft. """
    environ = Environ(os.environ)
    BSOFT_HOME = os.environ['BSOFT_HOME']
    
    environ.update({
            'BSOFT': BSOFT_HOME,
            'BPARAM': join(BSOFT_HOME, 'params'),
            'PATH': join(BSOFT_HOME, 'bin'),
            'LD_LIBRARY_PATH': join(BSOFT_HOME, 'lib')
            }, position=Environ.BEGIN)
    return environ
Ejemplo n.º 2
0
def getEnviron():
    """ Setup the environment variables needed to launch Bsoft. """
    environ = Environ(os.environ)
    BSOFT_HOME = os.environ['BSOFT_HOME']
    
    environ.update({
            'BSOFT': BSOFT_HOME,
            'BPARAM': join(BSOFT_HOME, 'params'),
            'PATH': join(BSOFT_HOME, 'bin'),
            'LD_LIBRARY_PATH': join(BSOFT_HOME, 'lib')
            }, position=Environ.BEGIN)
    return environ
Ejemplo n.º 3
0
def readSetOfCoordinates(outputDir, micSet, coordSet):
    """ Read from Bsoft .star files.
    Params:
        outputDir: the directory where the .star files are.
           
        micSet: the SetOfMicrographs to associate the .star, which 
            name should be the same of the micrographs.
        coordSet: the SetOfCoordinates that will be populated.
    """
    addBsoftLabelAliases()
    boxSize = 0
    for mic in micSet:
        outputFile = join(outputDir, replaceBaseExt(mic.getFileName(), 'star'))
        #scipionPosFile = join(outputDir, "scipion_" + replaceBaseExt(mic.getFileName(), 'pos'))
        if exists(outputFile):
            posMd = xmipp.MetaData(outputFile)
            for objId in posMd:
                coord = rowToCoordinate(rowFromMd(posMd, objId))
                boxSize = 2 * posMd.getValue(xmipp.MDL_PICKING_PARTICLE_SIZE,
                                             objId)
                coord.setMicrograph(mic)
                coord.setX(coord.getX())
                coord.setY(coord.getY())

                coordSet.append(coord)
                # Add an unique ID that will be propagated to particles
                posMd.setValue(xmipp.MDL_ITEM_ID, long(coord.getObjId()),
                               objId)


#         if not posMd.isEmpty():
#             posMd.write("particles@%s"  % scipionPosFile)

#reading origin.x value and converting to particle size, can change, we take last value
    coordSet.setBoxSize(boxSize)
Ejemplo n.º 4
0
def readSetOfCoordinates(outputDir, micSet, coordSet):
    """ Read from Bsoft .star files.
    Params:
        outputDir: the directory where the .star files are.
           
        micSet: the SetOfMicrographs to associate the .star, which 
            name should be the same of the micrographs.
        coordSet: the SetOfCoordinates that will be populated.
    """
    addBsoftLabelAliases()
    boxSize = 0
    for mic in micSet:
        outputFile = join(outputDir, replaceBaseExt(mic.getFileName(), 'star'))
        #scipionPosFile = join(outputDir, "scipion_" + replaceBaseExt(mic.getFileName(), 'pos'))
        if exists(outputFile):
            posMd = xmipp.MetaData(outputFile)
            for objId in posMd:
                coord = rowToCoordinate(rowFromMd(posMd, objId))
                boxSize = 2 * posMd.getValue(xmipp.MDL_PICKING_PARTICLE_SIZE, objId)
                coord.setMicrograph(mic)
                coord.setX(coord.getX())
                coord.setY(coord.getY())
                
                coordSet.append(coord)      
                # Add an unique ID that will be propagated to particles
                posMd.setValue(xmipp.MDL_ITEM_ID, long(coord.getObjId()), objId)
#         if not posMd.isEmpty():
#             posMd.write("particles@%s"  % scipionPosFile)
            
    #reading origin.x value and converting to particle size, can change, we take last value
    coordSet.setBoxSize(boxSize)
Ejemplo n.º 5
0
 def check_gauss(self):
     # Function to check if gaussian algorithm was used to pick and is so
     # ask user if she wants to perform an automatic picking for the remaining micrographs
     gaussJsonFile = join("e2boxercache", "gauss_box_DB.json")
     # Check if gauss json file exists and load it
     if os.path.exists(gaussJsonFile):
         jsonGaussDict = loadJson(gaussJsonFile)
         gaussParsDict = None
         micList = [os.path.relpath(mic.getFileName(), self.workingDir.get()) for mic in self.inputMics]
         # Go over the list of input micrographs and see if gaussian was used to pick any of them
         for mic in micList:
             if mic in jsonGaussDict:
                 gaussParsDict = jsonGaussDict[mic]
                 break
         if gaussParsDict is not None:
             # If found ask user if she wats to perform an automatic gaussian picking for the rest of mics
             # if askYesNo(Message.TITLE_PICK_GAUSS, Message.LABEL_PICK_GAUSS, None):
             self._params['boxSize'] = gaussParsDict['boxsize']
             # Run sxprocess.py to store parameters
             program = eman2.getEmanProgram("sxprocess.py")
             argsList = ["'%s'=%s:" %(key, val) for (key, val) in gaussParsDict.iteritems()]
             args = 'demoparms --makedb ' + "".join(argsList)
             # Remove last ":" to avoid error
             args = args[:-1]
             # Run the command with formatted parameters
             self._log.info('Launching: ' + program + ' ' + args)
             self.runJob(program, args)
             # Now run e2boxer.py with stored parameters
             #arguments = "--gauss_autoboxer=demoparms --write_ptcl --boxsize=%(boxSize)s --norm=normalize.ramp.normvar" + arguments
             arguments = "--gauss_autoboxer=demoparms --write_dbbox --boxsize=%(boxSize)s " + "%(inputMics)s"
             program = eman2.getEmanProgram("e2boxer.py")
             self._log.info('Launching: ' + program + ' ' + arguments % self._params)
             self.runJob(program, arguments % self._params)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    def copyTree(self, localFolder, remoteFolder):
        """
        Same as shutil.copytree, but allowing
        that the dest folder also exists.
        dest is a remote folder.
        """
        if not self.exists(remoteFolder):
            self.makePath(remoteFolder)

        for path in os.listdir(localFolder):
            localPath = join(localFolder, path)
            remotePath = join(remoteFolder, path)
            # Create folders
            if isdir(localPath):
                self.copyTree(localPath, remotePath)
            elif isfile(localPath):
                self.putFile(localPath, remotePath)
Ejemplo n.º 9
0
    def copyTree(self, localFolder, remoteFolder):
        """
        Same as shutil.copytree, but allowing
        that the dest folder also exists.
        dest is a remote folder.
        """
        if not self.exists(remoteFolder):
            self.makePath(remoteFolder)

        for path in os.listdir(localFolder):
            localPath = join(localFolder, path)
            remotePath = join(remoteFolder, path)
            # Create folders
            if isdir(localPath):
                self.copyTree(localPath, remotePath)
            elif isfile(localPath):
                self.putFile(localPath, remotePath)
Ejemplo n.º 10
0
def getEnviron():
    """ Setup the environment variables needed to launch Appion. """
    environ = Environ(os.environ)
    if 'DOGPICKER_HOME' in environ:
        environ.update({
                'PATH': os.environ['DOGPICKER_HOME'],
                'LD_LIBRARY_PATH': join(os.environ['DOGPICKER_HOME'], 'appionlib') + ":" + os.environ['DOGPICKER_HOME'],
                }, position=Environ.BEGIN)
    else:
        #TODO: Find a generic way to warn of this situation
        print "DOGPICKER_HOME variable not set on environment."
    return environ
    def getMethods(self, output):#output is not used but to overwrite getMethods it is used
        msg = ""
        configfile = join(self._getExtraPath(), 'config.xmd')
        existsConfig = exists(configfile)
        if existsConfig:
            md = xmipp.MetaData('properties@' + configfile)
            configobj = md.firstObject()
            particleSize = md.getValue(xmipp.MDL_PICKING_PARTICLE_SIZE, configobj)
            manualParticlesSize = md.getValue(xmipp.MDL_PICKING_MANUALPARTICLES_SIZE, configobj)
            msg = 'User picked %d particles with a particle size of %d.' % (manualParticlesSize, particleSize)

        return msg
Ejemplo n.º 12
0
    def getDefaultBoxSize(self):
        import xmipp
        boxSize = 100
        importFrom = self.getImportFrom()
        scale = self.scale.get()

        if importFrom == ProtImportCoordinates.IMPORT_FROM_XMIPP:
            configfile = join(self.filesPath.get(), 'config.xmd')
            existsConfig = exists(configfile)
            if existsConfig:
                md = xmipp.MetaData('properties@' + configfile)
                configobj = md.firstObject()
                boxSize = md.getValue(xmipp.MDL_PICKING_PARTICLE_SIZE, configobj)
        if importFrom == ProtImportCoordinates.IMPORT_FROM_EMAN:
            # Read the boxSize from the e2boxercache/base.json
            jsonFnbase = join(self.filesPath.get(), 'e2boxercache', 'base.json')
            from pyworkflow.em.packages.eman2 import loadJson
            jsonBoxDict = loadJson(jsonFnbase)
            boxSize = int(jsonBoxDict["box_size"])
        boxSize = (int)(boxSize * scale)
        return boxSize
Ejemplo n.º 13
0
def readSetOfCoordinates(workDir, micSet, coordSet):
    """ Read from Appion .txt files.
    It is expected a file named: base.txt under the workDir.
    Params:
        workDir: where the Appion dogpicker output files are located.
        micSet: the SetOfMicrographs to associate the .txt, which
            name should be the same of the micrographs.
        coordSet: the SetOfCoordinates that will be populated.
    """

    for mic in micSet:
        micCoordFn = join(workDir, replaceBaseExt(mic.getFileName(), 'txt'))
        readCoordinates(mic, micCoordFn, coordSet)
Ejemplo n.º 14
0
def readSetOfCoordinates(workDir, micSet, coordSet):
    """ Read from Appion .txt files.
    It is expected a file named: base.txt under the workDir.
    Params:
        workDir: where the Appion dogpicker output files are located.
        micSet: the SetOfMicrographs to associate the .txt, which
            name should be the same of the micrographs.
        coordSet: the SetOfCoordinates that will be populated.
    """

    for mic in micSet:
        micCoordFn = join(workDir, replaceBaseExt(mic.getFileName(), 'txt'))
        readCoordinates(mic, micCoordFn, coordSet)
 def getSummary(self, coordsSet):
     summary = []
     configfile = join(self._getExtraPath(), 'config.xmd')
     if exists(configfile):
         md = xmipp.MetaData('properties@' + configfile)
         configobj = md.firstObject()
         activemic = md.getValue(xmipp.MDL_MICROGRAPH, configobj)
         manualParticlesSize = md.getValue(xmipp.MDL_PICKING_MANUALPARTICLES_SIZE, configobj)
         particleSize = md.getValue(xmipp.MDL_PICKING_PARTICLE_SIZE, configobj)
         summary.append("Particles picked: %d"%manualParticlesSize)
         summary.append("Particle size: %d"%particleSize)
         summary.append("Last micrograph: " + activemic)
     return "\n".join(summary)
Ejemplo n.º 16
0
 def cleanPath(self, *remotePaths):
     """
     Same as pyworkflow.utils.path.cleanPath but for remote folders or files.
     """
     for path in remotePaths:
         if self.exists(path):
             # Create folders
             if self.isdir(path):
                 files = [join(path, f) for f in self.sftp.listdir(path)]
                 self.cleanPath(*files)
                 log.info('RemotePath.cleanPath, rmdir path: %s' % path)
                 self.sftp.rmdir(path)
             else:# isfile(path):
                 log.info('RemotePath.cleanPath, remove path: %s' % path)
                 self.sftp.remove(path)
Ejemplo n.º 17
0
 def cleanPath(self, *remotePaths):
     """
     Same as pyworkflow.utils.path.cleanPath but for remote folders or files.
     """
     for path in remotePaths:
         if self.exists(path):
             # Create folders
             if self.isdir(path):
                 files = [join(path, f) for f in self.sftp.listdir(path)]
                 self.cleanPath(*files)
                 log.info('RemotePath.cleanPath, rmdir path: %s' % path)
                 self.sftp.rmdir(path)
             else:  # isfile(path):
                 log.info('RemotePath.cleanPath, remove path: %s' % path)
                 self.sftp.remove(path)
Ejemplo n.º 18
0
 def check_gauss(self):
     if self._useNewBoxer():
         # gauss picker is not implemented for Eman v.2.21 yet
         pass
     else:
         # Function to check if gaussian algorithm was used to pick
         # and if so ask user if she wants to perform an automatic
         # picking for the remaining micrographs
         gaussJsonFile = join("e2boxercache", "gauss_box_DB.json")
         # Check if gauss json file exists and load it
         if os.path.exists(gaussJsonFile):
             jsonGaussDict = loadJson(gaussJsonFile)
             gaussParsDict = None
             micList = [
                 os.path.relpath(mic.getFileName(), self.workingDir.get())
                 for mic in self.inputMics
             ]
             # Go over the list of input micrographs and see if
             # gaussian was used to pick any of them
             for mic in micList:
                 if mic in jsonGaussDict:
                     gaussParsDict = jsonGaussDict[mic]
                     break
             if gaussParsDict is not None:
                 # If found ask user if she wats to perform an automatic gaussian
                 # picking for the rest of mics
                 self._params['boxSize'] = gaussParsDict['boxsize']
                 # Run sxprocess.py to store parameters
                 program = eman2.Plugin.getProgram("sxprocess.py")
                 argsList = [
                     "'%s'=%s:" % (key, val)
                     for (key, val) in gaussParsDict.iteritems()
                 ]
                 args = 'demoparms --makedb ' + "".join(argsList)
                 # Remove last ":" to avoid error
                 args = args[:-1]
                 # Run the command with formatted parameters
                 self._log.info('Launching: ' + program + ' ' + args)
                 self.runJob(program, args)
                 # Now run e2boxer.py with stored parameters
                 arguments = "--gauss_autoboxer=demoparms --write_dbbox "
                 arguments += " --boxsize=%(boxSize)s " + "%(inputMics)s"
                 boxer = eman2.Plugin.getBoxerCommand(boxerVersion='old')
                 program = eman2.Plugin.getProgram(boxer)
                 self._log.info('Launching: ' + program + ' ' +
                                arguments % self._params)
                 self.runJob(program, arguments % self._params)
Ejemplo n.º 19
0
def getEnviron():
    """ Setup the environment variables needed to launch Appion. """
    environ = Environ(os.environ)
    if 'DOGPICKER_HOME' in environ:
        environ.update(
            {
                'PATH':
                os.environ['DOGPICKER_HOME'],
                'LD_LIBRARY_PATH':
                join(os.environ['DOGPICKER_HOME'], 'appionlib') + ":" +
                os.environ['DOGPICKER_HOME'],
            },
            position=Environ.BEGIN)
    else:
        #TODO: Find a generic way to warn of this situation
        print "DOGPICKER_HOME variable not set on environment."
    return environ