示例#1
0
def getTomoSetFromStar(prot, starFile):
    samplingRate = prot.pixelSize.get()
    imgh = ImageHandler()
    tomoTable = Table()
    tomoTable.read(starFile)
    tomoList = [row.get(TOMO_NAME, FILE_NOT_FOUND) for row in tomoTable]
    prot.tomoList = List(tomoList)
    tomoNamesUnique = list(set(tomoList))

    # Create a Volume template object
    tomo = Tomogram()
    tomo.setSamplingRate(samplingRate)
    for fileName in tomoNamesUnique:
        x, y, z, n = imgh.getDimensions(fileName)
        if fileName.endswith('.mrc') or fileName.endswith('.map'):
            if z == 1 and n != 1:
                zDim = n
                n = 1
            else:
                zDim = z
        else:
            zDim = z
        origin = Transform()
        origin.setShifts(x / -2. * samplingRate,
                         y / -2. * samplingRate,
                         zDim / -2. * samplingRate)

        tomo.setOrigin(origin)  # read origin from form

        for index in range(1, n + 1):
            tomo.cleanObjId()
            tomo.setLocation(index, fileName)
            tomo.setAcquisition(TomoAcquisition(**prot.acquisitionParams))
            prot.tomoSet.append(tomo)
示例#2
0
def _relionTomoStar2Subtomograms(prot, outputSubTomogramsSet, tomoTable, invert):
    ih = ImageHandler()
    samplingRate = outputSubTomogramsSet.getSamplingRate()
    for row, inSubtomo in zip(tomoTable, prot.inputSubtomos.get()):
        subtomo = SubTomogram()
        coordinate3d = Coordinate3D()
        transform = Transform()
        origin = Transform()

        volname = row.get(TOMO_NAME, FILE_NOT_FOUND)
        subtomoFn = row.get(SUBTOMO_NAME, FILE_NOT_FOUND)

        subtomo.setVolName(managePath4Sqlite(volname))
        subtomo.setTransform(transform)
        subtomo.setAcquisition(TomoAcquisition())
        subtomo.setClassId(row.get('rlnClassNumber', 0))
        subtomo.setSamplingRate(samplingRate)
        subtomo.setCoordinate3D(coordinate3d)  # Needed to get later the tomogram pointer via getCoordinate3D()

        x = row.get(COORD_X, 0)
        y = row.get(COORD_Y, 0)
        z = row.get(COORD_Z, 0)
        tiltPrior = row.get(TILT_PRIOR, 0)
        psiPrior = row.get(PSI_PRIOR, 0)
        # ctf3d = row.get(CTF_MISSING_WEDGE, FILE_NOT_FOUND)
        coordinate3d = subtomo.getCoordinate3D()
        coordinate3d.setX(float(x), BOTTOM_LEFT_CORNER)
        coordinate3d.setY(float(y), BOTTOM_LEFT_CORNER)
        coordinate3d.setZ(float(z), BOTTOM_LEFT_CORNER)
        coordinate3d._3dcftMrcFile = inSubtomo.getCoordinate3D()._3dcftMrcFile  # Used for the ctf3d in Relion 3.0 (tomo)
        M = _getTransformMatrix(row, invert)
        transform.setMatrix(M)
        subtomo.setCoordinate3D(coordinate3d)
        subtomo._tiltPriorAngle = Float(tiltPrior)
        subtomo._psiPriorAngle = Float(psiPrior)

        # Set the origin and the dimensions of the current subtomogram
        x, y, z, n = ih.getDimensions(subtomoFn)
        zDim, _ = manageIhDims(subtomoFn, z, n)
        origin.setShifts(x / -2. * samplingRate, y / -2. * samplingRate, zDim / -2. * samplingRate)
        subtomo.setOrigin(origin)

        subtomo.setFileName(managePath4Sqlite(subtomoFn))
        # if subtomo is in a vesicle
        if 'tid_' in subtomoFn:
            vesicleId = subtomoFn.split('tid_')[1]
            vesicleId = vesicleId[0]
            scoor = subtomo.getCoordinate3D()
            scoor.setGroupId(vesicleId)
            subtomo.setCoordinate3D(scoor)

        # Add current subtomogram to the output set
        outputSubTomogramsSet.append(subtomo)
示例#3
0
    def importVolumesStep(self, pattern, samplingRate, setOrigCoord=False):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        volSet = self._createSetOfVolumes()
        vol = emobj.Volume()

        if self.importFrom == self.IMPORT_FROM_FILES:
            self.info("Using pattern: '%s'" % pattern)

            # Create a Volume template object
            vol.setSamplingRate(samplingRate)

            imgh = emlib.image.ImageHandler()

            volSet.setSamplingRate(samplingRate)

            for fileName, fileId in self.iterFiles():
                x, y, z, n = imgh.getDimensions(fileName)
                if fileName.endswith('.mrc') or fileName.endswith('.map'):
                    fileName += ':mrc'
                    if z == 1 and n != 1:
                        zDim = n
                        n = 1
                    else:
                        zDim = z
                else:
                    zDim = z
                origin = emobj.Transform()
                if setOrigCoord:
                    origin.setShiftsTuple(self._getOrigCoord())
                else:
                    origin.setShifts(x / -2. * samplingRate,
                                     y / -2. * samplingRate,
                                     zDim / -2. * samplingRate)

                vol.setOrigin(origin)  # read origin from form

                if self.copyFiles or setOrigCoord:
                    newFileName = abspath(
                        self._getVolumeFileName(fileName, "mrc"))
                    emconv.Ccp4Header.fixFile(fileName, newFileName,
                                              origin.getShifts(), samplingRate,
                                              emconv.Ccp4Header.ORIGIN)
                    if self.setHalfMaps.get():
                        newFileName1 = abspath(
                            self._getVolumeFileName(self.half1map.get(),
                                                    "mrc"))
                        emconv.Ccp4Header.fixFile(self.half1map.get(),
                                                  newFileName1,
                                                  origin.getShifts(),
                                                  samplingRate,
                                                  emconv.Ccp4Header.ORIGIN)
                        newFileName2 = abspath(
                            self._getVolumeFileName(self.half2map.get(),
                                                    "mrc"))
                        emconv.Ccp4Header.fixFile(self.half2map.get(),
                                                  newFileName2,
                                                  origin.getShifts(),
                                                  samplingRate,
                                                  emconv.Ccp4Header.ORIGIN)

                        vol.setHalfMaps(
                            [relpath(newFileName1),
                             relpath(newFileName2)])
                else:
                    newFileName = abspath(self._getVolumeFileName(fileName))

                    if fileName.endswith(':mrc'):
                        fileName = fileName[:-4]

                    pwutils.createAbsLink(fileName, newFileName)
                    if self.setHalfMaps.get():
                        pwutils.createAbsLink(
                            self.half1map.get(),
                            abspath(
                                self._getVolumeFileName(self.half1map.get())))
                        pwutils.createAbsLink(
                            self.half2map.get(),
                            abspath(
                                self._getVolumeFileName(self.half2map.get())))

                        vol.setHalfMaps([
                            relpath(
                                self._getVolumeFileName(self.half1map.get())),
                            relpath(
                                self._getVolumeFileName(self.half2map.get()))
                        ])

                # Make newFileName relative
                # https://github.com/I2PC/scipion/issues/1935
                newFileName = relpath(newFileName)
                if n == 1:
                    vol.cleanObjId()
                    vol.setFileName(newFileName)
                    volSet.append(vol)
                else:
                    for index in range(1, n + 1):
                        vol.cleanObjId()
                        vol.setLocation(index, newFileName)
                        volSet.append(vol)
        else:  # import from EMDB
            self.info("Downloading map with ID = %s" % self.emdbId)
            try:
                localFileName, sampling, origin = \
                    fetch_emdb_map(self.emdbId,
                                   self._getExtraPath(),
                                   self._getTmpPath())
            except Exception as e:
                print(e)
                return
            # open volume and fill sampling and origin
            vol.setSamplingRate(sampling)
            vol.setFileName(localFileName)
            from pwem.objects.data import Transform
            originMat = Transform()
            originMat.setShifts(origin[0], origin[1], origin[2])
            vol.setOrigin(originMat)

        if volSet.getSize() > 1:
            self._defineOutputs(outputVolumes=volSet)
        else:
            self._defineOutputs(outputVolume=vol)