def readStarFile(prot, outputSetObject, fileType, starFile=None, invert=True, returnTable=False): warningMsg = None # # Star file can be provided by the user or not, depending on the protocol invoking this method # if not starFile: # starFile = prot.starFile.get() # # # If the star file is currently in the extra folder of another protocol execution, the paths # # generated with method _getExtraPath() will become wrong, but it doesn't have to be located there # if 'extra' in starFile: # starPath = '' # else: # starPath = dirname(starFile) + '/' tomoTable = Table() tomoTable.read(starFile) if fileType == RELION_SUBTOMO_STAR: labels = RELION_TOMO_LABELS _relionTomoStar2Subtomograms(prot,outputSetObject, tomoTable, invert) else: # fileType == PYSEG_PICKING_STAR: labels = PYSEG_PICKING_LABELS _pysegStar2Coords3D(prot, outputSetObject, tomoTable, invert) if not tomoTable.hasAllColumns(labels): missingCols = [name for name in labels if name not in tomoTable.getColumnNames()] warningMsg = 'Columns %s\nwere not found in the star file provided.\nThe corresponding numerical ' \ 'values will be considered as 0.' \ % ' '.join(['*' + colName + '*' for colName in missingCols]) if returnTable: return warningMsg, tomoTable else: return warningMsg
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)
def _getTomogramsFromStar(self): """Get the tomograms names to generate the output setOfTomograms and vesicles subtomogras ref tomograms""" tomoFileList = [] tomoTable = Table() tomoTable.read(self._starFile) for row in tomoTable: tomoFileList.append(row.get(TOMOGRAM)) return tomoFileList
def _findVesicleCenter(self, starFileInit, starFilePreseg1): ih = ImageHandler() outputTable = self._createTable() # Read preseg (vesicles not centered) table presegTable = Table() presegTable.read(starFilePreseg1) # Read initial data initTable = Table() initTable.read(starFileInit) # Generate the star file with the vesicles centered for the second pre_seg execution for row, rowp in zip(initTable, presegTable): tomo = row.get(TOMOGRAM, NOT_FOUND) vesicle = row.get(VESICLE, NOT_FOUND) materialIndex = row.get(PYSEG_LABEL, NOT_FOUND) # Get the upper left corner of the vesicle in the original tomogram: _psSegOffX #7 _psSegOffY #8 _psSegOffZ # #9 from output star file of pre_tomos_seg.py that do not distinguish inner and outer densities xdimCorner = rowp.get(PYSEG_OFFSET_X, 0) ydimCorner = rowp.get(PYSEG_OFFSET_Y, 0) zdimCorner = rowp.get(PYSEG_OFFSET_Z, 0) # Get the box dimensions, be sure that the Dimensions format is Dimensions: 239 x 1 x 298 x 298 # ((N)Objects x (Z)Slices x (Y)Rows x (X)Columns) x, y, z, _ = ih.getDimensions(rowp.get(MASK, NOT_FOUND)) # Add row to output table outputTable.addRow( tomo, vesicle, materialIndex, vesicle, xdimCorner + x / 2, ydimCorner + y / 2, zdimCorner + z / 2, ) outputTable.write(self.getVesiclesCenteredStarFile())