Exemple #1
0
 def convertStep(self, imgsFn):
     from convert import writeSetOfClasses2D, writeSetOfParticles
     imgSet = self.inputSet.get()
     if isinstance(imgSet, SetOfClasses2D):
         writeSetOfClasses2D(imgSet, self.imgsFn, writeParticles=False)
     else:
         writeSetOfParticles(imgSet, self.imgsFn)
 def convertInputStep(self, classesFn):
     inputSet = self.inputSet.get()
     
     if isinstance(inputSet, SetOfClasses2D):
         writeSetOfClasses2D(inputSet, classesFn)
     else:
         writeSetOfParticles(inputSet, classesFn)
    def convertInputStep(self, resetDeps):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId, volumesId: use this parameters just to force redo of
            convert if either the input particles and/or input volumes are
            changed.
        """
        self._imgFnList = []
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('input_star')

        subset = em.SetOfParticles(filename=":memory:")

        newIndex = 1
        for img in imgSet.iterItems(orderBy='RANDOM()', direction='ASC'):
            self._scaleImages(newIndex, img)
            newIndex += 1
            subset.append(img)
            subsetSize = self.subsetSize.get()
            minSize = min(subsetSize, imgSet.getSize())
            if subsetSize > 0 and subset.getSize() == minSize:
                break
        writeSetOfParticles(subset,
                            imgStar,
                            self._getExtraPath(),
                            alignType=em.ALIGN_NONE,
                            postprocessImageRow=self._postprocessParticleRow)
        self._convertInput(subset)
        self._convertRef()
Exemple #4
0
    def convertInputStep(self, moviesId, partsId):
        self._ih = em.ImageHandler()  # used to convert movies
        inputMovies = self.getInputMovies()
        firstMovie = inputMovies.getFirstItem()
        self._linkOrConvertMovie = self._getConvertFunc(firstMovie)

        # convert movies to mrcs and write a movie star file
        writeSetOfMovies(inputMovies,
                         self._getPath(self._getFileName('inputMovies')),
                         preprocessImageRow=self._preprocessMovieRow)

        inputParts = self.getParticles()
        firstPart = inputParts.getFirstItem()
        self._linkOrConvertPart = self._getConvertFunc(firstPart)
        # convert particle set to star file
        # we avoid to use the defaul convertBinaryFiles because we want
        # to set a different naming convention to map between movie mrcs
        # and particles stack mrcs
        writeSetOfParticles(
            inputParts,
            self._getPath(self._getFileName('inputParts')),
            None,  # do not use convertBinaryFiles
            fillMagnification=True,
            alignType=inputParts.getAlignment(),
            postprocessImageRow=self._postprocessParticleRow)
Exemple #5
0
 def convertInputStep(self, particlesId, classesId):
     writeSetOfParticles(self.inputParticles.get(),self.imgsFn,alignType=em.ALIGN_NONE)
     if not self.randomInitialization:
         if isinstance(self.initialClasses.get(), SetOfClasses2D):
             writeSetOfClasses2D(self.initialClasses.get(),self.initialClassesFn, writeParticles=False)
         else:
             writeSetOfParticles(self.initialClasses.get(),self.initialClassesFn)
Exemple #6
0
    def convertInputStep(self, classesFn):
        inputSet = self.inputSet.get()

        if isinstance(inputSet, SetOfClasses2D):
            writeSetOfClasses2D(inputSet, classesFn)
        else:
            writeSetOfParticles(inputSet, classesFn)
Exemple #7
0
    def convertInputStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId: use this parameter just to force redo of convert if
                the input particles are changed.
        """
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('movie_particles')
        imgStarTmp = self._getTmpPath('movie_particles.star')
        self.info("Converting set from '%s' into '%s'" %
                  (imgSet.getFileName(), imgStarTmp))

        writeSetOfParticles(imgSet, imgStarTmp, self._getExtraPath(),
                            alignType=imgSet.getAlignment(),
                            extraLabels=MOVIE_EXTRA_LABELS)
        mdImg = md.MetaData(imgStarTmp)

        # replace mdColumn from *.stk to *.mrcs as Relion2 requires
        if getVersion() == V1_3:
            mdColumn = md.RLN_PARTICLE_NAME
        else:
            mdColumn = md.RLN_PARTICLE_ORI_NAME

        from convert import relionToLocation, locationToRelion
        for objId in mdImg:
            index, imgPath = relionToLocation(mdImg.getValue(mdColumn, objId))
            if not imgPath.endswith('mrcs'):
                newName = pwutils.replaceBaseExt(os.path.basename(imgPath), 'mrcs')
                newPath = self._getTmpPath(newName)
                newLoc = locationToRelion(index, newPath)
                if not exists(newPath):
                    pwutils.createLink(imgPath, newPath)
                mdImg.setValue(mdColumn, newLoc, objId)
        mdImg.write(imgStar)
 def convertStep(self, imgsFn):
     from convert import writeSetOfClasses2D, writeSetOfParticles
     imgSet = self.inputSet.get()
     if isinstance(imgSet, SetOfClasses2D):
         writeSetOfClasses2D(imgSet, self.imgsFn, writeParticles=False)
     else:
         writeSetOfParticles(imgSet, self.imgsFn)
Exemple #9
0
 def convertInputStep(self):
     writeSetOfParticles(self.inputParticles.get(), self.imgsFn)
     if not self.randomInitialization:
         if isinstance(self.initialClasses.get(), SetOfClasses2D):
             writeSetOfClasses2D(self.initialClasses.get(), self.initialClassesFn, writeParticles=False)
         else:
             writeSetOfParticles(self.initialClasses.get(), self.initialClassesFn)
    def convertInputStep(self, resetDeps):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId, volumesId: use this parameters just to force redo of
            convert if either the input particles and/or input volumes are
            changed.
        """
        self._imgFnList = []
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('input_star')

        subset = em.SetOfParticles(filename=":memory:")

        newIndex = 1
        for img in imgSet.iterItems(orderBy='RANDOM()', direction='ASC'):
            self._scaleImages(newIndex, img)
            newIndex += 1
            subset.append(img)
            subsetSize = self.subsetSize.get()
            minSize = min(subsetSize, imgSet.getSize())
            if subsetSize   > 0 and subset.getSize() == minSize:
                break
        writeSetOfParticles(subset, imgStar, self._getExtraPath(),
                            alignType=em.ALIGN_NONE,
                            postprocessImageRow=self._postprocessParticleRow)
        self._convertInput(subset)
        self._convertRef()
Exemple #11
0
 def convertInputStep(self, inputId):
     """ Write the input images as a Xmipp metadata file. """
     writeSetOfParticles(self.inputParticles.get(),
                         self._getFileName('input_particles'))
     # If input references, also convert to xmipp metadata
     if not self.doGenerateReferences:
         writeSetOfParticles(self.inputReferences.get(),
                             self._getFileName('input_references'))
 def convertInputStep(self, particlesId):
     """ Write the input images as a Xmipp metadata file. 
     particlesId: is only need to detect changes in
     input particles and cause restart from here.
     """
     imgSet = self.inputParticles.get()
     writeSetOfParticles(imgSet, self._getFileName('input_star'),
                         self._getExtraPath())
Exemple #13
0
 def convertInputStep(self, particlesId):
     """ Write the input images as a Xmipp metadata file. 
     particlesId: is only need to detect changes in
     input particles and cause restart from here.
     """
     imgSet = self.inputParticles.get()
     writeSetOfParticles(imgSet, self._getFileName('input_star'),
                         self._getExtraPath())
Exemple #14
0
 def convertInputStep(self, inputId):
     """ Write the input images as a Xmipp metadata file. """
     writeSetOfParticles(self.inputParticles.get(),
                         self._getFileName('input_particles'))
     # If input references, also convert to xmipp metadata
     if not self.doGenerateReferences:
         writeSetOfParticles(self.inputReferences.get(),
                             self._getFileName('input_references'))
Exemple #15
0
    def convertInputStep(self):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        """
        imgSet  = self.inputParticles.get()
        imgStar = self._getFileName('input_particles.star')

        from convert import writeSetOfParticles
        # Pass stack file as None to avoid write the images files
        writeSetOfParticles(imgSet,imgStar,self._getTmpPath(), alignType=ALIGN_PROJ)
Exemple #16
0
 def convertInputStep(self, particlesId, classesId):
     writeSetOfParticles(self.inputParticles.get(),
                         self.imgsFn,
                         alignType=em.ALIGN_NONE)
     if not self.randomInitialization:
         if isinstance(self.initialClasses.get(), SetOfClasses2D):
             writeSetOfClasses2D(self.initialClasses.get(),
                                 self.initialClassesFn,
                                 writeParticles=False)
         else:
             writeSetOfParticles(self.initialClasses.get(),
                                 self.initialClassesFn)
Exemple #17
0
 def convertInputStep(self, inputParticlesId):
     writeSetOfParticles(self.inputParticles.get(), self.imgsFn)
     self.runJob('xmipp_metadata_utilities',
                 '-i %s --fill image1 constant noImage' % self.imgsFn,
                 numberOfMpi=1)
     self.runJob('xmipp_metadata_utilities',
                 '-i %s --operate modify_values "image1=image"' %
                 self.imgsFn,
                 numberOfMpi=1)
     self.runJob('xmipp_metadata_utilities',
                 '-i %s --operate rename_column "itemId particleId"' %
                 self.imgsFn,
                 numberOfMpi=1)
    def convertInputStep(self):
        inputParts = self.inputParticles.get()
        imgStar = self._getPath('input_particles.star')

        self.info("Converting set from '%s' into '%s'" %
                  (inputParts.getFileName(), imgStar))

        inputFolder = self._getPath('input')
        pwutils.makePath(inputFolder)
        convert.writeSetOfParticles(inputParts, imgStar, inputFolder,
                                    alignType=em.ALIGN_PROJ,
                                    fillMagnification=True,
                                    fillRandomSubset=True)
    def sortImages(self, inputId):
        imagesMd = self._getPath('images.xmd')
        writeSetOfParticles(self.inputParticles.get(), imagesMd)
        args = "-i Particles@%s --addToInput " % imagesMd
        
        if self.autoParRejection == self.REJ_MAXZSCORE:
            args += "--zcut " + str(self.maxZscore.get())
        
        elif self.autoParRejection == self.REJ_PERCENTAGE:
            args += "--percent " + str(self.percentage.get())

        self.runJob("xmipp_image_sort_by_statistics", args)
        
        self.outputMd = String(imagesMd)
 def convertStep(self, imgsFn):
     from convert import writeSetOfClasses2D, writeSetOfParticles
     imgSet = self.inputSet.get()
     if isinstance(imgSet, SetOfClasses2D):
         writeSetOfClasses2D(imgSet, self.imgsFn, writeParticles=True)
     else:
         writeSetOfParticles(imgSet, self.imgsFn)
     from pyworkflow.em.convert import ImageHandler
     img = ImageHandler()
     fnVol = self._getTmpPath("volume.vol")
     img.convert(self.inputVolume.get(), fnVol)
     xdim=self.inputVolume.get().getDim()[0]
     if xdim!=self._getDimensions():
         self.runJob("xmipp_image_resize","-i %s --dim %d"%(fnVol,self._getDimensions()))
    def convertInputStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId: use this parameters just to force redo of convert if 
                the input particles are changed.
        """
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('input_star')

        self.info("Converting set from '%s' into '%s'" %
                           (imgSet.getFileName(), imgStar))
        
        # Pass stack file as None to avoid write the images files
        writeSetOfParticles(imgSet, imgStar, self._getExtraPath())
        
        if self.doCtfManualGroups:
            self._splitInCTFGroups(imgStar)
        
        if not self.IS_CLASSIFY:
            if self.realignMovieFrames:
                movieParticleSet = self.inputMovieParticles.get()
                
                auxMovieParticles = self._createSetOfMovieParticles(suffix='tmp')
                auxMovieParticles.copyInfo(movieParticleSet)
                # Discard the movie particles that are not present in the refinement set
                for movieParticle in movieParticleSet:
                    particle = imgSet[movieParticle.getParticleId()]
                    if particle is not None:
                        auxMovieParticles.append(movieParticle)
                writeSetOfParticles(auxMovieParticles,
                                    self._getFileName('movie_particles'), None, originalSet=imgSet,
                                    postprocessImageRow=self._postprocessImageRow)
                mdMovies = md.MetaData(self._getFileName('movie_particles'))
                mdParts = md.MetaData(self._getFileName('input_star'))

                if getVersion() == "1.4":
                    mdParts.renameColumn(md.RLN_IMAGE_NAME, md.RLN_PARTICLE_ORI_NAME)
                else:
                    mdParts.renameColumn(md.RLN_IMAGE_NAME, md.RLN_PARTICLE_NAME)
                mdParts.removeLabel(md.RLN_MICROGRAPH_NAME)
                
                detectorPxSize = movieParticleSet.getAcquisition().getMagnification() * movieParticleSet.getSamplingRate() / 10000
                mdAux = md.MetaData()
                mdMovies.fillConstant(md.RLN_CTF_DETECTOR_PIXEL_SIZE, detectorPxSize)
                
                mdAux.join2(mdMovies, mdParts, md.RLN_PARTICLE_ID, md.RLN_IMAGE_ID, md.INNER_JOIN)
                
                mdAux.write(self._getFileName('movie_particles'), md.MD_OVERWRITE)
                cleanPath(auxMovieParticles.getFileName())
    def sortImages(self, inputId):
        imagesMd = self._getPath('images.xmd')
        writeSetOfParticles(self.inputParticles.get(), imagesMd)
        args = "-i Particles@%s --addToInput " % imagesMd
        
        if self.autoParRejection == self.REJ_MAXZSCORE:
            args += "--zcut " + str(self.maxZscore.get())
        
        elif self.autoParRejection == self.REJ_PERCENTAGE:
            args += "--percent " + str(self.percentage.get())

        self.runJob("xmipp_image_sort_by_statistics", args)
        
        self.outputMd = String(imagesMd)
 def convertStep(self, imgsFn):
     from convert import writeSetOfClasses2D, writeSetOfParticles
     imgSet = self.inputSet.get()
     if isinstance(imgSet, SetOfClasses2D):
         writeSetOfClasses2D(imgSet, self.imgsFn, writeParticles=True)
     else:
         writeSetOfParticles(imgSet, self.imgsFn)
     from pyworkflow.em.convert import ImageHandler
     img = ImageHandler()
     fnVol = self._getTmpPath("volume.vol")
     img.convert(self.inputVolume.get(), fnVol)
     xdim = self.inputVolume.get().getDim()[0]
     if xdim != self._getDimensions():
         self.runJob("xmipp_image_resize",
                     "-i %s --dim %d" % (fnVol, self._getDimensions()))
Exemple #24
0
    def convertInputStep(self, inputId, avgId, volId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId: use this parameters just to force redo of convert if
                the input particles are changed.
        """
        inputSet = self.inputSet.get()
        imgStar = self._getFileName('input_particles')
        refStar = self._getFileName('input_refs')
        # Pass stack file as None to avoid write the images files
        self.info("Converting set from '%s' into '%s'" %
                  (inputSet.getFileName(), imgStar))

        refSet = None
        # case refine3D
        if self.isInputClasses():
            refSet = self.inputSet.get()  # 2D or 3D classes

        else:
            if self.isInputAutoRefine():
                em.ImageHandler().convert(self.referenceVolume.get(),
                                          self._getFileName('input_refvol'))
            else:  # Autopicking case
                refSet = self.referenceAverages.get()

        self.classDict = {}

        if refSet:
            self.info("Converting reference from '%s' into %s" %
                      (refSet.getFileName(), refStar))

            # Compute class mapping
            classList = [cls.getObjId() for cls in refSet]
            classList.sort()
            for i, c in enumerate(classList):
                self.classDict[c] = i + 1

            writeReferences(refSet,
                            removeExt(refStar),
                            postprocessImageRow=self._updateClasses)

        # Write particles star file
        allParticles = self._allParticles(iterate=False)
        writeSetOfParticles(allParticles,
                            imgStar,
                            self._getPath(),
                            postprocessImageRow=self._postProcessImageRow)
Exemple #25
0
    def convertInputStep(self, classesFn):
        inputSet = self.inputSet.get()

        if isinstance(inputSet, SetOfClasses2D):
            writeSetOfClasses2D(inputSet, classesFn, writeParticles=False)
        else:
            writeSetOfParticles(inputSet, classesFn)

        if self.thereisRefVolume:
            inputVolume = self.refVolume.get()
            fnVolumes = self._getExtraPath('input_volumes.xmd')
            row = XmippMdRow()
            volumeToRow(inputVolume, row, alignType=ALIGN_NONE)
            md = xmipp.MetaData()
            row.writeToMd(md, md.addObject())
            md.write(fnVolumes)
 def convertInputStep(self, classesFn):
     inputSet = self.inputSet.get()
     
     if isinstance(inputSet, SetOfClasses2D):
         writeSetOfClasses2D(inputSet, classesFn, writeParticles=False)
     else:
         writeSetOfParticles(inputSet, classesFn)
         
     if self.thereisRefVolume:
         inputVolume= self.refVolume.get()
         fnVolumes = self._getExtraPath('input_volumes.xmd')
         row = XmippMdRow()
         volumeToRow(inputVolume, row, alignType = ALIGN_NONE)
         md = xmipp.MetaData()
         row.writeToMd(md, md.addObject())
         md.write(fnVolumes)
    def denoiseImages(self, inputId, inputClassesId):
        # We start preparing writing those elements we're using as input to keep them untouched
        imagesMd = self._getPath('images.xmd')
        writeSetOfParticles(self.inputParticles.get(), imagesMd)
        classesMd = self._getPath('classes.xmd')
        writeSetOfClasses2D(self.inputClasses.get(), classesMd)

        fnRoot = self._getExtraPath('pca')
        fnRootDenoised = self._getExtraPath('imagesDenoised')

        args = '-i Particles@%s --oroot %s --eigenvectors %d --maxImages %d' % (imagesMd, fnRoot, self.maxPCABases.get(), self.maxClasses.get())
        self.runJob("xmipp_image_rotational_pca", args)

        N=min(self.maxPCABases.get(), self.PCABases2Project.get())
        args='-i %s -o %s.stk --save_metadata_stack %s.xmd --basis %s.stk %d'\
             % (imagesMd, fnRootDenoised, fnRootDenoised, fnRoot, N)

        self.runJob("xmipp_transform_filter", args)

        self.outputMd = String('%s.stk' % fnRootDenoised)
    def denoiseImages(self, inputId, inputClassesId):
        # We start preparing writing those elements we're using as input to keep them untouched
        imagesMd = self._getPath('images.xmd')
        writeSetOfParticles(self.inputParticles.get(), imagesMd)
        classesMd = self._getPath('classes.xmd')
        writeSetOfClasses2D(self.inputClasses.get(), classesMd)

        fnRoot = self._getExtraPath('pca')
        fnRootDenoised = self._getExtraPath('imagesDenoised')

        args = '-i Particles@%s --oroot %s --eigenvectors %d --maxImages %d' % (imagesMd, fnRoot, self.maxPCABases.get(), self.maxClasses.get())
        self.runJob("xmipp_image_rotational_pca", args)

        N=min(self.maxPCABases.get(), self.PCABases2Project.get())
        args='-i %s -o %s.stk --save_metadata_stack %s.xmd --basis %s.stk %d'\
             % (imagesMd, fnRootDenoised, fnRootDenoised, fnRoot, N)

        self.runJob("xmipp_transform_filter", args)

        self.outputMd = String('%s.stk' % fnRootDenoised)
    def exportParticlesStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file. 
        """
        imgSet = self.inputParticles.get()
        self._stackType = self.stackType.get()
        self._ih = em.ImageHandler()
        self._stackDict = {}
        particlesPath = self._getPath('Particles')
        pwutils.cleanPath(particlesPath)
        pwutils.makePath(particlesPath)

        alignType = imgSet.getAlignment() if self.useAlignment else em.ALIGN_NONE
        # Create links to binary files and write the relion .star file
        writeSetOfParticles(imgSet, self._getPath("particles.star"),
                            outputDir=self._getExtraPath(),
                            alignType=alignType,
                            postprocessImageRow=self._postprocessImageRow,
                            fillMagnification=True)

        pwutils.prettyDict(self._stackDict)
Exemple #30
0
    def convertInputStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId: use this parameter just to force redo of convert if
                the input particles are changed.
        """
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('movie_particles')
        imgStarTmp = self._getTmpPath('movie_particles.star')
        self.info("Converting set from '%s' into '%s'" %
                  (imgSet.getFileName(), imgStarTmp))

        writeSetOfParticles(imgSet,
                            imgStarTmp,
                            self._getExtraPath(),
                            alignType=imgSet.getAlignment(),
                            extraLabels=MOVIE_EXTRA_LABELS)
        mdImg = md.MetaData(imgStarTmp)

        # replace mdColumn from *.stk to *.mrcs as Relion2 requires
        if getVersion() == V1_3:
            mdColumn = md.RLN_PARTICLE_NAME
        else:
            mdColumn = md.RLN_PARTICLE_ORI_NAME

        from convert import relionToLocation, locationToRelion
        for objId in mdImg:
            index, imgPath = relionToLocation(mdImg.getValue(mdColumn, objId))
            if not imgPath.endswith('mrcs'):
                newName = pwutils.replaceBaseExt(os.path.basename(imgPath),
                                                 'mrcs')
                newPath = self._getTmpPath(newName)
                newLoc = locationToRelion(index, newPath)
                if not exists(newPath):
                    pwutils.createLink(imgPath, newPath)
                mdImg.setValue(mdColumn, newLoc, objId)
        mdImg.write(imgStar)
    def exportParticlesStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file. 
        """
        imgSet = self.inputParticles.get()
        self._stackType = self.stackType.get()
        self._ih = em.ImageHandler()
        self._stackDict = {}
        particlesPath = self._getPath('Particles')
        pwutils.cleanPath(particlesPath)
        pwutils.makePath(particlesPath)

        alignType = imgSet.getAlignment(
        ) if self.useAlignment else em.ALIGN_NONE
        # Create links to binary files and write the relion .star file
        writeSetOfParticles(imgSet,
                            self._getPath("particles.star"),
                            outputDir=self._getExtraPath(),
                            alignType=alignType,
                            postprocessImageRow=self._postprocessImageRow,
                            fillMagnification=True)

        pwutils.prettyDict(self._stackDict)
Exemple #32
0
 def convertInputStep(self):
     writeSetOfParticles(self.inputParticles.get(),
                         self.imgsFn,
                         alignType=em.ALIGN_NONE)
 def convertInputStep(self):
     writeSetOfParticles(self.inputParticles.get(), self.imgsFn)
    def convertInputStep(self, particlesId):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        Params:
            particlesId: use this parameters just to force redo of convert if 
                the input particles are changed.
        """
        imgSet = self._getInputParticles()
        imgStar = self._getFileName('input_star')

        self.info("Converting set from '%s' into '%s'" %
                  (imgSet.getFileName(), imgStar))

        # Pass stack file as None to avoid write the images files
        writeSetOfParticles(imgSet, imgStar, self._getExtraPath())

        if self.doCtfManualGroups:
            self._splitInCTFGroups(imgStar)

        if not self.IS_CLASSIFY:
            if self.realignMovieFrames:
                movieParticleSet = self.inputMovieParticles.get()

                auxMovieParticles = self._createSetOfMovieParticles(
                    suffix='tmp')
                auxMovieParticles.copyInfo(movieParticleSet)
                # Discard the movie particles that are not present in the refinement set
                for movieParticle in movieParticleSet:
                    particle = imgSet[movieParticle.getParticleId()]
                    if particle is not None:
                        auxMovieParticles.append(movieParticle)
                writeSetOfParticles(
                    auxMovieParticles,
                    self._getFileName('movie_particles'),
                    None,
                    originalSet=imgSet,
                    postprocessImageRow=self._postprocessImageRow)
                mdMovies = md.MetaData(self._getFileName('movie_particles'))
                mdParts = md.MetaData(self._getFileName('input_star'))

                if getVersion() == "1.4":
                    mdParts.renameColumn(md.RLN_IMAGE_NAME,
                                         md.RLN_PARTICLE_ORI_NAME)
                else:
                    mdParts.renameColumn(md.RLN_IMAGE_NAME,
                                         md.RLN_PARTICLE_NAME)
                mdParts.removeLabel(md.RLN_MICROGRAPH_NAME)

                detectorPxSize = movieParticleSet.getAcquisition(
                ).getMagnification() * movieParticleSet.getSamplingRate(
                ) / 10000
                mdAux = md.MetaData()
                mdMovies.fillConstant(md.RLN_CTF_DETECTOR_PIXEL_SIZE,
                                      detectorPxSize)

                mdAux.join2(mdMovies, mdParts, md.RLN_PARTICLE_ID,
                            md.RLN_IMAGE_ID, md.INNER_JOIN)

                mdAux.write(self._getFileName('movie_particles'),
                            md.MD_OVERWRITE)
                cleanPath(auxMovieParticles.getFileName())
Exemple #35
0
    def convertInputStep(self, movId, partId, postId):
        inputMovies = self.inputMovies.get()
        inputParts = self.inputParticles.get()
        imgStar = self._getPath('input_particles.star')
        inputPartsFolder = self._getInputPath('particles')
        pwutils.makePath(inputPartsFolder)

        self.info("Converting set from '%s' into '%s'" %
                  (inputParts.getFileName(), imgStar))

        tableMovies = Table(
            columns=['rlnMicrographName', 'rlnMicrographMetadata'])
        tableGeneral = Table(columns=[
            'rlnImageSizeX', 'rlnImageSizeY', 'rlnImageSizeZ',
            'rlnMicrographMovieName', 'rlnMicrographBinning',
            'rlnMicrographOriginalPixelSize', 'rlnMicrographDoseRate',
            'rlnMicrographPreExposure', 'rlnVoltage',
            'rlnMicrographStartFrame', 'rlnMotionModelVersion'
        ])
        tableShifts = Table(columns=[
            'rlnMicrographFrameNumber', 'rlnMicrographShiftX',
            'rlnMicrographShiftY'
        ])
        tableCoeffs = Table(
            columns=['rlnMotionModelCoeffsIdx', 'rlnMotionModelCoeff'])

        # Create the first row, later only the movieName will be updated
        xdim, ydim, ndim = inputMovies.getDim()
        acq = inputMovies.getAcquisition()
        firstMovie = inputMovies.getFirstItem()
        a0, aN = firstMovie.getAlignment().getRange()
        moviesPixelSize = inputMovies.getSamplingRate()
        binningFactor = inputParts.getSamplingRate() / moviesPixelSize
        hasLocal = firstMovie.hasAttribute('_rlnMotionModelCoeff')
        motionMode = 1 if hasLocal else 0

        tableGeneral.addRow(xdim, ydim, ndim, 'movieName',
                            binningFactor, moviesPixelSize,
                            acq.getDosePerFrame(), acq.getDoseInitial(),
                            acq.getVoltage(), a0, motionMode)
        row = tableGeneral[0]

        for movie in inputMovies:
            movieFn = movie.getFileName()
            movieBase = os.path.basename(movieFn)
            movieStar = self._getInputPath(
                pwutils.replaceBaseExt(movieFn, 'star'))
            tableMovies.addRow(movieBase, movieStar)
            with open(movieStar, 'w') as f:
                # Update Movie name
                tableGeneral[0] = row._replace(rlnMicrographMovieName=movieFn)
                tableGeneral.writeStar(f, tableName='general', singleRow=True)
                # Write shifts
                tableShifts.clearRows()
                alignment = movie.getAlignment()
                shiftsX, shiftsY = alignment.getShifts()
                a0, aN = alignment.getRange()
                empty = -9999.000
                for i in range(1, a0):
                    tableShifts.addRow(i, empty, empty)
                # Adjust the shifts to be relative to the first frame
                # so let's add the opposite value
                xoff, yoff = -shiftsX[0], -shiftsY[0]
                for i in range(a0, aN + 1):
                    tableShifts.addRow(i, shiftsX[i - a0] + xoff,
                                       shiftsY[i - a0] + yoff)
                for i in range(aN + 1, ndim + 1):
                    tableShifts.addRow(i, empty, empty)
                tableShifts.writeStar(f, tableName='global_shift')

                # Write coefficients
                if hasLocal:
                    coeffs = movie.getAttributeValue('_rlnMotionModelCoeff',
                                                     '')
                    tableCoeffs.clearRows()
                    for i, c in enumerate(json.loads(coeffs)):
                        tableCoeffs.addRow(i, c)
                    tableCoeffs.writeStar(f, tableName='local_motion_model')

        with open(self._getPath('input_corrected_micrographs.star'), 'w') as f:
            tableMovies.writeStar(f)

        convert.writeSetOfParticles(inputParts,
                                    imgStar,
                                    inputPartsFolder,
                                    alignType=em.ALIGN_PROJ,
                                    fillMagnification=True,
                                    fillRandomSubset=True)
Exemple #36
0
 def convertInputStep(self, particlesId):
     """  Write the input images as a Relion star file.
     """
     imgSet = self.inputParticles.get()
     writeSetOfParticles(imgSet, self._getFileName('input_star'),
                         self._getExtraPath())
Exemple #37
0
    def convertInputStep(self, resetDeps, copyAlignment):
        """ Create the input file in STAR format as expected by Relion.
        If the input particles comes from Relion, just link the file.
        """
        imgStar = self._getFileName('input_star', lev=self._level, rLev=1)

        if self._level == 1:
            makePath(self._getRunPath(self._level, 1))
            imgSet = self._getInputParticles()
            self.info("Converting set from '%s' into '%s'" %
                      (imgSet.getFileName(), imgStar))

            # Pass stack file as None to avoid write the images files
            # If copyAlignment is set to False pass alignType to ALIGN_NONE
            alignType = imgSet.getAlignment() if copyAlignment \
                else em.ALIGN_NONE

            hasAlign = alignType != em.ALIGN_NONE
            alignToPrior = hasAlign and self._getBoolAttr('alignmentAsPriors')
            fillRandomSubset = hasAlign and self._getBoolAttr(
                'fillRandomSubset')

            writeSetOfParticles(
                imgSet,
                imgStar,
                self._getExtraPath(),
                alignType=alignType,
                postprocessImageRow=self._postprocessParticleRow,
                fillRandomSubset=fillRandomSubset)
            if alignToPrior:
                self._copyAlignAsPriors(imgStar, alignType)

            if self.doCtfManualGroups:
                self._splitInCTFGroups(imgStar)

            self._convertVol(em.ImageHandler(), self.inputVolumes.get())
        else:
            noOfLevRuns = self._getLevRuns(self._level)
            lastCls = None

            prevStar = self._getFileName('outputData', lev=self._level - 1)
            mdData = md.MetaData(prevStar)
            print('how many run levels? %d' % noOfLevRuns)

            for row in md.iterRows(mdData, sortByLabel=md.RLN_PARTICLE_CLASS):
                clsPart = row.getValue(md.RLN_PARTICLE_CLASS)
                if clsPart != lastCls:
                    makePath(self._getRunPath(self._level, clsPart))

                    if lastCls is not None:
                        print("writing %s" % fn)
                        mdInput.write(fn)
                    paths = self._getRunPath(self._level, clsPart)
                    makePath(paths)
                    print("Path: %s and newRlev: %d" % (paths, clsPart))
                    lastCls = clsPart
                    mdInput = md.MetaData()
                    fn = self._getFileName('input_star',
                                           lev=self._level,
                                           rLev=clsPart)
                objId = mdInput.addObject()
                row.writeToMd(mdInput, objId)
            print("writing %s and ending the loop" % fn)
            mdInput.write(fn)
 def convertInputStep(self):
     writeSetOfParticles(self.inputParticles.get(),self.imgsFn) 
 def convertInputStep(self):
     writeSetOfParticles(self.inputParticles.get(),self.imgsFn,alignType=constants.ALIGN_NONE)
Exemple #40
0
 def convertInputStep(self, outputFn):
     """ Create a metadata with the images and geometrical information. """
     writeSetOfParticles(self.inputParticles.get(), outputFn, self._getPath())
 def convertInputStep(self, inputParticlesId):
     writeSetOfParticles(self.directionalClasses.get(),self._getExtraPath("directionalClasses.xmd"))
 def convertInputStep(self, outputFn):
     """ Create a metadata with the images and geometrical information. """
     writeSetOfParticles(self.inputParticles.get(), outputFn)
     
     return [outputFn]
 def convertInputStep(self, inputParticlesId):
     writeSetOfParticles(self.inputParticles.get(),self.imgsFn)
     self.runJob('xmipp_metadata_utilities','-i %s --fill image1 constant noImage'%self.imgsFn,numberOfMpi=1)
     self.runJob('xmipp_metadata_utilities','-i %s --operate modify_values "image1=image"'%self.imgsFn,numberOfMpi=1)
     self.runJob('xmipp_metadata_utilities','-i %s --operate rename_column "itemId particleId"'%self.imgsFn,numberOfMpi=1)