def createOutputStep(self): # PARTICLES cleanPattern(self._getPath("*.sqlite")) partSet = self._createSetOfParticles() readSetOfParticles(self._getPath("particles.xmd"), partSet) inputSampling = self.inputCoordinates[0].get().getMicrographs( ).getSamplingRate() partSet.setSamplingRate(self._getDownFactor() * inputSampling) boxSize = self._getBoxSize() # COORDINATES writeSet = False if self.checkIfPrevRunIsCompatible("coords_"): writeSet = True if not "OR" in self.coordinatesDict: self.loadCoords(self._getExtraPath( self.CONSENSUS_COOR_PATH_TEMPLATE % 'TRUE'), 'OR', writeSet=False) coordSet = SetOfCoordinates( filename=self._getPath("coordinates.sqlite")) coordSet.copyInfo(self.coordinatesDict['OR']) coordSet.setBoxSize(boxSize) coordSet.setMicrographs(self.coordinatesDict['OR'].getMicrographs()) downFactor = self._getDownFactor() for part in partSet: coord = part.getCoordinate().clone() coord.scale(downFactor) deepZscoreLabel = '_xmipp_%s' % xmipp.label2Str( MD.MDL_ZSCORE_DEEPLEARNING1) setattr(coord, deepZscoreLabel, getattr(part, deepZscoreLabel)) coordSet.append(coord) coordSet.write() partSet.write() self._defineOutputs(outputCoordinates=coordSet) self._defineOutputs(outputParticles=partSet) for inSetOfCoords in self.inputCoordinates: self._defineSourceRelation(inSetOfCoords.get(), coordSet) self._defineSourceRelation(inSetOfCoords.get(), partSet)
def readSetOfCoordsFromPosFnames(posDir, setOfInputCoords, sqliteOutName, write=True): """ posDir: path where there are .pos files with coordinates setOfInputCoords. Set to find micrographs sqliteOutName. Path where sqlite map will be created. Warning, it overwrites content """ inputMics = setOfInputCoords.getMicrographs() cleanPath(sqliteOutName) setOfOutputCoordinates= SetOfCoordinates(filename= sqliteOutName) setOfOutputCoordinates.setMicrographs(inputMics) setOfOutputCoordinates.setBoxSize(setOfInputCoords.getBoxSize()) readSetOfCoordinates(posDir, micSet=inputMics, coordSet=setOfOutputCoordinates, readDiscarded=False) if write: setOfOutputCoordinates.write() return setOfOutputCoordinates
def _visualizeCoordinates(self, e=None): views = [] outCoords = self.protocol.getOutput() if not outCoords: print(" > Not output found, yet."); return coordsViewerFn = self.protocol._getExtraPath('coordsViewer.sqlite') mdLabel = emlib.MDL_GOOD_REGION_SCORE if not getXmippAttribute(outCoords.getFirstItem(), mdLabel): print(" > outputCoordinates do NOT have 'MDL_GOOD_REGION_SCORE'!"); return cleanPath(coordsViewerFn) newOutput = SetOfCoordinates(filename=coordsViewerFn) newOutput.copyInfo(outCoords) newOutput.setMicrographs(outCoords.getMicrographs()) thres = self.visualizeCoordinates.get() for coord in outCoords: if getXmippAttribute(coord, mdLabel).get() > thres: newOutput.append(coord.clone()) newOutput.write() newOutput.close() #SetOfCoordinates does not implement __exit__, required for with micSet = newOutput.getMicrographs() # accessing mics to provide metadata file if micSet is None: raise Exception('visualize: SetOfCoordinates has no micrographs set.') fn = self.protocol._getExtraPath("allMics.xmd") xmipp3.convert.writeSetOfMicrographs(micSet, fn) tmpDir = self.protocol._getExtraPath('manualThresholding_%03d'%int(thres*100)) cleanPath(tmpDir) makePath(tmpDir) xmipp3.convert.writeSetOfCoordinates(tmpDir, newOutput) views.append(CoordinatesObjectView(self._project, fn, tmpDir, self.protocol, inTmpFolder=True)) return views