Beispiel #1
0
    def createOutputStep(self):

        if not self.realignMovieFrames:
            imgSet = self._getInputParticles()
            vol = Volume()
            vol.setFileName(self._getExtraPath('relion_class001.mrc'))
            vol.setSamplingRate(imgSet.getSamplingRate())
            half1 = self._getFileName("final_half1_volume", ref3d=1)
            half2 = self._getFileName("final_half2_volume", ref3d=1)
            vol.setHalfMaps([half1, half2])

            outImgSet = self._createSetOfParticles()
            outImgSet.copyInfo(imgSet)
            self._fillDataFromIter(outImgSet, self._lastIter())

            self._defineOutputs(outputVolume=vol)
            self._defineSourceRelation(self.inputParticles, vol)
            self._defineOutputs(outputParticles=outImgSet)
            self._defineTransformRelation(self.inputParticles, outImgSet)

            fsc = FSC(objLabel=self.getRunName())
            blockName = 'model_class_%d@' % 1
            fn = blockName + self._getExtraPath("relion_model.star")
            mData = md.MetaData(fn)
            fsc.loadFromMd(mData, md.RLN_RESOLUTION,
                           md.RLN_MLMODEL_FSC_HALVES_REF)
            self._defineOutputs(outputFSC=fsc)
            self._defineSourceRelation(vol, fsc)

        else:
            movieSet = self.inputMovieParticles.get()
            if self.movieIncludeRotSearch:
                vol = Volume()
                vol.setFileName(self._getExtraPath('relion_class001.mrc'))
                vol.setSamplingRate(movieSet.getSamplingRate())
                half1 = self._getFileName("final_half1_volume", ref3d=1)
                half2 = self._getFileName("final_half2_volume", ref3d=1)
                vol.setHalfMaps([half1, half2])

                self._defineOutputs(outputVolume=vol)
                self._defineSourceRelation(self.inputParticles, vol)
                self._defineSourceRelation(self.inputMovieParticles, vol)

            fnOut = self._getFileName('dataFinal')
            outMovieSet = self._createSetOfMovieParticles()
            outMovieSet.copyInfo(movieSet)
            outMovieSet.setAlignmentProj()
            # not using copyItems since input movie particle
            # set is missing a lot of metadata (CTF, micName etc.)
            # that was created in convertInputStep
            readSetOfParticles(fnOut,
                               outMovieSet,
                               alignType=ALIGN_PROJ,
                               extraLabels=MOVIE_EXTRA_LABELS,
                               postprocessImageRow=self._updateParticle)

            self._defineOutputs(outputParticles=outMovieSet)
            self._defineTransformRelation(self.inputParticles, outMovieSet)
            self._defineTransformRelation(self.inputMovieParticles,
                                          outMovieSet)
Beispiel #2
0
    def importParticles(self):
        """ Import particles from a metadata 'images.xmd' """
        self.ignoreIds = self.protocol.ignoreIdColumn.get()
        self._imgDict = {} # store which images stack have been linked/copied and the new path
        self._findImagesPath(label=md.RLN_IMAGE_NAME)
        if self._micIdOrName:
            # If MDL_MICROGRAPH_ID or MDL_MICROGRAPH then
            # create a set to link from particles
            self.micSet = self.protocol._createSetOfMicrographs()
            self.protocol.setSamplingRate(self.micSet)
            self.micSet.setIsPhaseFlipped(self.protocol.haveDataBeenPhaseFlipped.get())
            self.protocol.fillAcquisition(self.micSet.getAcquisition())

        partSet = self.protocol._createSetOfParticles()
        partSet.setObjComment('Particles imported from Relion star file:\n%s' % self._starFile)

        # Update both samplingRate and acquisition with parameters
        # selected in the protocol form
        self.protocol.setSamplingRate(partSet)
        partSet.setIsPhaseFlipped(self.protocol.haveDataBeenPhaseFlipped.get())
        self.protocol.fillAcquisition(partSet.getAcquisition())
        # Read the micrographs from the 'self._starFile' metadata
        # but fixing the filenames with new ones (linked or copy to extraDir)
        from convert import readSetOfParticles
        readSetOfParticles(self._starFile, partSet,
                           preprocessImageRow=self._preprocessImageRow,
                           postprocessImageRow=self._postprocessImageRow,
                           readAcquisition=False, alignType=self.alignType)
        if self._micIdOrName:
            self.protocol._defineOutputs(outputMicrographs=self.micSet)
        self.protocol._defineOutputs(outputParticles=partSet)

        if self._classesFunc is not None:
            self._createClasses(partSet)
Beispiel #3
0
    def importParticles(self):
        """ Import particles from Frealign.
        Params:
            parFile: the filename of the parameter file with the alignment in Frealign.
            stackFile: single stack file with the images.
        """
        partSet = self.protocol._createSetOfParticles()
        partSet.setObjComment('Particles imported from Frealign parfile:\n%s' %
                              self.parFile)

        # Create a local link to the input stack file
        localStack = self.protocol._getExtraPath(
            os.path.basename(self.stackFile))
        pwutils.createLink(self.stackFile, localStack)
        # Create a temporary set only with location
        tmpSet = SetOfParticles(filename=':memory:')
        tmpSet.readStack(localStack)
        self._setupSet(tmpSet)

        # Update both samplingRate and acquisition with parameters
        # selected in the protocol form
        self._setupSet(partSet)
        # Now read the alignment parameters from par file
        readSetOfParticles(tmpSet, partSet, self.parFile)
        partSet.setHasCTF(True)
        # Register the output set of particles
        self.protocol._defineOutputs(outputParticles=partSet)
    def createOutputStep(self):
        lastIter = self._getLastIter()
        inputSet = self.inputParticles.get()
        inputRef = self.input3DReference.get()
        lastIterDir = self._iterWorkingDir(lastIter)

        # Register output volume
        volFn = join(lastIterDir, 'volume_iter_%03d.mrc' % lastIter)
        vol = Volume()
        vol.setSamplingRate(inputSet.getSamplingRate())
        vol.setFileName(volFn)
        self._defineOutputs(outputVolume=vol)
        self._defineSourceRelation(inputSet, vol)
        self._defineSourceRelation(inputRef, vol)

        # Register output Particles with their 3D alignment
        #TODO: save alignment
        #read last alignment file
        file2 = self._getFileName('output_par', iter=lastIter)
        partSet = self._createSetOfParticles()
        partSet.copyInfo(inputSet)
        readSetOfParticles(inputSet, partSet, file2)
        self._defineOutputs(outputParticles=partSet)
        self._defineTransformRelation(inputSet, partSet)
        self._defineSourceRelation(inputRef, partSet)
Beispiel #5
0
    def importParticles(self):
        """ Import particles from Frealign.
        Params:
            parFile: the filename of the parameter file with the alignment in Frealing.
            stackFile: single stack file with the images.
        """
        partSet = self.protocol._createSetOfParticles()
        partSet.setObjComment("Particles imported from Frealign parfile:\n%s" % self.parFile)

        # Create a local link to the input stack file
        localStack = self.protocol._getExtraPath(os.path.basename(self.stackFile))
        pwutils.createLink(self.stackFile, localStack)
        # Create a temporarly set only with location
        tmpSet = SetOfParticles(filename=":memory:")
        tmpSet.readStack(localStack)
        self._setupSet(tmpSet)

        # Update both samplingRate and acquisition with parameters
        # selected in the protocol form
        self._setupSet(partSet)
        # Now read the alignment parameters from par file
        readSetOfParticles(tmpSet, partSet, self.parFile)
        partSet.setHasCTF(True)
        # Register the output set of particles
        self.protocol._defineOutputs(outputParticles=partSet)
Beispiel #6
0
    def importParticles(self):
        """ Import particles from a metadata 'images.xmd' """
        self.ignoreIds = self.protocol.ignoreIdColumn.get()
        self._imgDict = {} # store which images stack have been linked/copied and the new path
        self._findImagesPath(label=md.RLN_IMAGE_NAME)
        if self._micIdOrName:
            # If MDL_MICROGRAPH_ID or MDL_MICROGRAPH then
            # create a set to link from particles
            self.micSet = self.protocol._createSetOfMicrographs()
            self.protocol.setSamplingRate(self.micSet)
            self.micSet.setIsPhaseFlipped(self.protocol.haveDataBeenPhaseFlipped.get())
            self.protocol.fillAcquisition(self.micSet.getAcquisition())

        partSet = self.protocol._createSetOfParticles()
        partSet.setObjComment('Particles imported from Relion star file:\n%s' % self._starFile)

        # Update both samplingRate and acquisition with parameters
        # selected in the protocol form
        self.protocol.setSamplingRate(partSet)
        partSet.setIsPhaseFlipped(self.protocol.haveDataBeenPhaseFlipped.get())
        self.protocol.fillAcquisition(partSet.getAcquisition())
        # Read the micrographs from the 'self._starFile' metadata
        # but fixing the filenames with new ones (linked or copy to extraDir)
        from convert import readSetOfParticles
        readSetOfParticles(self._starFile, partSet,
                           preprocessImageRow=self._preprocessImageRow,
                           postprocessImageRow=self._postprocessImageRow,
                           readAcquisition=False, alignType=self.alignType)
        if self._micIdOrName:
            self.protocol._defineOutputs(outputMicrographs=self.micSet)
        self.protocol._defineOutputs(outputParticles=partSet)

        if self._classesFunc is not None:
            self._createClasses(partSet)
Beispiel #7
0
    def createOutputStep(self):
        
        if not self.realignMovieFrames:
            imgSet = self._getInputParticles()
            vol = Volume()
            vol.setFileName(self._getExtraPath('relion_class001.mrc'))
            vol.setSamplingRate(imgSet.getSamplingRate())
            half1 = self._getFileName("final_half1_volume", ref3d=1)
            half2 = self._getFileName("final_half2_volume", ref3d=1)
            vol.setHalfMaps([half1, half2])
            
            outImgSet = self._createSetOfParticles()
            outImgSet.copyInfo(imgSet)
            self._fillDataFromIter(outImgSet, self._lastIter())

            self._defineOutputs(outputVolume=vol)
            self._defineSourceRelation(self.inputParticles, vol)
            self._defineOutputs(outputParticles=outImgSet)
            self._defineTransformRelation(self.inputParticles, outImgSet)

            fsc = FSC(objLabel=self.getRunName())
            blockName = 'model_class_%d@' % 1
            fn = blockName + self._getExtraPath("relion_model.star")
            mData = md.MetaData(fn)
            fsc.loadFromMd(mData,
                           md.RLN_RESOLUTION,
                           md.RLN_MLMODEL_FSC_HALVES_REF)
            self._defineOutputs(outputFSC=fsc)
            self._defineSourceRelation(vol, fsc)

        else:
            movieSet = self.inputMovieParticles.get()
            if self.movieIncludeRotSearch:
                vol = Volume()
                vol.setFileName(self._getExtraPath('relion_class001.mrc'))
                vol.setSamplingRate(movieSet.getSamplingRate())
                half1 = self._getFileName("final_half1_volume", ref3d=1)
                half2 = self._getFileName("final_half2_volume", ref3d=1)
                vol.setHalfMaps([half1, half2])

                self._defineOutputs(outputVolume=vol)
                self._defineSourceRelation(self.inputParticles, vol)
                self._defineSourceRelation(self.inputMovieParticles, vol)

            fnOut = self._getFileName('dataFinal')
            outMovieSet = self._createSetOfMovieParticles()
            outMovieSet.copyInfo(movieSet)
            outMovieSet.setAlignmentProj()
            # not using copyItems since input movie particle
            # set is missing a lot of metadata (CTF, micName etc.)
            # that was created in convertInputStep
            readSetOfParticles(fnOut, outMovieSet, alignType=ALIGN_PROJ,
                               extraLabels=MOVIE_EXTRA_LABELS,
                               postprocessImageRow=self._updateParticle)

            self._defineOutputs(outputParticles=outMovieSet)
            self._defineTransformRelation(self.inputParticles, outMovieSet)
            self._defineTransformRelation(self.inputMovieParticles, outMovieSet)
Beispiel #8
0
 def _getMetadataSqlite(self, fn, clean=False):
     """ Read the classes from Xmipp metadata and write as sqlite file. """
     fnSqlite = fn + '.sqlite'
     if clean:
         cleanPath(fnSqlite)
         
     if not os.path.exists(fnSqlite):
         imagesSet = SetOfParticles(filename=fnSqlite)
         readSetOfParticles(fn+".xmd",imagesSet)
         imagesSet.write()
         imagesSet.close()
     return fnSqlite
Beispiel #9
0
    def createOutputStep(self):
        # Create the SetOfImages object on the database
        #imgSet = XmippSetOfParticles(self._getPath('images.xmd'))

        fnImages = self._getOutputImgMd()
        # Create output SetOfParticles
        imgSet = self._createSetOfParticles()
        imgSet.copyInfo(self.inputMics)
        if self.doFlip:
            # Check if self.inputMics are phase flipped.
            if self.inputMics.isPhaseFlipped():
                imgSet.setIsPhaseFlipped(False)
            else:
                imgSet.setIsPhaseFlipped(True)

        #imgSet.setHasCTF(self.fnCTF is not None)
        if self.downsampleType == OTHER:
            imgSet.setSamplingRate(self.inputMics.getSamplingRate() *
                                   self.downFactor.get())
        imgSet.setCoordinates(self.inputCoords)

        # Create a temporary set to read from the metadata file
        # and later create the good one with the coordinates
        # properly set. We need this because the .update is not
        # working in the mapper when new attributes are added.
        imgSet.setHasCTF(self.ctfRelations.hasValue())
        auxSet = SetOfParticles(filename=':memory:')
        auxSet.copyInfo(imgSet)
        readSetOfParticles(fnImages, auxSet)

        if self.downsampleType != SAME_AS_PICKING:
            factor = self.samplingInput / self.samplingFinal
        # For each particle retrieve micId from SetOFCoordinates and set it on the CTFModel
        for img in auxSet:
            #FIXME: This can be slow to make a query to grab the coord, maybe use zip(imgSet, coordSet)???
            coord = self.inputCoords[img.getObjId()]
            if self.downsampleType != SAME_AS_PICKING:
                x, y = coord.getPosition()
                coord.setPosition(x * factor, y * factor)
            ctfModel = img.getCTF()
            if ctfModel is not None:
                ctfModel.setObjId(coord.getMicId())
                ##img.setCTF(ctfModel)####JM
            img.setMicId(coord.getMicId())
            img.setCoordinate(coord)
            imgSet.append(img)

        self._storeMethodsInfo(fnImages)
        self._defineOutputs(outputParticles=imgSet)
        self._defineSourceRelation(self.inputCoordinates, imgSet)
        if self.ctfRelations.hasValue():
            self._defineSourceRelation(self.ctfRelations.get(), imgSet)
 def createOutputStep(self):
     # Create the SetOfImages object on the database
     #imgSet = XmippSetOfParticles(self._getPath('images.xmd'))
     
     fnImages = self._getOutputImgMd()
     # Create output SetOfParticles
     imgSet = self._createSetOfParticles()
     imgSet.copyInfo(self.inputMics)
     if self.doFlip:
         # Check if self.inputMics are phase flipped.
         if self.inputMics.isPhaseFlipped():
             imgSet.setIsPhaseFlipped(False)
         else:
             imgSet.setIsPhaseFlipped(True)
     
     #imgSet.setHasCTF(self.fnCTF is not None)
     if self.downsampleType == OTHER:
         imgSet.setSamplingRate(self.inputMics.getSamplingRate()*self.downFactor.get())
     imgSet.setCoordinates(self.inputCoords)
     
     # Create a temporary set to read from the metadata file
     # and later create the good one with the coordinates 
     # properly set. We need this because the .update is not
     # working in the mapper when new attributes are added.
     imgSet.setHasCTF(self.ctfRelations.hasValue())
     auxSet = SetOfParticles(filename=':memory:')
     auxSet.copyInfo(imgSet)
     readSetOfParticles(fnImages, auxSet)
     
     if self.downsampleType != SAME_AS_PICKING:
         factor = self.samplingInput / self.samplingFinal
     # For each particle retrieve micId from SetOFCoordinates and set it on the CTFModel
     for img in auxSet:
         #FIXME: This can be slow to make a query to grab the coord, maybe use zip(imgSet, coordSet)???
         coord = self.inputCoords[img.getObjId()]
         if self.downsampleType != SAME_AS_PICKING:
             x, y = coord.getPosition()
             coord.setPosition(x*factor, y*factor)           
         ctfModel = img.getCTF()
         if ctfModel is not None:
             ctfModel.setObjId(coord.getMicId())
             ##img.setCTF(ctfModel)####JM
         img.setMicId(coord.getMicId())
         img.setCoordinate(coord)
         imgSet.append(img)
         
     self._storeMethodsInfo(fnImages)
     self._defineOutputs(outputParticles=imgSet)
     self._defineSourceRelation(self.inputCoordinates, imgSet)
     if self.ctfRelations.hasValue():
         self._defineSourceRelation(self.ctfRelations.get(), imgSet)
Beispiel #11
0
 def _getIterData(self, it, **kwargs):
     from convert import readSetOfParticles
     
     imgSqlite = self.protocol._getFileName('data_scipion', iter=it)
     
     if not exists(imgSqlite):
         imgPar = self.protocol._getFileName('output_par', iter=it)
         
         cleanPath(imgSqlite)
         imgSet = em.SetOfParticles(filename=imgSqlite)
         readSetOfParticles(self.protocol.inputParticles.get(), imgSet, imgPar)
         imgSet.write()
         
     return imgSqlite
Beispiel #12
0
    def createOutputStep(self):
        imgSet = self.inputParticles.get()
        partSet = self._createSetOfParticles()
        partSet.copyInfo(imgSet)
        outImagesMd = self._getExtraPath('expanded_particles.star')

        mdOut = md.MetaData(outImagesMd)
        mdOut.removeLabel(md.RLN_IMAGE_ID)  # remove repeating rlnImageId in mdOut
        mdOut.write(outImagesMd, md.MD_OVERWRITE)

        readSetOfParticles(outImagesMd, partSet, alignType=ALIGN_PROJ,
                           postprocessImageRow=self._postprocessImageRow)

        self._defineOutputs(outputParticles=partSet)
        self._defineSourceRelation(imgSet, partSet)
Beispiel #13
0
    def createOutputStep(self):
        imgSet = self._getInputParticles()
        vol = Volume()
        vol.setFileName(self._getFileName('volume_shiny'))
        vol.setSamplingRate(imgSet.getSamplingRate())
        shinyPartSet = self._createSetOfParticles()
        shinyPartSet.copyInfo(imgSet)
        shinyPartSet.setAlignmentProj()
        readSetOfParticles(self._getFileName('shiny'), shinyPartSet,
                           alignType=ALIGN_PROJ)

        self._defineOutputs(outputParticles=shinyPartSet)
        self._defineOutputs(outputVolume=vol)
        
        self._defineSourceRelation(imgSet, shinyPartSet)
        self._defineSourceRelation(imgSet, vol)
Beispiel #14
0
    def createOutputStep(self):
        imgSet = self._getInputParticles()
        vol = Volume()
        vol.setFileName(self._getFileName('volume_shiny'))
        vol.setSamplingRate(imgSet.getSamplingRate())
        shinyPartSet = self._createSetOfParticles()
        shinyPartSet.copyInfo(imgSet)
        shinyPartSet.setAlignmentProj()
        readSetOfParticles(self._getFileName('shiny'),
                           shinyPartSet,
                           alignType=ALIGN_PROJ)

        self._defineOutputs(outputParticles=shinyPartSet)
        self._defineOutputs(outputVolume=vol)

        self._defineSourceRelation(imgSet, shinyPartSet)
        self._defineSourceRelation(imgSet, vol)
 def createOutputStep(self):
     """ Store the setOfParticles object 
     as result of the protocol. 
     """
     particles = self.inputParticles.get()
     # Define the output average
     avgFile = self._getExtraPath('level_00', 'class_classes.stk')
     avg = Particle()
     avg.setLocation(1, avgFile)
     avg.copyInfo(particles)
     self._defineOutputs(outputAverage=avg)
     self._defineSourceRelation(particles, avg)
         
     # Generate the Set of Particles with alignment
     alignedSet = self._createSetOfParticles()
     alignedSet.copyInfo(particles)
     alignedSet.setRepresentative(avg)
     readSetOfParticles(self.imgsFn, alignedSet)
     self._defineOutputs(outputParticles=alignedSet)
     self._defineSourceRelation(particles, alignedSet)
    def createOutputStep(self):
        lastIter = self._getLastIter()
        inputSet = self._getInputParticles()

        # Register output volume
        volFn = self._getFileName('iter_vol', iter=lastIter)
        vol = em.Volume()
        vol.setFileName(volFn)
        vol.setSamplingRate(inputSet.getSamplingRate())
        self._defineOutputs(outputVolume=vol)
        self._defineSourceRelation(self.inputParticles, vol)

        # Register output Particles with their 3D alignment
        file2 = self._getFileName('output_par', iter=lastIter)
        partSet = self._createSetOfParticles()
        partSet.copyInfo(inputSet)
        readSetOfParticles(inputSet, partSet, file2)
        self._defineOutputs(outputParticles=partSet)
        self._defineTransformRelation(self._getInputParticlesPointer(), partSet)
        
        if not self.doContinue:
            self._defineSourceRelation(self.input3DReference, vol)
            self._defineSourceRelation(self.input3DReference, partSet)
Beispiel #17
0
    def createOutputStep(self):
        # Create the SetOfImages objects on the database and the ImagesTiltPair

        mdUntilted = xmipp.MetaData()
        mdTilted = xmipp.MetaData()
        #for objId in mdPairs:
        for uMic, tMic in izip(self.uMics, self.tMics):
            umicName = removeBaseExt(uMic.getFileName())
            fnMicU = self._getExtraPath(umicName + ".xmd")
            fnPosU = self._getExtraPath(umicName + ".pos")
            # Check if there are picked particles in this micrographs
            if exists(fnMicU):
                mdMicU = xmipp.MetaData(fnMicU)
                mdPosU = xmipp.MetaData('particles@%s' % fnPosU)
                mdPosU.merge(mdMicU)
                mdUntilted.unionAll(mdPosU)
                tmicName = removeBaseExt(tMic.getFileName())
                fnMicT = self._getExtraPath(tmicName + ".xmd")
                fnPosT = self._getExtraPath(tmicName + ".pos")
                mdMicT = xmipp.MetaData(fnMicT)
                mdPosT = xmipp.MetaData('particles@%s' % fnPosT)
                mdPosT.merge(mdMicT)
                mdTilted.unionAll(mdPosT)

        # Write image metadatas (check if it is really necessary)
        fnTilted = self._getExtraPath("images_tilted.xmd")
        fnUntilted = self._getExtraPath("images_untilted.xmd")
        mdUntilted.write(fnUntilted)
        mdTilted.write(fnTilted)

        # Create outputs SetOfParticles both for tilted and untilted
        imgSetU = self._createSetOfParticles(suffix="Untilted")
        imgSetU.copyInfo(self.uMics)

        imgSetT = self._createSetOfParticles(suffix="Tilted")
        imgSetT.copyInfo(self.tMics)

        if self.downsampleType == OTHER:
            imgSetU.setSamplingRate(self.samplingFinal)
            imgSetT.setSamplingRate(self.samplingFinal)

        imgSetU.setCoordinates(self.inputCoordinatesTiltedPairs.get().getUntilted())
        imgSetT.setCoordinates(self.inputCoordinatesTiltedPairs.get().getTilted())

        #Read untilted and tilted particles on a temporary object (also disabled particles)
        imgSetAuxU = self._createSetOfParticles('auxU')
        imgSetAuxU.copyInfo(imgSetU)
        readSetOfParticles(fnUntilted, imgSetAuxU, removeDisabled=False)
        imgSetAuxU.write()

        imgSetAuxT = self._createSetOfParticles('auxT')
        imgSetAuxT.copyInfo(imgSetT)
        readSetOfParticles(fnTilted, imgSetAuxT, removeDisabled=False)
        imgSetAuxT.write()

        coordsT = self.inputCoordinatesTiltedPairs.get().getTilted()
        # For each untilted particle retrieve micId from SetOFCoordinates untilted
        for imgU, coordU in izip(imgSetAuxU, self.inputCoordinatesTiltedPairs.get().getUntilted()):
            #FIXME: REmove this check when sure that objIds are equal
            id = imgU.getObjId()
            if id != coordU.getObjId():
                raise Exception('ObjId in untilted is not equal!!!!')

            imgT = imgSetAuxT[id]
            coordT = coordsT[id]

            #If both particles are enabled append them
            if imgU.isEnabled() and imgT.isEnabled():
                imgU.setCoordinate(coordU)
                imgSetU.append(imgU)
                imgT.setCoordinate(coordT)
                imgSetT.append(imgT)

        # For each untilted particle retrieve micId from SetOFCoordinates tilted
        #for img in imgSetAuxU:
        # for img, coord in izip(imgSetAuxT, self.inputCoordinatesTiltedPairs.get().getTilted()):
        #     #FIXME: This can be slow to make a query to grab the coord, maybe use zip(imgSet, coordSet)???
        #     #FIXME: REmove this check when sure that objIds are equal
        #     if img.getObjId() != coord.getObjId():
        #         raise Exception('ObjId is not equal!!!!')
        #     #coord = self.inputCoordinatesTiltedPairs.get().getTilted()[img.getObjId()]
        #     img.setCoordinate(coord)
        #     #img.cleanObjId()
        #     imgSetT.append(img)

        imgSetU.write()
        imgSetT.write()

        self._storeMethodsInfo(fnUntilted)

        # Define output ParticlesTiltPair 
        outputset = ParticlesTiltPair(filename=self._getPath('particles_pairs.sqlite'))
        outputset.setTilted(imgSetT)
        outputset.setUntilted(imgSetU)
        for imgU, imgT in izip(imgSetU, imgSetT):
            outputset.append(TiltPair(imgU, imgT))

        outputset.setCoordsPair(self.inputCoordinatesTiltedPairs.get())
        self._defineOutputs(outputParticlesTiltPair=outputset)
        self._defineSourceRelation(self.inputCoordinatesTiltedPairs, outputset)
    def createOutputStep(self):
        imgSet = self._createSetOfParticles()
        imgSet.copyInfo(self.inputParticles.get())
        readSetOfParticles(self.outputMd.get(), imgSet)

        self._defineOutputs(outputParticles=imgSet)
    def createOutputStep(self):
        # Create the SetOfImages object on the database
        #imgSet = XmippSetOfParticles(self._getPath('images.xmd'))
                  
        #Create images.xmd metadata
        fnImages = self._getPath('images.xmd')
        imgsXmd = xmipp.MetaData() 
        posFiles = glob(self._getExtraPath('*.pos')) 
        for posFn in posFiles:
            xmdFn = self._getExtraPath(replaceBaseExt(posFn, "xmd"))
            if exists(xmdFn):
                md = xmipp.MetaData(xmdFn)
                mdPos = xmipp.MetaData('particles@%s' % posFn)
                mdPos.merge(md) 
                #imgSet.appendFromMd(mdPos)
                imgsXmd.unionAll(mdPos)
            else:
                self.warning("The coord file %s wasn't used to extract! Maybe you are extracting over a subset of micrographs" % basename(posFn))
        imgsXmd.write(fnImages)

        # IF selected run xmipp_image_sort_by_statistics to add zscore info to images.xmd
        if self.doSort:
            args="-i %(fnImages)s --addToInput"
            if self.rejectionMethod == REJECT_MAXZSCORE:
                maxZscore = self.maxZscore.get()
                args += " --zcut " + str(maxZscore)
            elif self.rejectionMethod == REJECT_PERCENTAGE:
                percentage = self.percentage.get()
                args += " --percent " + str(percentage)

            self.runJob("xmipp_image_sort_by_statistics", args % locals())
        # Create output SetOfParticles
        imgSet = self._createSetOfParticles()
        imgSet.copyInfo(self.inputMics)
        if self.doFlip:
            # Check if self.inputMics are phase flipped.
            if self.inputMics.isPhaseFlipped():
                imgSet.setIsPhaseFlipped(False)
            else:
                imgSet.setIsPhaseFlipped(True)
        
        #imgSet.setHasCTF(self.fnCTF is not None)
        if self.downsampleType == OTHER:
            imgSet.setSamplingRate(self.inputMics.getSamplingRate()*self.downFactor.get())
        imgSet.setCoordinates(self.inputCoords)
        
        # Create a temporary set to read from the metadata file
        # and later create the good one with the coordinates 
        # properly set. We need this because the .update is not
        # working in the mapper when new attributes are added.
        imgSet.setHasCTF(self.ctfRelations.hasValue())
        auxSet = SetOfParticles(filename=':memory:')
        auxSet.copyInfo(imgSet)
        readSetOfParticles(fnImages, auxSet)
        # For each particle retrieve micId from SetOFCoordinates and set it on the CTFModel
        for img in auxSet:
            #FIXME: This can be slow to make a query to grab the coord, maybe use zip(imgSet, coordSet)???
            coord = self.inputCoords[img.getObjId()]
            ctfModel = img.getCTF()
            if ctfModel is not None:
                ctfModel.setObjId(coord.getMicId())
                ##img.setCTF(ctfModel)####JM
            img.setMicId(coord.getMicId())
            img.setCoordinate(coord)
            imgSet.append(img)
            
        self._storeMethodsInfo(fnImages)
        self._defineOutputs(outputParticles=imgSet)
        self._defineSourceRelation(self.inputCoords, imgSet)
Beispiel #20
0
    def createOutputStep(self):
        fnTilted = self._getExtraPath("images_tilted.xmd")
        fnUntilted = self._getExtraPath("images_untilted.xmd")

        # Create outputs SetOfParticles both for tilted and untilted
        imgSetU = self._createSetOfParticles(suffix="Untilted")
        imgSetU.copyInfo(self.uMics)
        imgSetT = self._createSetOfParticles(suffix="Tilted")
        imgSetT.copyInfo(self.tMics)

        sampling = self.samplingMics if self._micsOther(
        ) else self.samplingInput
        if self._doDownsample():
            sampling *= self.downFactor.get()
        imgSetU.setSamplingRate(sampling)
        imgSetT.setSamplingRate(sampling)

        # set coords from the input, will update later if needed
        imgSetU.setCoordinates(
            self.inputCoordinatesTiltedPairs.get().getUntilted())
        imgSetT.setCoordinates(
            self.inputCoordinatesTiltedPairs.get().getTilted())

        # Read untilted and tilted particles on a temporary object (also disabled particles)
        imgSetAuxU = SetOfParticles(filename=':memory:')
        imgSetAuxU.copyInfo(imgSetU)
        readSetOfParticles(fnUntilted, imgSetAuxU, removeDisabled=False)

        imgSetAuxT = SetOfParticles(filename=':memory:')
        imgSetAuxT.copyInfo(imgSetT)
        readSetOfParticles(fnTilted, imgSetAuxT, removeDisabled=False)

        # calculate factor for coords scaling
        factor = 1 / self.samplingFactor
        if self._doDownsample():
            factor /= self.downFactor.get()

        coordsT = self.inputCoordinatesTiltedPairs.get().getTilted()
        # For each untilted particle retrieve micId from SetOfCoordinates untilted
        for imgU, coordU in izip(
                imgSetAuxU,
                self.inputCoordinatesTiltedPairs.get().getUntilted()):
            # FIXME: Remove this check when sure that objIds are equal
            id = imgU.getObjId()
            if id != coordU.getObjId():
                raise Exception(
                    'ObjIds in untilted img and coord are not the same!!!!')
            imgT = imgSetAuxT[id]
            coordT = coordsT[id]

            # If both particles are enabled append them
            if imgU.isEnabled() and imgT.isEnabled():
                if self._micsOther() or self._doDownsample():
                    coordU.scale(factor)
                    coordT.scale(factor)
                imgU.setCoordinate(coordU)
                imgSetU.append(imgU)
                imgT.setCoordinate(coordT)
                imgSetT.append(imgT)

        imgSetU.write()
        imgSetT.write()

        # Define output ParticlesTiltPair
        outputset = ParticlesTiltPair(
            filename=self._getPath('particles_pairs.sqlite'))
        outputset.setTilted(imgSetT)
        outputset.setUntilted(imgSetU)
        for imgU, imgT in izip(imgSetU, imgSetT):
            outputset.append(TiltPair(imgU, imgT))

        outputset.setCoordsPair(self.inputCoordinatesTiltedPairs.get())
        self._defineOutputs(outputParticlesTiltPair=outputset)
        self._defineSourceRelation(self.inputCoordinatesTiltedPairs, outputset)
    def createOutputStep(self):
        fnTilted = self._getExtraPath("images_tilted.xmd")
        fnUntilted = self._getExtraPath("images_untilted.xmd")

        # Create outputs SetOfParticles both for tilted and untilted
        imgSetU = self._createSetOfParticles(suffix="Untilted")
        imgSetU.copyInfo(self.uMics)
        imgSetT = self._createSetOfParticles(suffix="Tilted")
        imgSetT.copyInfo(self.tMics)

        sampling = self.samplingMics if self._micsOther() else self.samplingInput
        if self._doDownsample():
            sampling *= self.downFactor.get()
        imgSetU.setSamplingRate(sampling)
        imgSetT.setSamplingRate(sampling)

        # set coords from the input, will update later if needed
        imgSetU.setCoordinates(self.inputCoordinatesTiltedPairs.get().getUntilted())
        imgSetT.setCoordinates(self.inputCoordinatesTiltedPairs.get().getTilted())

        # Read untilted and tilted particles on a temporary object (also disabled particles)
        imgSetAuxU = SetOfParticles(filename=':memory:')
        imgSetAuxU.copyInfo(imgSetU)
        readSetOfParticles(fnUntilted, imgSetAuxU, removeDisabled=False)

        imgSetAuxT = SetOfParticles(filename=':memory:')
        imgSetAuxT.copyInfo(imgSetT)
        readSetOfParticles(fnTilted, imgSetAuxT, removeDisabled=False)

        # calculate factor for coords scaling
        factor = 1 / self.samplingFactor
        if self._doDownsample():
            factor /= self.downFactor.get()

        coordsT = self.inputCoordinatesTiltedPairs.get().getTilted()
        # For each untilted particle retrieve micId from SetOfCoordinates untilted
        for imgU, coordU in izip(imgSetAuxU, self.inputCoordinatesTiltedPairs.get().getUntilted()):
            # FIXME: Remove this check when sure that objIds are equal
            id = imgU.getObjId()
            if id != coordU.getObjId():
                raise Exception('ObjIds in untilted img and coord are not the same!!!!')
            imgT = imgSetAuxT[id]
            coordT = coordsT[id]

            # If both particles are enabled append them
            if imgU.isEnabled() and imgT.isEnabled():
                if self._micsOther() or self._doDownsample():
                    coordU.scale(factor)
                    coordT.scale(factor)
                imgU.setCoordinate(coordU)
                imgSetU.append(imgU)
                imgT.setCoordinate(coordT)
                imgSetT.append(imgT)

        imgSetU.write()
        imgSetT.write()

        # Define output ParticlesTiltPair
        outputset = ParticlesTiltPair(filename=self._getPath('particles_pairs.sqlite'))
        outputset.setTilted(imgSetT)
        outputset.setUntilted(imgSetU)
        for imgU, imgT in izip(imgSetU, imgSetT):
            outputset.append(TiltPair(imgU, imgT))

        outputset.setCoordsPair(self.inputCoordinatesTiltedPairs.get())
        self._defineOutputs(outputParticlesTiltPair=outputset)
        self._defineSourceRelation(self.inputCoordinatesTiltedPairs, outputset)
    def createOutputStep(self):
        # Create the SetOfImages objects on the database and the ImagesTiltPair

        mdUntilted = xmipp.MetaData()
        mdTilted = xmipp.MetaData()
        #for objId in mdPairs:
        for uMic, tMic in izip(self.uMics, self.tMics):
            umicName = removeBaseExt(uMic.getFileName())
            fnMicU = self._getExtraPath(umicName + ".xmd")
            fnPosU = self._getExtraPath(umicName + ".pos")
            # Check if there are picked particles in this micrographs
            if exists(fnMicU):
                mdMicU = xmipp.MetaData(fnMicU)
                mdPosU = xmipp.MetaData('particles@%s' % fnPosU)
                mdPosU.merge(mdMicU)
                mdUntilted.unionAll(mdPosU)
                tmicName = removeBaseExt(tMic.getFileName())
                fnMicT = self._getExtraPath(tmicName + ".xmd")
                fnPosT = self._getExtraPath(tmicName + ".pos")
                mdMicT = xmipp.MetaData(fnMicT)
                mdPosT = xmipp.MetaData('particles@%s' % fnPosT)
                mdPosT.merge(mdMicT)
                mdTilted.unionAll(mdPosT)

        # Write image metadatas (check if it is really necessary)
        fnTilted = self._getExtraPath("images_tilted.xmd")
        fnUntilted = self._getExtraPath("images_untilted.xmd")
        mdUntilted.write(fnUntilted)
        mdTilted.write(fnTilted)

        # Create outputs SetOfParticles both for tilted and untilted
        imgSetU = self._createSetOfParticles(suffix="Untilted")
        imgSetU.copyInfo(self.uMics)

        imgSetT = self._createSetOfParticles(suffix="Tilted")
        imgSetT.copyInfo(self.tMics)

        if self.downsampleType == OTHER:
            imgSetU.setSamplingRate(self.samplingFinal)
            imgSetT.setSamplingRate(self.samplingFinal)

        imgSetU.setCoordinates(self.inputCoordinatesTiltedPairs.get().getUntilted())
        imgSetT.setCoordinates(self.inputCoordinatesTiltedPairs.get().getTilted())

        #Read untilted and tilted particles on a temporary object (also disabled particles)
        imgSetAuxU = self._createSetOfParticles('auxU')
        imgSetAuxU.copyInfo(imgSetU)
        readSetOfParticles(fnUntilted, imgSetAuxU, removeDisabled=False)
        imgSetAuxU.write()

        imgSetAuxT = self._createSetOfParticles('auxT')
        imgSetAuxT.copyInfo(imgSetT)
        readSetOfParticles(fnTilted, imgSetAuxT, removeDisabled=False)
        imgSetAuxT.write()

        coordsT = self.inputCoordinatesTiltedPairs.get().getTilted()
        # For each untilted particle retrieve micId from SetOFCoordinates untilted
        for imgU, coordU in izip(imgSetAuxU, self.inputCoordinatesTiltedPairs.get().getUntilted()):
            #FIXME: REmove this check when sure that objIds are equal
            id = imgU.getObjId()
            if id != coordU.getObjId():
                raise Exception('ObjId in untilted is not equal!!!!')

            imgT = imgSetAuxT[id]
            coordT = coordsT[id]

            #If both particles are enabled append them
            if imgU.isEnabled() and imgT.isEnabled():
                imgU.setCoordinate(coordU)
                imgSetU.append(imgU)
                imgT.setCoordinate(coordT)
                imgSetT.append(imgT)

        # For each untilted particle retrieve micId from SetOFCoordinates tilted
        #for img in imgSetAuxU:
        # for img, coord in izip(imgSetAuxT, self.inputCoordinatesTiltedPairs.get().getTilted()):
        #     #FIXME: This can be slow to make a query to grab the coord, maybe use zip(imgSet, coordSet)???
        #     #FIXME: REmove this check when sure that objIds are equal
        #     if img.getObjId() != coord.getObjId():
        #         raise Exception('ObjId is not equal!!!!')
        #     #coord = self.inputCoordinatesTiltedPairs.get().getTilted()[img.getObjId()]
        #     img.setCoordinate(coord)
        #     #img.cleanObjId()
        #     imgSetT.append(img)

        imgSetU.write()
        imgSetT.write()

        self._storeMethodsInfo(fnUntilted)

        # Define output ParticlesTiltPair 
        outputset = ParticlesTiltPair(filename=self._getPath('particles_pairs.sqlite'))
        outputset.setTilted(imgSetT)
        outputset.setUntilted(imgSetU)
        for imgU, imgT in izip(imgSetU, imgSetT):
            outputset.append(TiltPair(imgU, imgT))

        outputset.setCoordsPair(self.inputCoordinatesTiltedPairs.get())
        self._defineOutputs(outputParticlesTiltPair=outputset)
        self._defineSourceRelation(self.inputCoordinatesTiltedPairs, outputset)