def getFilePreview(self, objFile): self._imgPreview = None self._imgInfo = None filename = objFile.getPath() ext = pwutils.getExt(filename) if ext == '.xmd' or ext == '.ctfparam' or ext == '.pos' or ext == '.doc': msg = "*Metadata File* " blocks = emlib.getBlocksInMetaDataFile(filename) nblocks = len(blocks) if nblocks <= 1: mdStr = self._getMdString(filename) msg += " (single block)\n" if self._imgInfo: msg += "\nFirst item: \n" + self._imgInfo msg += '\n' + mdStr else: mdStr = self._getMdString(filename, blocks[0]) msg += " (%d blocks) " % nblocks if self._imgInfo: msg += "\nFirst item: \n" + self._imgInfo msg += "\nFirst block: \n" + mdStr msg += "\nAll blocks:" + ''.join( ["\n - %s" % b for b in blocks]) elif ext == '.star': msg = "*Relion STAR file* \n" msg += self._getMdString(filename) return self._imgPreview, msg
def runInitAngularReferenceFileStep(self): '''Create Initial angular file. Either fill it with zeros or copy input''' #NOTE: if using angles, self.selFileName file should contain angles info md = emlib.MetaData(self.selFileName) # Ensure this labels are always md.addLabel(emlib.MDL_ANGLE_ROT) md.addLabel(emlib.MDL_ANGLE_TILT) md.addLabel(emlib.MDL_ANGLE_PSI) expImages = self._getFileName('inputParticlesDoc') ctfImages = self._getFileName('imageCTFpairs') md.write(self._getExpImagesFileName(expImages)) blocklist = emlib.getBlocksInMetaDataFile(ctfImages) mdCtf = emlib.MetaData() mdAux = emlib.MetaData() readLabels = [emlib.MDL_ITEM_ID, emlib.MDL_IMAGE] for block in blocklist: #read ctf block from ctf file mdCtf.read(block + '@' + ctfImages, readLabels) #add ctf columns to images file mdAux.joinNatural(md, mdCtf) # write block in images file with ctf info mdCtf.write(block + '@' + expImages, emlib.MD_APPEND) return [expImages]
def _pickMicrograph(self, mic, *args): micPath = mic.getFileName() # Get particle picking boxsize from the previous run boxSize = self.particlePickingRun.outputCoordinates.getBoxSize() modelRoot = self._getExtraPath('model') micName = removeBaseExt(micPath) proceed = True if self.micsToPick == MICS_SAMEASPICKING: basePos = replaceBaseExt(micPath, "pos") fnPos = self.particlePickingRun._getExtraPath(basePos) if exists(fnPos): blocks = emlib.getBlocksInMetaDataFile(fnPos) copy = True if 'header' in blocks: mdheader = emlib.MetaData("header@" + fnPos) state = mdheader.getValue( emlib.MDL_PICKING_MICROGRAPH_STATE, mdheader.firstObject()) if state == "Available": copy = False if copy: # Copy manual .pos file of this micrograph copyFile(fnPos, self._getExtraPath(basename(fnPos))) proceed = False if proceed: args = "-i %s " % micPath args += "--particleSize %d " % boxSize args += "--model %s " % modelRoot args += "--outputRoot %s " % self._getExtraPath(micName) args += "--mode autoselect --thr %d" % self.numberOfThreads self.runJob("xmipp_micrograph_automatic_picking", args)
def homogeneizeStep(self): minClass = self.homogeneize.get() fnNeighbours = self._getExtraPath("neighbours.xmd") # Look for the block with the minimum number of images if minClass == 0: minClass = 1e38 for block in emlib.getBlocksInMetaDataFile(fnNeighbours): projNumber = int(block.split("_")[1]) fnDir = self._getExtraPath("direction_%d" % projNumber, "level_00", "class_classes.xmd") if exists(fnDir): blockSize = md.getSize("class000001_images@" + fnDir) if blockSize < minClass: minClass = blockSize # Construct the homogeneized metadata mdAll = emlib.MetaData() mdSubset = emlib.MetaData() mdRandom = emlib.MetaData() for block in emlib.getBlocksInMetaDataFile(fnNeighbours): projNumber = int(block.split("_")[1]) fnDir = self._getExtraPath("direction_%d" % projNumber, "level_00", "class_classes.xmd") if exists(fnDir): mdDirection = emlib.MetaData("class000001_images@" + fnDir) mdRandom.randomize(mdDirection) mdSubset.selectPart(mdRandom, 0, min(mdRandom.size(), minClass)) mdAll.unionAll(mdSubset) mdAll.removeDuplicates(md.MDL_ITEM_ID) mdAll.sort(md.MDL_ITEM_ID) mdAll.fillConstant(md.MDL_PARTICLE_ID, 1) fnHomogeneous = self._getExtraPath("images_homogeneous.xmd") mdAll.write(fnHomogeneous) self.runJob("xmipp_metadata_utilities", '-i %s --operate modify_values "particleId=itemId"' % fnHomogeneous, numberOfMpi=1)
def classifyGroupsStep(self): # Create two metadatas, one for classes and another one for images mdClasses = emlib.MetaData() mdImages = emlib.MetaData() fnNeighbours = self._getExtraPath("neighbours.xmd") fnGallery = self._getExtraPath("gallery.stk") self.classCount = 0 self.classImages = set() for block in emlib.getBlocksInMetaDataFile(fnNeighbours): # Figure out the projection number from the block name projNumber = int(block.split("_")[1]) self.classifyOneGroup(projNumber, projMdBlock="%s@%s" % (block, fnNeighbours), projRef="%06d@%s" % (projNumber, fnGallery), mdClasses=mdClasses, mdImages=mdImages) galleryMd = emlib.MetaData(self._getExtraPath("gallery.doc")) # Increment the reference number to starts from 1 galleryMd.operate("ref=ref+1") mdJoined = emlib.MetaData() # Add extra information from the gallery metadata mdJoined.join1(mdClasses, galleryMd, emlib.MDL_REF) # Remove unnecessary columns md.keepColumns(mdJoined, "ref", "ref2", "image", "image1", "classCount", "angleRot", "angleTilt") # Write both classes and images fnDirectional = self._getDirectionalClassesFn() self.info("Writting classes info to: %s" % fnDirectional) mdJoined.write(fnDirectional) fnDirectionalImages = self._getDirectionalImagesFn() self.info("Writing images info to: %s" % fnDirectionalImages) mdImages.write(fnDirectionalImages)