Example #1
0
    def show(self, form):
        prot = form.protocol
        micSet = prot.getInputMicrographs()

        if not micSet:
            print 'must specify input micrographs'
            return

        project = prot.getProject()
        micfn = micSet.getFileName()

        # Prepare a temporary folder to convert some input files
        # and put some of the intermediate result files
        coordsDir = project.getTmpPath(micSet.getName())
        pwutils.cleanPath(coordsDir)
        pwutils.makePath(coordsDir)
        prot.convertInputs(coordsDir)

        pickerConfig = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerConfig, "w")

        pickScript = pw.join('em', 'packages', 'igbmc', 'run_gempicker.py')

        pickCmd = prot._getPickArgs(threshold=False, workingDir=coordsDir)[0]
        convertCmd = pw.join('apps', 'pw_convert.py')

        args = {
                "pickScript": pickScript,
                "pickCmd": pickCmd,
                "convertCmd": convertCmd,
                'coordsDir': coordsDir,
                'micsSqlite': micSet.getFileName(),
                'thresholdLow': prot.thresholdLow,
                'thresholdHigh': prot.thresholdHigh,
                "useGPU": prot.useGPU
          }

        f.write("""
        parameters = thresholdLow,thresholdHigh
        thresholdLow.value =  %(thresholdLow)s
        thresholdLow.label = Threshold Low
        thresholdLow.help = Low value cut-off
        thresholdHigh.value =  %(thresholdHigh)s
        thresholdHigh.label = Threshold High
        thresholdHigh.help = High value cut-off
        autopickCommand = %(pickScript)s %%(micrograph) %(coordsDir)s %(useGPU)s %(pickCmd)s --thresh=%%(thresholdLow) --threshHigh=%%(thresholdHigh)
        convertCommand = %(convertCmd)s --coordinates --from gempicker --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)

        f.close()

        process = CoordinatesObjectView(project, micfn, coordsDir, prot,
                                        mode=CoordinatesObjectView.MODE_AUTOMATIC,
                                        pickerProps=pickerConfig).show()
        process.wait()
        myprops = pwutils.readProperties(pickerConfig)

        if myprops['applyChanges'] == 'true':
            form.setVar('thresholdLow', myprops['thresholdLow.value'])
            form.setVar('thresholdHigh', myprops['thresholdHigh.value'])
Example #2
0
    def show(self, form):
        autopickProt = form.protocol
        micSet = autopickProt.getInputMicrographs()
        if not micSet:
            print 'must specify input micrographs'
            return
        project = autopickProt.getProject()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)
        # Get current values of the properties
        #         micfn = os.path.join(coordsDir, 'micrographs.xmd')
        #         writeSetOfMicrographs(micSet, micfn)
        dogpickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(dogpickerProps, "w")

        args = {
            "dogpicker":
            os.path.join(os.environ['DOGPICKER_HOME'], "ApDogPicker.py"),
            "convert":
            pw.join('apps', 'pw_convert.py'),
            'coordsDir':
            coordsDir,
            'micsSqlite':
            micSet.getFileName(),
            "diameter":
            autopickProt.diameter,
            "threshold":
            autopickProt.threshold,
            "apix":
            micSet.getSamplingRate()
        }

        f.write("""
        parameters = diameter,threshold
        diameter.value = %(diameter)s
        diameter.label = Diameter
        diameter.help = some help
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        autopickCommand = %(dogpicker)s  --thresh=%%(threshold) --diam=%%(diameter) --apix=%(apix)s  --image=%%(micrograph) --outfile=%(coordsDir)s/%%(micrographName).txt 
        convertCommand = %(convert)s --coordinates --from dogpicker --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)
        f.close()
        process = CoordinatesObjectView(project,
                                        micfn,
                                        coordsDir,
                                        autopickProt,
                                        pickerProps=dogpickerProps).show()
        process.wait()
        # Check if the wizard changes were accepted or just canceled

        myprops = readProperties(dogpickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('diameter', myprops['diameter.value'])
            form.setVar('threshold', myprops['threshold.value'])
Example #3
0
    def show(self, form):
        autopickProt = form.protocol
        autopickFomProt = autopickProt.getInputAutopick()
        project = autopickProt.getProject()
        micSet = autopickFomProt.getInputMicrographs()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)
        pickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerProps, "w")
        args = {
            "picker": "%s relion_autopick" % pw.getScipionScript(),
            "convert": pw.join('apps', 'pw_convert.py'),
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            "diameter": autopickFomProt.particleDiameter,
            "threshold": autopickProt.pickingThreshold,
            "apix": micSet.getSamplingRate(),
            'ang': autopickFomProt.angularSampling,
            'lowpass': autopickFomProt.lowpassFilterRefs,
            'ref': 'input_references.star',
            'min_distance': autopickProt.interParticleDistance,
            'protDir': autopickFomProt.getWorkingDir()
        }

        autopickCmd = '%(picker)s --i extra/%%(micrographName).star --o autopick --particle_diameter %(diameter)s '
        autopickCmd += '--angpix %(apix)s --ref %(ref)s --ang %(ang)s --lowpass %(lowpass)s --threshold %%(threshold) '
        autopickCmd += '--min_distance %%(ipd) --read_fom_maps' % args
        if autopickFomProt.refsHaveInvertedContrast:
            autopickCmd += ' --invert'

        if autopickFomProt.refsCtfCorrected:
            autopickCmd += ' --ctf'
        args['autopickCmd'] = autopickCmd
        f.write("""
        parameters = ipd,threshold
        ipd.value = %(min_distance)s
        ipd.label = Minimum inter-particles distance
        ipd.help = some help
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        runDir = %(protDir)s
        autopickCmd = %(autopickCmd)s
        convertCommand = %(convert)s --coordinates --from relion --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s --extra %(protDir)s/extra
        """ % args)
        f.close()
        process = CoordinatesObjectView(autopickProt.getProject(),
                                        micfn,
                                        coordsDir,
                                        autopickFomProt,
                                        pickerProps=pickerProps).show()
        process.wait()
        myprops = pwutils.readProperties(pickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('pickingThreshold', myprops['threshold.value'])
            form.setVar('interParticleDistance', myprops['ipd.value'])
Example #4
0
    def show(self, form):
        prot = form.protocol
        micSet = prot.getInputMicrographs()

        if not micSet:
            print 'must specify input micrographs'
            return

        project = prot.getProject()
        micfn = micSet.getFileName()

        # Prepare a temporary folder to convert some input files
        # and put some of the intermediate result files
        coordsDir = project.getTmpPath(micSet.getName())
        pwutils.cleanPath(coordsDir)
        pwutils.makePath(coordsDir)
        prot.convertInputs(coordsDir)

        pickerConfig = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerConfig, "w")

        pickScript = pw.join('em', 'packages', 'igbmc', 'run_gempicker.py')

        pickCmd = prot.getArgs(threshold=False, workingDir=coordsDir)
        convertCmd = pw.join('apps', 'pw_convert.py')

        args = {
                "pickScript": pickScript,
                "pickCmd": pickCmd,
                "convertCmd": convertCmd,
                'coordsDir': coordsDir,
                'micsSqlite': micSet.getFileName(),
                'thresholdLow': prot.thresholdLow,
                'thresholdHigh': prot.thresholdHigh,
                "useGPU": prot.useGPU
          }

        f.write("""
        parameters = thresholdLow,thresholdHigh
        thresholdLow.value =  %(thresholdLow)s
        thresholdLow.label = Threshold Low
        thresholdLow.help = Low value cut-off
        thresholdHigh.value =  %(thresholdHigh)s
        thresholdHigh.label = Threshold High
        thresholdHigh.help = High value cut-off
        autopickCommand = %(pickScript)s %%(micrograph) %(coordsDir)s %(useGPU)s %(pickCmd)s --thresh=%%(thresholdLow) --threshHigh=%%(thresholdHigh)
        convertCommand = %(convertCmd)s --coordinates --from gempicker --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)

        f.close()

        process = CoordinatesObjectView(project, micfn, coordsDir, prot,
                                        pickerProps=pickerConfig).show()
        process.wait()
        myprops = pwutils.readProperties(pickerConfig)

        if myprops['applyChanges'] == 'true':
            form.setVar('thresholdLow', myprops['thresholdLow.value'])
            form.setVar('thresholdHigh', myprops['thresholdHigh.value'])
Example #5
0
    def show(self, form):
        autopickProt = form.protocol
        autopickFomProt = autopickProt.getInputAutopick()
        project = autopickProt.getProject()
        micSet = autopickFomProt.getInputMicrographs()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)
        pickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerProps, "w")
        args = {
          "picker" : "%s relion_autopick" % pw.getScipionScript(),
          "convert" : pw.join('apps', 'pw_convert.py'),
          'coordsDir':coordsDir,
          'micsSqlite': micSet.getFileName(),
          "diameter": autopickFomProt.particleDiameter,
          "threshold": autopickProt.pickingThreshold,
          "apix": micSet.getSamplingRate(),
          'ang': autopickFomProt.angularSampling,
          'lowpass':autopickFomProt.lowpassFilterRefs,
          'ref': 'input_references.star',
          'min_distance': autopickProt.interParticleDistance,
          'protDir': autopickFomProt.getWorkingDir()
          }

        autopickCmd = '%(picker)s --i extra/%%(micrographName).star --o autopick --particle_diameter %(diameter)s '
        autopickCmd += '--angpix %(apix)s --ref %(ref)s --ang %(ang)s --lowpass %(lowpass)s --threshold %%(threshold) '
        autopickCmd += '--min_distance %%(ipd) --read_fom_maps' % args
        if autopickFomProt.refsHaveInvertedContrast:
            autopickCmd += ' --invert'
        
        if autopickFomProt.refsCtfCorrected:
            autopickCmd += ' --ctf'
        args['autopickCmd'] = autopickCmd
        f.write("""
        parameters = ipd,threshold
        ipd.value = %(min_distance)s
        ipd.label = Minimum inter-particles distance
        ipd.help = some help
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        runDir = %(protDir)s
        autopickCmd = %(autopickCmd)s
        convertCommand = %(convert)s --coordinates --from relion --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s --extra %(protDir)s/extra
        """ % args)
        f.close()
        process = CoordinatesObjectView(autopickProt.getProject(), micfn, coordsDir, autopickFomProt, pickerProps=pickerProps).show()
        process.wait()
        myprops = pwutils.readProperties(pickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('pickingThreshold', myprops['threshold.value'])
            form.setVar('interParticleDistance', myprops['ipd.value'])
Example #6
0
    def show(self, form):
        autopickProt = form.protocol
        micSet = autopickProt.getInputMicrographs()
        if not micSet:
            print('must specify input micrographs')
            return
        project = autopickProt.getProject()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)
        # Get current values of the properties
        #         micfn = os.path.join(coordsDir, 'micrographs.xmd')
        #         writeSetOfMicrographs(micSet, micfn)
        dogpickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(dogpickerProps, "w")

        args = {
            "dogpicker": os.path.join(Plugin.getHome(), "ApDogPicker.py"),
            "convert": 'emconvert',
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            "diameter": autopickProt.diameter,
            "threshold": autopickProt.threshold,
            "apix": micSet.getSamplingRate()
        }

        f.write("""
        parameters = diameterA,threshold
        diameterA.value = %(diameter)s
        diameterA.label = Diameter in A 
        diameterA.help = Sampling rate is %(apix)s
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = Threshold in standard deviations above the mean
        autopickCommand = python2 %(dogpicker)s  --thresh=%%(threshold) --diam=%%(diameterA) --apix=%(apix)s  --image=%%(micrograph) --outfile=%(coordsDir)s/%%(micrographName).txt 
        convertCommand = %(convert)s --coordinates --from dogpicker --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)
        f.close()
        process = CoordinatesObjectView(
            project,
            micfn,
            coordsDir,
            autopickProt,
            mode=CoordinatesObjectView.MODE_AUTOMATIC,
            pickerProps=dogpickerProps).show()
        process.wait()
        # Check if the wizard changes were accepted or just canceled

        myprops = readProperties(dogpickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('diameter', myprops['diameterA.value'])
            form.setVar('threshold', myprops['threshold.value'])
Example #7
0
    def show(self, form):
        autopickProt = form.protocol
        micSet = autopickProt.getInputMicrographs()
        if not micSet:
            print 'must specify input micrographs'
            return
        project = autopickProt.getProject()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)
        # Get current values of the properties
#         micfn = os.path.join(coordsDir, 'micrographs.xmd')
#         writeSetOfMicrographs(micSet, micfn)
        dogpickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(dogpickerProps, "w")

        args = {
          "dogpicker" : os.path.join(os.environ['DOGPICKER_HOME'], "ApDogPicker.py"),
          "convert" : pw.join('apps', 'pw_convert.py'),
          'coordsDir': coordsDir,
          'micsSqlite': micSet.getFileName(),
          "diameter": autopickProt.diameter,
          "threshold": autopickProt.threshold,
          "apix": micSet.getSamplingRate()
          }


        f.write("""
        parameters = diameter,threshold
        diameter.value = %(diameter)s
        diameter.label = Diameter
        diameter.help = some help
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        autopickCommand = %(dogpicker)s  --thresh=%%(threshold) --diam=%%(diameter) --apix=%(apix)s  --image=%%(micrograph) --outfile=%(coordsDir)s/%%(micrographName).txt 
        convertCommand = %(convert)s --coordinates --from dogpicker --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)
        f.close()
        process = CoordinatesObjectView(project, micfn, coordsDir, autopickProt,
                                        mode=CoordinatesObjectView.MODE_AUTOMATIC,
                                        pickerProps=dogpickerProps).show()
        process.wait()
        # Check if the wizard changes were accepted or just canceled

        myprops = readProperties(dogpickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('diameter', myprops['diameter.value'])
            form.setVar('threshold', myprops['threshold.value'])
Example #8
0
    def show(self, form):
        prot = form.protocol
        micSet = prot.getInputMicrographs()

        gpus = prot.getGpuList()

        if not gpus:
            form.showWarning("You should select at least one GPU.")
            return

        if not micSet:
            form.showWarning("You should select input micrographs "
                             "before opening the wizard.")
            return

        project = prot.getProject()

        if prot.micrographsSelection == 0:  # all micrographs
            micFn = micSet.getFileName()
        else:
            # Create a subset based on defocus values
            ctfs = prot.ctfRelations.get()
            if ctfs is None:
                form.showWarning("You should select CTFs if using a defocus "
                                 "subset. ")
                return
            micSubset = prot._createSetOfMicrographs(suffix='subset')
            for mic in getSubsetByDefocus(ctfs, micSet,
                                          prot.micrographsNumber.get()):
                micSubset.append(mic)
            micSubset.write()
            micSubset.close()
            micFn = micSubset.getFileName()

        # Prepare a temporary folder to convert some input files
        # and put some of the intermediate result files
        coordsDir = project.getTmpPath(micSet.getName())
        pwutils.cleanPath(coordsDir)
        pwutils.makePath(coordsDir)
        refStack = os.path.join(coordsDir, 'references.mrcs')
        prot.convertReferences(refStack)

        # Get current values of the properties
        #         micFn = os.path.join(coordsDir, 'micrographs.xmd')
        #         writeSetOfMicrographs(micSet, micFn)
        pickerConfig = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerConfig, "w")

        pickScript = pw.join('em', 'packages', 'gautomatch',
                             'run_gautomatch.py')

        # Let use the first selected gpu for the wizard
        pickCmd = prot.getArgs(threshold=False, mindist=False) % {
            'GPU': gpus[0]
        }
        convertCmd = pw.join('apps', 'pw_convert.py')

        args = {
            "pickScript": pickScript,
            "pickCmd": pickCmd,
            "convertCmd": convertCmd,
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            'threshold': prot.threshold.get(),
            "mindist": prot.minDist.get(),
            "refStack": refStack
        }

        # If Gautomatch will guess advanced parameter we don't need to send
        # the min distance to the wizard.
        if prot.advanced:
            f.write("""
            parameters = threshold
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        else:
            f.write("""
            parameters = threshold,mindist
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            mindist.value = %(mindist)s
            mindist.label = Min search distance
            mindist.help = Use value of 0.9~1.1X diameter
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold) --min_dist %%(mindist)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        f.close()

        process = CoordinatesObjectView(
            project,
            micFn,
            coordsDir,
            prot,
            mode=CoordinatesObjectView.MODE_AUTOMATIC,
            pickerProps=pickerConfig).show()
        process.wait()
        myprops = pwutils.readProperties(pickerConfig)

        if myprops['applyChanges'] == 'true':
            form.setVar('threshold', myprops['threshold.value'])
            if not prot.advanced:
                form.setVar('minDist', myprops['mindist.value'])
            else:
                pass  # TODO: We could even in future parse the 'guessed' params
Example #9
0
    def show(self, form):
        prot = form.protocol
        micSet = prot.getInputMicrographs()

        if not micSet:
            print 'must specify input micrographs'
            return

        project = prot.getProject()
        micfn = micSet.getFileName()

        # Prepare a temporary folder to convert some input files
        # and put some of the intermediate result files
        coordsDir = project.getTmpPath(micSet.getName())
        pwutils.cleanPath(coordsDir)
        pwutils.makePath(coordsDir)
        refStack = os.path.join(coordsDir, 'references.mrcs')
        prot.convertReferences(refStack)

        # Get current values of the properties
        #         micfn = os.path.join(coordsDir, 'micrographs.xmd')
        #         writeSetOfMicrographs(micSet, micfn)
        pickerConfig = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerConfig, "w")

        pickScript = pw.join('em', 'packages', 'gautomatch',
                             'run_gautomatch.py')

        pickCmd = prot.getArgs(threshold=False, mindist=False)
        convertCmd = pw.join('apps', 'pw_convert.py')

        args = {
            "pickScript": pickScript,
            "pickCmd": pickCmd,
            "convertCmd": convertCmd,
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            'threshold': prot.threshold.get(),
            "mindist": prot.minDist.get(),
            "refStack": refStack
        }

        # If Gautomatch will guess advanced parameter we don't need to send
        # the min distance to the wizard.
        if prot.advanced:
            f.write("""
            parameters = threshold
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        else:
            f.write("""
            parameters = threshold,mindist
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            mindist.value = %(mindist)s
            mindist.label = Min search distance
            mindist.help = Use value of 0.9~1.1X diameter
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold) --min_dist %%(mindist)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        f.close()

        process = CoordinatesObjectView(project,
                                        micfn,
                                        coordsDir,
                                        prot,
                                        pickerProps=pickerConfig).show()
        process.wait()
        myprops = pwutils.readProperties(pickerConfig)

        if myprops['applyChanges'] == 'true':
            form.setVar('threshold', myprops['threshold.value'])
            if not prot.advanced:
                form.setVar('minDist', myprops['mindist.value'])
            else:
                pass  # TODO: We could even in future parse the 'guessed' params
Example #10
0
    def show(self, form):
        autopickProt = form.protocol

        if not autopickProt.hasAttribute('outputCoordinatesSubset'):
            form.showWarning("You should run the procotol in 'Optimize' mode "
                             "at least once before opening the wizard.")
            return

        project = autopickProt.getProject()
        micSet = autopickProt.outputMicrographsSubset
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)

        from pyworkflow.em.packages.xmipp3.convert import writeSetOfMicrographs
        micStarFn = os.path.join(coordsDir, 'micrographs.xmd')

        # Set CTF information to the micrographs to be displayed in the
        # picking list
        autopickProt.micDict = OrderedDict()
        micDict, _ = autopickProt._loadInputList()

        def _preprocessMic(mic, micRow):
            mic.setCTF(micDict[mic.getMicName()].getCTF())

        writeSetOfMicrographs(micSet,
                              micStarFn,
                              preprocessImageRow=_preprocessMic)

        # Create a folder in extra to backup the original autopick star files
        backupDir = autopickProt._getExtraPath('wizard-backup')
        cleanPath(backupDir)
        makePath(backupDir)
        pwutils.copyPattern(autopickProt._getExtraPath("*autopick.star"),
                            backupDir)

        cmd = '%s relion_autopick ' % pw.getScipionScript()
        #cmd += '--i extra/%(micrographName).star '
        cmd += '--i input_micrographs.star '
        cmd += '--threshold %(threshold) --min_distance %(ipd) '
        cmd += ' --max_stddev_noise %(maxStddevNoise) '
        cmd += ' --read_fom_maps'
        cmd += autopickProt.getAutopickParams()

        convertCmd = pw.join('apps', 'pw_convert.py')
        convertCmd += ' --coordinates --from relion --to xmipp '
        convertCmd += ' --input %s' % micSet.getFileName()
        convertCmd += ' --output %s' % coordsDir
        convertCmd += ' --extra %s' % autopickProt._getExtraPath()

        args = {
            "threshold": autopickProt.pickingThreshold,
            'min_distance': autopickProt.interParticleDistance,
            'autopickCommand': cmd,
            'preprocessCommand': 'rm -rf %s/*.pos' % coordsDir,
            'convertCmd': convertCmd,
            'protDir': autopickProt.getWorkingDir(),
            'maxStddevNoise': autopickProt.maxStddevNoise
        }

        pickerProps = os.path.join(coordsDir, 'picker.conf')

        f = open(pickerProps, "w")
        f.write("""
        parameters = ipd,threshold,maxStddevNoise
        ipd.value = %(min_distance)s
        ipd.label = Inter-particles distance (A)
        ipd.help = Minimum distance (in Angstroms) between particles
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        maxStddevNoise.value = %(maxStddevNoise)s
        maxStddevNoise.label = Max. stddev noise
        maxStddevNoise.help = Prevent picking in carbon areas, useful values probably between 1.0 and 1.2, use -1 to switch it off
        runDir = %(protDir)s
        preprocessCommand = %(preprocessCommand)s
        autopickCommand = %(autopickCommand)s
        convertCommand = %(convertCmd)s
        hasInitialCoordinates = true
        doPickAll = true
        """ % args)
        f.close()
        process = CoordinatesObjectView(
            autopickProt.getProject(),
            micStarFn,
            coordsDir,
            autopickProt,
            mode=CoordinatesObjectView.MODE_AUTOMATIC,
            pickerProps=pickerProps).show()
        process.wait()
        myprops = pwutils.readProperties(pickerProps)

        # Check if the wizard changes were accepted or just canceled
        if myprops.get('applyChanges', 'false') == 'true':
            form.setVar('pickingThreshold', myprops['threshold.value'])
            form.setVar('interParticleDistance', myprops['ipd.value'])
            form.setVar('maxStddevNoise', myprops['maxStddevNoise.value'])
            # Change the run type now to 'Compute' after using the wizard
            # and (supposedly) optimized parameters
            form.setVar('runType', RUN_COMPUTE)
            # Mark the wizard was used
            setattr(autopickProt, 'wizardExecuted', True)
        else:
            # If the wizard was not execute, we should restore the original
            # autopick star files in case their were modified by the wizard
            pwutils.copyPattern(os.path.join(backupDir, "*autopick.star"),
                                autopickProt._getExtraPath())
Example #11
0
    def show(self, form):
        autopickProt = form.protocol
        project = autopickProt.getProject()
        micSet = autopickProt.getInputMicrographs()
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        print("coordsDir: ", coordsDir)
        params, minDiameter, maxDiameter, threshold = autopickProt._getPickArgs(
        )

        cleanPath(coordsDir)
        makePath(coordsDir, 'extra')
        pickerProps = os.path.join(coordsDir, 'picker.conf')
        from pyworkflow.em.packages.relion.convert import writeSetOfMicrographs
        micStarFn = os.path.join(coordsDir, 'input_micrographs.star')

        def _postprocessMic(mic, micRow):
            micFn = mic.getFileName()
            micBase = os.path.basename(micFn)
            createLink(micFn, os.path.join(coordsDir, micBase))
            micRow.setValue(md.RLN_MICROGRAPH_NAME, micBase)

        writeSetOfMicrographs(micSet,
                              micStarFn,
                              postprocessImageRow=_postprocessMic)

        f = open(pickerProps, "w")

        #params = params.replace('--odir ""', '--odir extra')
        autopickCmd = "%s relion_autopick " % pw.getScipionScript()
        autopickCmd += ' --i input_micrographs.star '
        autopickCmd += params
        autopickCmd += ' --LoG_diam_min %(mind) '
        autopickCmd += ' --LoG_diam_max %(maxd) '
        autopickCmd += ' --LoG_adjust_threshold %(threshold) '

        args = {
            "convert": pw.join('apps', 'pw_convert.py'),
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            "minDiameter": minDiameter,
            "maxDiameter": maxDiameter,
            "threshold": threshold,
            'projDir': project.getPath(),  #autopickProt.getWorkingDir(),
            "autopickCmd": autopickCmd
        }

        f.write("""
        parameters = mind,maxd,threshold
        mind.value = %(minDiameter)s
        mind.label = Min. Diameter for LoG filter (A)
        mind.help = The smallest allowed diameter for the blob-detection algorithm. This should correspond to the smallest size of your particles in Angstroms.
        maxd.value = %(maxDiameter)s
        maxd.label = Max. Diameter for LoG filter (A)
        maxd.help = The largest allowed diameter for the blob-detection algorithm. This should correspond to the largest size of your particles in Angstroms.
        threshold.value =  %(threshold)s
        threshold.label = Adjust default threshold
        threshold.help = Lower threshold -> more particles
        runDir = %(coordsDir)s
        autopickCommand = %(autopickCmd)s
        convertCommand = %(convert)s --coordinates --from relion --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s --extra %(coordsDir)s/
        hasInitialCoordinates = false
        doPickAll = true
        """ % args)
        f.close()
        process = CoordinatesObjectView(autopickProt.getProject(),
                                        micfn,
                                        coordsDir,
                                        autopickProt,
                                        pickerProps=pickerProps).show()
        process.wait()
        myprops = pwutils.readProperties(pickerProps)

        if myprops['applyChanges'] == 'true':
            form.setVar('minDiameter', myprops['mind.value'])
            form.setVar('maxDiameter', myprops['maxd.value'])
            form.setVar('threshold', myprops['threshold.value'])
Example #12
0
    def show(self, form):
        prot = form.protocol
        micSet = prot.getInputMicrographs()

        gpus = prot.getGpuList()

        if not gpus:
            form.showWarning("You should select at least one GPU.")
            return

        if not micSet:
            form.showWarning("You should select input micrographs "
                             "before opening the wizard.")
            return

        project = prot.getProject()

        if prot.micrographsSelection == 0:  # all micrographs
            micFn = micSet.getFileName()
        else:
            # Create a subset based on defocus values
            ctfs = prot.ctfRelations.get()
            if ctfs is None:
                form.showWarning("You should select CTFs if using a defocus "
                                 "subset. ")
                return
            micSubset = prot._createSetOfMicrographs(suffix='subset')
            for mic in getSubsetByDefocus(ctfs, micSet,
                                          prot.micrographsNumber.get()):
                micSubset.append(mic)
            micSubset.write()
            micSubset.close()
            micFn = micSubset.getFileName()

        # Prepare a temporary folder to convert some input files
        # and put some of the intermediate result files
        coordsDir = project.getTmpPath(micSet.getName())
        pwutils.cleanPath(coordsDir)
        pwutils.makePath(coordsDir)
        refStack = os.path.join(coordsDir, 'references.mrcs')
        prot.convertReferences(refStack)

        # Get current values of the properties
#         micFn = os.path.join(coordsDir, 'micrographs.xmd')
#         writeSetOfMicrographs(micSet, micFn)
        pickerConfig = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerConfig, "w")

        pickScript = pw.join('em', 'packages', 'gautomatch',
                             'run_gautomatch.py')

        # Let use the first selected gpu for the wizard
        pickCmd = prot.getArgs(threshold=False,
                               mindist=False) % {'GPU': gpus[0]}
        convertCmd = pw.join('apps', 'pw_convert.py')

        args = {
            "pickScript": pickScript,
            "pickCmd": pickCmd,
            "convertCmd": convertCmd,
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            'threshold': prot.threshold.get(),
            "mindist": prot.minDist.get(),
            "refStack": refStack
          }

        # If Gautomatch will guess advanced parameter we don't need to send
        # the min distance to the wizard.
        if prot.advanced:
            f.write("""
            parameters = threshold
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        else:
            f.write("""
            parameters = threshold,mindist
            threshold.value =  %(threshold)s
            threshold.label = Threshold
            threshold.help = Particles with CCC above the threshold will be picked
            mindist.value = %(mindist)s
            mindist.label = Min search distance
            mindist.help = Use value of 0.9~1.1X diameter
            autopickCommand = %(pickScript)s %%(micrograph) %(refStack)s %(coordsDir)s %(pickCmd)s --cc_cutoff %%(threshold) --min_dist %%(mindist)
            convertCommand = %(convertCmd)s --coordinates --from gautomatch --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
            """ % args)

        f.close()

        process = CoordinatesObjectView(project, micFn, coordsDir, prot,
                                        mode=CoordinatesObjectView.MODE_AUTOMATIC,
                                        pickerProps=pickerConfig).show()
        process.wait()
        myprops = pwutils.readProperties(pickerConfig)

        if myprops['applyChanges'] == 'true':
            form.setVar('threshold', myprops['threshold.value'])
            if not prot.advanced:
                form.setVar('minDist', myprops['mindist.value'])
            else:
                pass  # TODO: We could even in future parse the 'guessed' params
Example #13
0
    def show(self, form):
        autopickProt = form.protocol
        micSet = autopickProt.getInputMicrographs()
        if not micSet:
            print('must specify input micrographs')
            return

        # ensuring a valid boxSize
        if autopickProt.boxSize.get() is None:
            autopickProt.boxSize.set(100)

        project = autopickProt.getProject()
        coordsDir = project.getTmpPath(micSet.getName())

        cleanPath(coordsDir)
        makePath(coordsDir)

        micMdFn = os.path.join(coordsDir, "micrographs.xmd")
        writeSetOfMicrographs(micSet, micMdFn)

        pickerProps = os.path.join(coordsDir, 'picker.conf')
        f = open(pickerProps, "w")
        params = ['boxSize', 'lowerThreshold', 'higherThreshold', 'gaussWidth']
        program = eman2.Plugin.getBoxerCommand(boxerVersion='old')

        extraParams = "invert_contrast=%s:use_variance=%s:%s" % (
            autopickProt.doInvert,
            autopickProt.useVarImg,
            autopickProt.extraParams)

        args = {
            "params": ','.join(params),
            "preprocess": "%s %s" % (pw.getScipionScript(),
                                     eman2.Plugin.getProgram('sxprocess.py')),
            "picker": "%s %s" % (pw.getScipionScript(), program),
            "convert": pw.join('apps', 'pw_convert.py'),
            'coordsDir': coordsDir,
            'micsSqlite': micSet.getFileName(),
            "boxSize": autopickProt.boxSize,
            "lowerThreshold": autopickProt.lowerThreshold,
            "higherThreshold": autopickProt.higherThreshold,
            "gaussWidth": autopickProt.gaussWidth,
            "extraParams": extraParams
        }

        f.write("""
        parameters = %(params)s
        boxSize.value = %(boxSize)s
        boxSize.label = Box Size
        boxSize.help = Box size in pixels
        lowerThreshold.value =  %(lowerThreshold)s
        lowerThreshold.label = Lower Threshold
        lowerThreshold.help = Lower Threshold
        higherThreshold.help = Higher Threshold
        higherThreshold.value =  %(higherThreshold)s
        higherThreshold.label = Higher Threshold
        gaussWidth.help = Width of the Gaussian kernel used
        gaussWidth.value =  %(gaussWidth)s
        gaussWidth.label = Gauss Width
        runDir = %(coordsDir)s
        preprocessCommand = %(preprocess)s demoparms --makedb=thr_low=%%(lowerThreshold):thr_hi=%%(higherThreshold):boxsize=%%(boxSize):gauss_width=%%(gaussWidth):%(extraParams)s
        autopickCommand = %(picker)s --gauss_autoboxer=demoparms --write_dbbox --boxsize=%%(boxSize) --norm=normalize.ramp.normvar %%(micrograph) 
        convertCommand = %(convert)s --coordinates --from eman2 --to xmipp --input  %(micsSqlite)s --output %(coordsDir)s
        """ % args)
        f.close()
        process = CoordinatesObjectView(project, micMdFn, coordsDir, autopickProt,
                                        mode=CoordinatesObjectView.MODE_AUTOMATIC,
                                        pickerProps=pickerProps).show()
        process.wait()
        myprops = readProperties(pickerProps)

        if myprops['applyChanges'] == 'true':
            for param in params:
                form.setVar(param, myprops[param + '.value'])
Example #14
0
    def show(self, form):
        autopickProt = form.protocol

        if not autopickProt.hasAttribute('outputCoordinatesSubset'):
            form.showWarning("You should run the procotol in 'Optimize' mode "
                               "at least once before opening the wizard.")
            return

        project = autopickProt.getProject()
        micSet = autopickProt.outputMicrographsSubset
        micfn = micSet.getFileName()
        coordsDir = project.getTmpPath(micSet.getName())
        cleanPath(coordsDir)
        makePath(coordsDir)

        from pyworkflow.em.packages.xmipp3.convert import writeSetOfMicrographs
        micStarFn = os.path.join(coordsDir, 'micrographs.xmd')

        # Set CTF information to the micrographs to be displayed in the
        # picking list
        autopickProt.micDict = OrderedDict()
        micDict, _ = autopickProt._loadInputList()

        def _preprocessMic(mic, micRow):
            mic.setCTF(micDict[mic.getMicName()].getCTF())

        writeSetOfMicrographs(micSet, micStarFn,
                              preprocessImageRow=_preprocessMic)

        # Create a folder in extra to backup the original autopick star files
        backupDir = autopickProt._getExtraPath('wizard-backup')
        cleanPath(backupDir)
        makePath(backupDir)
        pwutils.copyPattern(autopickProt._getExtraPath("*autopick.star"),
                            backupDir)

        cmd = '%s relion_autopick ' % pw.getScipionScript()
        #cmd += '--i extra/%(micrographName).star '
        cmd += '--i input_micrographs.star '
        cmd += '--threshold %(threshold) --min_distance %(ipd) '
        cmd += ' --max_stddev_noise %(maxStddevNoise) '
        cmd += ' --read_fom_maps'
        cmd += autopickProt.getAutopickParams()

        convertCmd = pw.join('apps', 'pw_convert.py')
        convertCmd += ' --coordinates --from relion --to xmipp '
        convertCmd += ' --input %s' % micSet.getFileName()
        convertCmd += ' --output %s' % coordsDir
        convertCmd += ' --extra %s' % autopickProt._getExtraPath()

        args = {
            "threshold": autopickProt.pickingThreshold,
            'min_distance': autopickProt.interParticleDistance,
            'autopickCommand': cmd,
            'preprocessCommand': 'rm -rf %s/*.pos' % coordsDir,
            'convertCmd': convertCmd,
            'protDir': autopickProt.getWorkingDir(),
            'maxStddevNoise': autopickProt.maxStddevNoise
        }

        pickerProps = os.path.join(coordsDir, 'picker.conf')

        f = open(pickerProps, "w")
        f.write("""
        parameters = ipd,threshold,maxStddevNoise
        ipd.value = %(min_distance)s
        ipd.label = Inter-particles distance (A)
        ipd.help = Minimum distance (in Angstroms) between particles
        threshold.value =  %(threshold)s
        threshold.label = Threshold
        threshold.help = some help
        maxStddevNoise.value = %(maxStddevNoise)s
        maxStddevNoise.label = Max. stddev noise
        maxStddevNoise.help = Prevent picking in carbon areas, useful values probably between 1.0 and 1.2, use -1 to switch it off
        runDir = %(protDir)s
        preprocessCommand = %(preprocessCommand)s
        autopickCommand = %(autopickCommand)s
        convertCommand = %(convertCmd)s
        hasInitialCoordinates = true
        doPickAll = true
        """ % args)
        f.close()
        process = CoordinatesObjectView(autopickProt.getProject(), micStarFn,
                                        coordsDir, autopickProt,
                                        mode=CoordinatesObjectView.MODE_AUTOMATIC,
                                        pickerProps=pickerProps).show()
        process.wait()
        myprops = pwutils.readProperties(pickerProps)

        # Check if the wizard changes were accepted or just canceled
        if myprops.get('applyChanges', 'false') == 'true':
            form.setVar('pickingThreshold', myprops['threshold.value'])
            form.setVar('interParticleDistance', myprops['ipd.value'])
            form.setVar('maxStddevNoise', myprops['maxStddevNoise.value'])
            # Change the run type now to 'Compute' after using the wizard
            # and (supposedly) optimized parameters
            form.setVar('runType', RUN_COMPUTE)
            # Mark the wizard was used
            setattr(autopickProt, 'wizardExecuted', True)
        else:
            # If the wizard was not execute, we should restore the original
            # autopick star files in case their were modified by the wizard
            pwutils.copyPattern(os.path.join(backupDir, "*autopick.star"),
                                autopickProt._getExtraPath())