Пример #1
0
    def _createSubSetFromMicrographsTiltPair(self, micrographsTiltPair):
        """ Create a subset of Micrographs Tilt Pair. """
        output = MicrographsTiltPair(filename=self._getPath('micrographs_pairs.sqlite'))
        print "self._dbName=%s" % self._dbName
        modifiedSet = MicrographsTiltPair(filename=self._dbName, prefix=self._dbPrefix)
        inputU = micrographsTiltPair.getUntilted()
        inputT = micrographsTiltPair.getTilted()
        outputU = SetOfMicrographs(filename=self._getPath('mics_untilted.sqlite'))
        outputT = SetOfParticles(filename=self._getPath('mics_tilted.sqlite'))
        outputU.copyInfo(inputU)
        outputT.copyInfo(inputT)
        for micPairI in modifiedSet:
            untilted = micPairI.getUntilted()
            tilted = micPairI.getTilted()
            if micPairI.isEnabled():

                micPairO = TiltPair()
                micPairO.setUntilted(untilted)
                micPairO.setTilted(tilted)
                output.append(micPairO)
                outputU.append(untilted)
                outputT.append(tilted)
        output.setUntilted(outputU)
        output.setTilted(outputT)
        # Register outputs
        outputDict = {'outputMicrographsTiltPair': output}
        self._defineOutputs(**outputDict)
        self._defineTransformRelation(micrographsTiltPair, output)
        return output
Пример #2
0
    def _createSubSetFromMicrographsTiltPair(self, micrographsTiltPair):
        """ Create a subset of Micrographs Tilt Pair. """
        output = MicrographsTiltPair(filename=self._getPath('micrographs_pairs.sqlite'))
        print "self._dbName=%s" % self._dbName
        modifiedSet = MicrographsTiltPair(filename=self._dbName, prefix=self._dbPrefix)

        for micPairI in modifiedSet:
            untilted = micPairI.getUntilted()
            tilted = micPairI.getTilted()
            if micPairI.isEnabled():

                micPairO = TiltPair()
                micPairO.setUntilted(untilted)
                micPairO.setTilted(tilted)
                output.append(micPairO)
        # Register outputs
        outputDict = {'outputMicrographsTiltPair': output}
        self._defineOutputs(**outputDict)
        return output
Пример #3
0
    def _createSubSetFromMicrographsTiltPair(self, micrographsTiltPair):
        """ Create a subset of Micrographs Tilt Pair. """
        output = MicrographsTiltPair(
            filename=self._getPath('micrographs_pairs.sqlite'))
        modifiedSet = MicrographsTiltPair(filename=self._dbName,
                                          prefix=self._dbPrefix)
        inputU = micrographsTiltPair.getUntilted()
        inputT = micrographsTiltPair.getTilted()
        outputU = SetOfMicrographs(
            filename=self._getPath('mics_untilted.sqlite'))
        outputT = SetOfParticles(filename=self._getPath('mics_tilted.sqlite'))
        outputU.copyInfo(inputU)
        outputT.copyInfo(inputT)

        for micPairI in modifiedSet:
            untilted = micPairI.getUntilted()
            tilted = micPairI.getTilted()

            if micPairI.isEnabled():
                micPairO = TiltPair()
                micPairO.setUntilted(untilted)
                micPairO.setTilted(tilted)
                output.append(micPairO)
                outputU.append(untilted)
                outputT.append(tilted)
        output.setUntilted(outputU)
        output.setTilted(outputT)
        # Register outputs
        outputDict = {'outputMicrographsTiltPair': output}
        self._defineOutputs(**outputDict)
        self._defineTransformRelation(micrographsTiltPair, output)
        return output
Пример #4
0
    def _createCoordinatesTiltPair(self, micTiltPairs, uCoords, tCoords,
                                   angles, suffix):
        coordTiltPairs = self.__createSet(CoordinatesTiltPair,
                                          'coordinates_pairs%s.sqlite', suffix)
        coordTiltPairs.setUntilted(uCoords)
        coordTiltPairs.setTilted(tCoords)
        coordTiltPairs.setAngles(angles)
        coordTiltPairs.setMicsPair(micTiltPairs)

        for coordU, coordT in izip(uCoords, tCoords):
            coordTiltPairs.append(TiltPair(coordU, coordT))

        return coordTiltPairs
Пример #5
0
    def createTiltedPairsStep(self):
        args = {}
        self.micsPairsSqlite = self._getPath('micrographs_pairs.sqlite')
        cleanPath(self.micsPairsSqlite)  # Delete if exists

        micsTiltPair = MicrographsTiltPair(filename=self.micsPairsSqlite)
        micsU = self.importMicrographs(self.patternUntilted.get(), 'Untilted',
                                       self.voltage.get(),
                                       self.sphericalAberration.get(),
                                       self.ampContrast.get())
        micsT = self.importMicrographs(self.patternTilted.get(), 'Tilted',
                                       self.voltage.get(),
                                       self.sphericalAberration.get(),
                                       self.ampContrast.get())

        micsTiltPair.setUntilted(micsU)
        micsTiltPair.setTilted(micsT)

        for micU, micT in izip(micsU, micsT):
            micsTiltPair.append(TiltPair(micU, micT))

        args[self.OUTPUT_NAME] = micsTiltPair
        self._defineOutputs(**args)
Пример #6
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.getMicSampling() if self._micsOther(
        ) else self.getCoordSampling()
        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.getCoords().getTilted()
        # For each untilted particle retrieve micId from SetOfCoordinates untilted
        for imgU, coordU in izip(imgSetAuxU, self.getCoords().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)

        if self.doFlip:
            imgSetU.setIsPhaseFlipped(self.ctfUntilt.hasValue())
            imgSetU.setHasCTF(self.ctfUntilt.hasValue())
            imgSetT.setIsPhaseFlipped(self.ctfTilt.hasValue())
            imgSetT.setHasCTF(self.ctfTilt.hasValue())
        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)
Пример #7
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)