コード例 #1
0
        def _insertMicStep(mic):
            localDeps = [firstStepId]
            fnLast = mic.getFileName()
            micName = pwutils.removeBaseExt(mic.getFileName())

            def getMicTmp(suffix):
                return self._getTmpPath(micName + suffix)

            # Create a list with micrographs operations (programs in xmipp) and
            # the required command line parameters (except input/ouput files)
            micOps = []

            # Check if it is required to downsample your micrographs
            downFactor = self.downFactor.get()

            if self.notOne(downFactor):
                fnDownsampled = getMicTmp("_downsampled.xmp")
                args = "-i %s -o %s --step %f --method fourier"
                micOps.append(('xmipp_transform_downsample',
                               args % (fnLast, fnDownsampled, downFactor)))
                fnLast = fnDownsampled

            if self.doRemoveDust:
                fnNoDust = getMicTmp("_noDust.xmp")
                args = " -i %s -o %s --bad_pixels outliers %f"
                micOps.append(('xmipp_transform_filter',
                               args % (fnLast, fnNoDust, self.thresholdDust)))
                fnLast = fnNoDust

            if self._useCTF() and self.ctfDict[mic] is not None:
                # We need to write a Xmipp ctfparam file
                # to perform the phase flip on the micrograph
                fnCTF = self._getTmpPath("%s.ctfParam" % micName)
                mic.setCTF(self.ctfDict[mic])
                micrographToCTFParam(mic, fnCTF)
                # Insert step to flip micrograph
                if self.doFlip:
                    fnFlipped = getMicTmp('_flipped.xmp')
                    args = " -i %s -o %s --ctf %s --sampling %f"
                    micOps.append(
                        ('xmipp_ctf_phase_flip', args %
                         (fnLast, fnFlipped, fnCTF, self._getNewSampling())))
                    fnLast = fnFlipped
            else:
                fnCTF = None

            # Actually extract
            deps.append(
                self._insertFunctionStep('extractParticlesStep',
                                         mic.getObjId(),
                                         micName,
                                         fnCTF,
                                         fnLast,
                                         micOps,
                                         self.doInvert.get(),
                                         self._getNormalizeArgs(),
                                         self.doBorders.get(),
                                         prerequisites=localDeps))
コード例 #2
0
    def preprocessMicsStep(self):

        for i in range(len(self.inputCoordinatesTrue)):
            coordTrue = self.inputCoordinatesTrue[i].get()
            coordFalse = self.inputCoordinatesFalse[i].get()
            mics_ = coordTrue.getMicrographs()
            samplingRate = mics_.getSamplingRate()
            micIds = self.getMicsIds(i)
            micsFnameSet = {
                mics_[micId].getMicName(): mics_[micId].getFileName()
                for micId in micIds
            }
            if self.ignoreCTF.get():
                preproMicsContent = "#mics\n"
                for micName in micsFnameSet:
                    preproMicsContent += "%s\n" % (micsFnameSet[micName])
            else:
                preproMicsContent = "#mics ctfs\n"
                setOfMicCtf = self.ctfRelations[i].get()
                if setOfMicCtf.getSize() < len(micsFnameSet):
                    raise ValueError(
                        "Error, there are different number of CTFs compared to "
                        +
                        "the number of micrographs where particles were picked"
                    )
                else:
                    assert setOfMicCtf is not None, "Error, CTFs must be provided to compute phase flip"
                    for ctf in setOfMicCtf:
                        ctf_mic = ctf.getMicrograph()
                        ctfMicName = ctf_mic.getMicName()
                        if ctfMicName in micsFnameSet:
                            ctf_mic.setCTF(ctf)
                            ctfMicName = micsFnameSet[ctfMicName]
                            fnCTF = self._getTmpPath(
                                "%s.ctfParam" % os.path.basename(ctfMicName))
                            micrographToCTFParam(ctf_mic, fnCTF)
                            preproMicsContent += "%s %s\n" % (ctfMicName,
                                                              fnCTF)

            inputsFname = self._getExtraPath("preprocMic_inputs_%d.txt" % i)
            ouputDir = self._getExtraPath(self.PRE_PROC_MICs_PATH % i)
            nThrs = self.numberOfThreads.get()
            with open(inputsFname, "w") as f:
                f.write(preproMicsContent)
            downFactor = self._getDownFactor()
            args = "-i %s -s %s -d %s -o %s -t %d" % (
                inputsFname, samplingRate, downFactor, ouputDir, nThrs)
            if self.doInvert.get():
                args += " --invert_contrast"

            if not self.ignoreCTF.get():
                args += " --phase_flip"

            self.runJob('xmipp_preprocess_mics', args, numberOfMpi=1)
コード例 #3
0
    def _extractMicrograph(self, mic, doInvert, normalizeArgs, doBorders):
        """ Extract particles from one micrograph """
        fnLast = mic.getFileName()
        baseMicName = pwutils.removeBaseExt(fnLast)
        outputRoot = str(self._getExtraPath(baseMicName))
        fnPosFile = self._getMicPos(mic)
        boxSize = self.boxSize.get()
        downFactor = self.downFactor.get()
        patchSize = self.patchSize.get() if self.patchSize.get() > 0 \
                    else int(boxSize*1.5*downFactor)

        particlesMd = 'particles@%s' % fnPosFile
        # If it has coordinates extract the particles
        if exists(fnPosFile):
            # Create a list with micrographs operations (programs in xmipp) and
            # the required command line parameters (except input/ouput files)
            micOps = []

            # Compute the variance and Gini coeff. of the part. and mic., resp.
            args = '--pos %s' % fnPosFile
            args += ' --mic %s' % fnLast
            args += ' --patchSize %d' % patchSize
            self.runJob('xmipp_coordinates_noisy_zones_filter', args)

            def getMicTmp(suffix):
                return self._getTmpPath(baseMicName + suffix)

            # Check if it is required to downsample our micrographs
            if self.notOne(downFactor):
                fnDownsampled = getMicTmp("_downsampled.xmp")
                args = "-i %s -o %s --step %f --method fourier"
                self.runJob('xmipp_transform_downsample',
                            args % (fnLast, fnDownsampled, downFactor))
                fnLast = fnDownsampled

            if self.doRemoveDust:
                fnNoDust = getMicTmp("_noDust.xmp")
                args = " -i %s -o %s --bad_pixels outliers %f"
                self.runJob('xmipp_transform_filter',
                            args % (fnLast, fnNoDust, self.thresholdDust))
                fnLast = fnNoDust

            if self._useCTF():
                # We need to write a Xmipp ctfparam file
                # to perform the phase flip on the micrograph
                fnCTF = self._getTmpPath("%s.ctfParam" % baseMicName)
                micrographToCTFParam(mic, fnCTF)
                # Insert step to flip micrograph
                if self.doFlip:
                    fnFlipped = getMicTmp('_flipped.xmp')
                    args = " -i %s -o %s --ctf %s --sampling %f"
                    self.runJob(
                        'xmipp_ctf_phase_flip', args %
                        (fnLast, fnFlipped, fnCTF, self._getNewSampling()))
                    fnLast = fnFlipped
            else:
                fnCTF = None

            args = " -i %s --pos %s" % (fnLast, particlesMd)
            args += " -o %s --Xdim %d" % (outputRoot, boxSize)

            if doInvert:
                args += " --invert"

            if fnCTF:
                args += " --ctfparam " + fnCTF

            if doBorders:
                args += " --fillBorders"

            self.runJob("xmipp_micrograph_scissor", args)

            # Normalize
            if normalizeArgs:
                self.runJob('xmipp_transform_normalize',
                            '-i %s.stk %s' % (outputRoot, normalizeArgs))
        else:
            self.warning("The micrograph %s hasn't coordinate file! " %
                         baseMicName)
            self.warning("Maybe you picked over a subset of micrographs")

        # Let's clean the temporary mrc micrographs
        if not pwutils.envVarOn("SCIPION_DEBUG_NOCLEAN"):
            pwutils.cleanPattern(self._getTmpPath(baseMicName) + '*')