def convertInputStep(self): self._ih = em.ImageHandler() # used to convert micrographs # Match ctf information against the micrographs self.ctfDict = {} if self.ctfRelations.get() is not None: for ctf in self.ctfRelations.get(): self.ctfDict[ctf.getMicrograph().getMicName()] = ctf.clone() micStar = self._getPath('input_micrographs.star') writeSetOfMicrographs(self.getInputMicrographs(), micStar, alignType=em.ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) # We need to compute a scale factor for the coordinates if extracting # from other micrographs with a different pixel size micDict = {} for mic in self.getInputMicrographs(): micDict[mic.getMicName()] = mic.getFileName() def _getCoordsStarFile(mic): micName = mic.getMicName() if not micName in micDict: return None micFn = micDict[micName] return self._getExtraPath( pwutils.replaceBaseExt(micFn, 'coords.star')) self.info("Using scale: %s" % self.getScaleFactor()) writeSetOfCoordinates(self._getExtraPath(), self.getInputCoords(), _getCoordsStarFile, scale=self.getScaleFactor())
def writeCtfStarStep(self): inputCTF = self.inputCTF.get() if self.micrographSource == 0: # same as CTF estimation ctfMicSet = inputCTF.getMicrographs() else: ctfMicSet = self.inputMicrographs.get() micSet = SetOfMicrographs(filename=':memory:') psd = inputCTF.getFirstItem().getPsdFile() hasPsd = psd and os.path.exists(psd) if hasPsd: psdPath = self._getPath('PSD') pwutils.makePath(psdPath) print "Writing PSD files to %s" % psdPath for ctf in inputCTF: # Get the corresponding micrograph mic = ctfMicSet[ctf.getObjId()] if mic is None: print("Skipping CTF id: %s, it is missing from input " "micrographs. " % ctf.getObjId()) continue micFn = mic.getFileName() if not os.path.exists(micFn): print "Skipping micrograph %s, it does not exists. " % micFn continue mic2 = mic.clone() mic2.setCTF(ctf) if hasPsd: psdFile = ctf.getPsdFile() newPsdFile = join(psdPath, '%s_psd.mrc' % mic.getMicName()) if not os.path.exists(psdFile): print "PSD file %s does not exits" % psdFile print "Skipping micrograph %s" % micFn continue pwutils.copyFile(psdFile, newPsdFile) ctf.setPsdFile(newPsdFile) micSet.append(mic2) starFile = self._getPath(self.CTF_STAR_FILE % self.getObjId()) print "Writing set: %s" % inputCTF print " to: %s" % starFile acq = ctfMicSet.getAcquisition() self.samplingRate = ctfMicSet.getSamplingRate() mag = acq.getMagnification() self.detectorPixelSize = 1e-4 * self.samplingRate * mag writeSetOfMicrographs(micSet, starFile, preprocessImageRow=self.preprocessMicrograph) # Let's create a link from the project roots to facilitate the import # of the star file into a Relion project pwutils.createLink(starFile, os.path.basename(starFile))
def _pickMicrographList(self, micList, *args): micStar = self._getPath('input_micrographs_%s-%s.star' % (micList[0].strId(), micList[-1].strId())) writeSetOfMicrographs(micList, micStar, alignType=ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) self._pickMicrographsFromStar(micStar, *args)
def _pickMicrographList(self, micList, params, threshold, minDistance, fom): micStar = self._getPath('input_micrographs_%s-%s.star' % (micList[0].strId(), micList[-1].strId())) writeSetOfMicrographs(micList, micStar, alignType=ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) self._pickMicrographsFromStar(micStar, params, threshold, minDistance, fom)
def writeCtfStarStep(self): inputCTF = self.inputCTF.get() if self.micrographSource == 0: # same as CTF estimation ctfMicSet = inputCTF.getMicrographs() else: ctfMicSet = self.inputMicrographs.get() micSet = SetOfMicrographs(filename=':memory:') psd = inputCTF.getFirstItem().getPsdFile() hasPsd = psd and os.path.exists(psd) if hasPsd: psdPath = self._getPath('PSD') pwutils.makePath(psdPath) print "Writing PSD files to %s" % psdPath for ctf in inputCTF: # Get the corresponding micrograph mic = ctfMicSet[ctf.getObjId()] if mic is None: print( "Skipping CTF id: %s, it is missing from input " "micrographs. " % ctf.getObjId()) continue micFn = mic.getFileName() if not os.path.exists(micFn): print "Skipping micrograph %s, it does not exists. " % micFn continue mic2 = mic.clone() mic2.setCTF(ctf) if hasPsd: psdFile = ctf.getPsdFile() newPsdFile = join(psdPath, '%s_psd.mrc' % mic.getMicName()) if not os.path.exists(psdFile): print "PSD file %s does not exits" % psdFile print "Skipping micrograph %s" % micFn continue pwutils.copyFile(psdFile, newPsdFile) ctf.setPsdFile(newPsdFile) micSet.append(mic2) starFile = self._getPath(self.CTF_STAR_FILE % self.getObjId()) print "Writing set: %s" % inputCTF print " to: %s" % starFile writeSetOfMicrographs(micSet, starFile, preprocessImageRow=self.preprocessMicrograph) # Let's create a link from the project roots to facilitate the import # of the star file into a Relion project pwutils.createLink(starFile, os.path.basename(starFile))
def _convertCoordinates(self, mic, coordList): micStar, _ = self._getStarFiles(mic) writeSetOfMicrographs([mic], self._getPath(micStar), alignType=em.ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) writeMicCoordinates(mic, coordList, self._getMicPos(mic), getPosFunc=self._getPos)
def convertInputStep(self, micsId, refsId): self._ih = ImageHandler() # used to convert micrographs # Match ctf information against the micrographs self.ctfDict = {} if self.ctfRelations.get() is not None: for ctf in self.ctfRelations.get(): self.ctfDict[ctf.getMicrograph().getMicName()] = ctf.clone() micStar = self._getPath('input_micrographs.star') writeSetOfMicrographs(self.getInputMicrographs(), micStar, preprocessImageRow=self._preprocessMicrographRow, postprocessImageRow=self._postprocessMicrographRow) writeReferences(self.getInputReferences(), self._getPath('input_references'))
def _extractMicrographList(self, micList, params): micsStar = self._getMicsStar(micList) writeSetOfMicrographs(micList, self._getPath(micsStar), alignType=em.ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) partsStar = self._getMicParticlesStar(micList) for mic in micList: self._convertCoordinates(mic, self.coordDict[mic.getObjId()]) self._micCoordStarDict[mic.getObjId()] = partsStar args = ' --i %s --part_star %s %s' % (micsStar, partsStar, params) self.runJob(self._getProgram('relion_preprocess'), args, cwd=self.getWorkingDir())
def convertInputStep(self, micsId, refsId, runType): # runType is passed as parameter to force a re-execute of this step # if there is a change in the type self._ih = ImageHandler() # used to convert micrographs # Match ctf information against the micrographs self.ctfDict = {} if self.ctfRelations.get() is not None: for ctf in self.ctfRelations.get(): self.ctfDict[ctf.getMicrograph().getMicName()] = ctf.clone() micStar = self._getPath('input_micrographs.star') writeSetOfMicrographs(self.getMicrographList(), micStar, alignType=ALIGN_NONE, preprocessImageRow=self._preprocessMicrographRow) if self.useInputReferences(): writeReferences(self.getInputReferences(), self._getPath('input_references'), useBasename=True)
def convertInputStep(self, micFn, inputId): writeSetOfMicrographs(self.inputMics, micFn)