def __init__(self, **kwargs): MockObject.__init__(self, **kwargs) self._micrographPointer = pwobj.Pointer(objDoStore=False) self._x = pwobj.Integer(kwargs.get('x', None)) self._y = pwobj.Integer(kwargs.get('y', None)) self._micId = pwobj.Integer() self._micName = pwobj.String()
def __init__(self, confs={}, **kwargs): pwobj.OrderedObject.__init__(self, **kwargs) self.config = ProjectConfig() # Store the current view selected by the user self.currentProtocolsView = pwobj.String() # Store the color mode: 0= Status, 1=Labels, ... self.colorMode = pwobj.Integer(ProjectSettings.COLOR_MODE_STATUS) self.nodeList = NodeConfigList( ) # Store graph nodes positions and other info self.labelsList = LabelsList() # Label list self.mapper = None # This should be set when load, or write self.runsView = pwobj.Integer(1) # by default the graph view self.readOnly = pwobj.Boolean(False) self.runSelection = pwobj.CsvList(int) # Store selected runs self.dataSelection = pwobj.CsvList(int) # Store selected runs # Some extra settings stored, now mainly used # from the webtools # Time when the project was created self.creationTime = pwobj.String(dt.datetime.now()) # Number of days that this project is active # if None, the project will not expire # This is used in webtools where a limited time # is allowed for each project self.lifeTime = pwobj.Integer() # Set a disk quota for the project (in Gb) # if None, quota is unlimited self.diskQuota = pwobj.Integer()
def __init__(self, location=None, **kwargs): MockImage.__init__(self, location, **kwargs) # This may be redundant, but make the Particle # object more independent for tracking coordinates self._coordinate = None self._micId = pwobj.Integer() self._classId = pwobj.Integer()
def __init__(self, nodeId=0, x=None, y=None, selected=False, expanded=True): pwobj.Scalar.__init__(self) # Special node id 0 for project node self._values = {'id': nodeId, 'x': pwobj.Integer(x).get(0), 'y': pwobj.Integer(y).get(0), 'selected': selected, 'expanded': expanded}
def __init__(self, location=None, **kwargs): """ Params: :param location: Could be a valid location: (index, filename) or filename """ EdBaseObject.__init__(self, **kwargs) # Image location is composed by an index and a filename self._index = pwobj.Integer(0) self._filename = pwobj.String() # Detector distance of this image self._distance = pwobj.Float() # Where oscillation starts and its range self._oscStart = pwobj.Float() self._oscRange = pwobj.Float() # Beam center (in pixels) self._beamCenterX = pwobj.Float() self._beamCenterY = pwobj.Float() # Exposure time (in seconds) self._exposureTime = pwobj.Float() # TwoTheta self._twoTheta = pwobj.Float() # Pixel size of the image (in millimeters) self._pixelSizeX = pwobj.Float() self._pixelSizeY = pwobj.Float() # Dimensions of images in this set (number of pixels) self._dimX = pwobj.Integer() self._dimY = pwobj.Integer() # Wavelength self._wavelength = pwobj.Float() # Detector type self._detector = Detector() # Experiment time self._collectionTime = pwobj.String() # Add parameter to state if the image should be ignored in processing self._ignore = pwobj.Boolean() # Add information about goniometer rotation axis relative to image self._rotX = pwobj.Float() self._rotY = pwobj.Float() self._rotZ = pwobj.Float() if location: self.setLocation(location)
def __init__(self, **kwargs): EdBaseObject.__init__(self, **kwargs) self._spotId = pwobj.Integer() self._bbox = pwobj.CsvList() self._flag = pwobj.Integer() self._intensitySumValue = pwobj.Float() self._intensitySumVariance = pwobj.Float() self._nSignal = pwobj.Integer() self._panel = pwobj.Integer() self._shoebox = None self._xyzobsPxValue = pwobj.CsvList() self._xyzobsPxVariance = pwobj.CsvList()
def compareClassesStep(self, i1, i2): set1 = self.inputClasses1.get() set2 = self.inputClasses2.get() # Compare each pair of class from set1 and set2 # compute the Jaccard index for each (J = len(intersection) / len(union)) # Create a list will all pairs indexes and the sort them jaccardList = [] f = open(self._getPath('jaccard.txt'), 'w') f.write( '; class1 class2 intersection(i) union(i) jaccard index = len(i)/len(u)\n' ) for cls1 in set1: ids1 = cls1.getIdSet() for cls2 in set2: ids2 = cls2.getIdSet() inter = len(ids1.intersection(ids2)) union = len(ids1.union(ids2)) jaccardIndex = float(inter) / union jaccardTuple = (cls1.getObjId(), cls2.getObjId(), inter, union, jaccardIndex) f.write('%d %d %d %d %0.3f\n' % jaccardTuple) jaccardList.append(jaccardTuple) f.close() jaccardList.sort(key=lambda e: e[4], reverse=True) visitedClasses = set() outputFn = self._getPath('consensus.sqlite') pwutils.cleanPath(outputFn) outputSet = emobj.EMSet(filename=outputFn) for clsId1, clsId2, inter, union, jaccardIndex in jaccardList: if clsId1 not in visitedClasses: visitedClasses.add(clsId1) # mark as visited cls1 = set1[clsId1] cls2 = set2[clsId2] o = pwobj.Object() o.setObjLabel('classes %d - %d' % (clsId1, clsId2)) o.class1 = cls1.clone() o.class1.id = pwobj.Integer(clsId1) o.class2 = cls2.clone() o.class2.id = pwobj.Integer(clsId2) o.jaccard = pwobj.Float(jaccardIndex) o.intersection = pwobj.Integer(inter) o.union = pwobj.Integer(union) outputSet.append(o) self._defineOutputs(outputConsensus=outputSet)
def testWithPointer(self): obj = pwobj.Integer(10) self.assertFalse(obj.hasPointer(), "Default instantiation off Integer has a pointer.") self.assertEqual(obj.get(), 10, "Integer.get(), without pointer fails.") pointee = pwobj.Object() setattr(pointee, "value", pwobj.Integer(20)) # Set a pointer (not a real case though, but enough here) obj.setPointer(pwobj.Pointer(pointee, extended='value')) self.assertEqual(obj.get(), 20, "Integer.get() fails with a pointer.")
def searchStep(self): outputDatabaseID = SetOfDatabaseID().create(path=self._getPath()) fnList = [] for item in self.inputListID.get(): newItem = DatabaseID() newItem.copy(item) newItem._uniprotFile = pwobj.String("Not available") newItem._unitprotSeqLength = pwobj.Integer(-1) uniprotId = item._uniprotId.get() print("Processing %s" % uniprotId) urlId = "https://www.uniprot.org/uniprot/%s.fasta" % uniprotId fnFasta = self._getExtraPath("%s.fasta" % uniprotId) if not os.path.exists(fnFasta): print("Fetching uniprot: %s" % urlId) for i in range(3): try: urllib.request.urlretrieve(urlId, fnFasta) if not fnFasta in fnList: fnList.append(fnFasta) break except: # The library raises an exception when the web is not found pass if os.path.exists(fnFasta): newItem._uniprotFile = pwobj.String(fnFasta) newItem._unitprotSeqLength = pwobj.Integer( sequenceLength(fnFasta)) outputDatabaseID.append(newItem) fnAll = self._getPath("sequences.fasta") with open(fnAll, 'w') as outfile: for fname in fnList: with open(fname) as infile: for line in infile: outfile.write(line) outfile.write('\n\n') seqFile = ProteinSequenceFile() seqFile.setFileName(fnAll) self._defineOutputs(outputUniprot=outputDatabaseID) self._defineSourceRelation(self.inputListID, outputDatabaseID) self._defineOutputs(outputSequence=seqFile) self._defineSourceRelation(self.inputListID, seqFile)
def __init__(self, **kwargs): Volume.__init__(self, **kwargs) self._acquisition = None self._tsId = pwobj.String(kwargs.get('tsId', None)) self._tomoPointer = pwobj.Pointer(objDoStore=False) self._tomoId = pwobj.Integer() self._tomoName = pwobj.String()
def _createOutputStep(self): # New Output would be an Integer boxSize = pwobj.Integer(10) if self.iBoxSize.hasValue(): boxSize.set(2 * int(self.iBoxSize.get())) self._defineOutputs(oBoxSize=boxSize)
def _particlesToEmx(emxData, partSet, micSet=None, **kwargs): """ Write a SetOfMicrograph as expected in EMX format Params: micSet: input set of micrographs filename: the EMX file where to store the micrographs information. micSet: micrographs set associated with the particles **kwargs: writeImages: if set to False, only coordinates are exported. imagesStack: if passed all images will be output into a single stack file. imagesPrefix: used when not imagesStack is passed. A different stack will be created per micrograph. """ writeImages = kwargs.get('writeImages', True) imagesPrefix = kwargs.get('imagesPrefix', None) micDict = {} # Use singleMic for count all particles to be written to a single stack imagesStack = kwargs.get('imagesStack', None) singleMic = Micrograph() singleMic.setFileName(imagesStack) singleMic.counter = pwobj.Integer(0) def _getMicKey(particle): coord = particle.getCoordinate() if coord is None or coord.getMicName() is None: return '%05d' % particle.getMicId() else: return pwutils.removeExt(coord.getMicName()) def _getLocation(particle): if imagesStack is not None: mic = singleMic else: micKey = _getMicKey(particle) if micKey not in micDict: mic = Micrograph() mic.setFileName(join(imagesPrefix, 'particles_%s.mrc' % micKey)) mic.counter = pwobj.Integer(0) micDict[micKey] = mic else: mic = micDict[micKey] # Count one more particle assigned to this micrograph mic.counter.increment() return (mic.counter.get(), mic.getFileName()) ih = ImageHandler() partAlign = partSet.getAlignment() for particle in partSet: if writeImages: newLoc = _getLocation(particle) ih.convert(particle, newLoc) localFn = basename(newLoc[1]) particle.setLocation(newLoc[0], localFn) emxObj = _particleToEmx(emxData, particle, micSet, partAlign) else: emxObj = _coordinateToEmx(emxData, particle, micSet) emxData.addObject(emxObj)
def test_removeFromLists(self): """ Check that lists are properly stored after removing some elements. """ fn = self.getOutputPath("lists.sqlite") print(">>> Using db: ", fn) # Let's create a Mapper to store a simple List containing two integers mapper = pwmapper.SqliteMapper(fn, pw.Config.getDomain().getMapperDict()) iList = pwobj.List() i1 = pwobj.Integer(4) i2 = pwobj.Integer(3) iList.append(i1) iList.append(i2) # Store the list and commit changes to db, then close db. mapper.store(iList) mapper.commit() mapper.close() # Now let's open again the db with a different connection # and load the previously stored list mapper2 = pwmapper.SqliteMapper(fn, pw.Config.getDomain().getMapperDict()) iList2 = mapper2.selectByClass('List')[0] # Let's do some basic checks self.assertEqual(iList2.getSize(), 2) self.assertTrue(pwobj.Integer(4) in iList2) self.assertTrue(pwobj.Integer(3) in iList2) # Now remove one of the integers in the list # check consistency in the list elements iList2.remove(pwobj.Integer(4)) self.assertEqual(iList2.getSize(), 1) self.assertTrue(pwobj.Integer(4) not in iList2) self.assertTrue(pwobj.Integer(3) in iList2) # Store once again the new list with one element mapper2.store(iList2) mapper2.commit() mapper2.close() # Open the db and load the list once again mapper3 = pwmapper.SqliteMapper(fn, pw.Config.getDomain().getMapperDict()) iList3 = mapper3.selectByClass('List')[0] # Check the same consistency before it was stored self.assertEqual(iList3.getSize(), 1) self.assertTrue(pwobj.Integer(4) not in iList3) self.assertTrue(pwobj.Integer(3) in iList3)
def test_formatString(self): """ Test that Scalar objects behave well when using string formatting such as: %f or %d """ i = pwobj.Integer(10) f = pwobj.Float(3.345) s1 = "i = %d, f = %0.3f" % (i, f) self.assertEqual(s1, "i = 10, f = 3.345")
def loadFromParticles(self, inputParts, outputParts): # compute difference in defocus and save in database micInfo = None lastMicId = None infoList = [] # Coordinates of the particle with higher x and y values # These values are used for plotting xMax = 0 yMax = 0 def _avgDefocus(p): dU, dV, _ = p.getCTF().getDefocus() return (dU + dV) / 2.0 for p1, p2 in zip(inputParts.iterItems(orderBy=['_micId', 'id']), outputParts.iterItems(orderBy=['_micId', 'id'])): coord = p1.getCoordinate() micId = coord.getMicId() if micId != lastMicId: micInfo = CtfRefineMicInfo(micId=micId, micName=coord.getMicName()) infoList.append(micInfo) lastMicId = micId p1D = _avgDefocus(p1) p2D = _avgDefocus(p2) x, y = coord.getPosition() if xMax < x: xMax = x if yMax < y: yMax = y micInfo.addEntry(x, y, p2D, p2D - p1D) for micInfo in infoList: micInfo.computeStats() self._infoSet.append(micInfo) self._infoSet._xMax = pwobj.Integer(xMax) self._infoSet._yMax = pwobj.Integer(yMax) self._infoSet.write()
def test_Object(self): value = 2 i = pwobj.Integer(value) self.assertEqual(value, i.get()) # compare objects i2 = pwobj.Integer(value) self.assertEqual(i, i2) value = 2. f = pwobj.Float(value) self.assertAlmostEqual(value, f.get()) f.multiply(5) self.assertAlmostEqual(value*5, f.get()) a = pwobj.Integer() self.assertEqual(a.hasValue(), False) c = Complex.createComplex() # Check values are correct self.assertEqual(c.imag.get(), Complex.cGold.imag) self.assertEqual(c.real.get(), Complex.cGold.real) # Test Boolean logic b = pwobj.Boolean(False) self.assertTrue(not b.get()) b.set('True') self.assertTrue(b.get()) b = pwobj.Boolean() b.set(False) self.assertTrue(not b.get()) # CsvList should be empty if set to '' l = pwobj.CsvList() l.set('') self.assertEqual(len(l), 0) # Test emptiness self.assertIsNotEmpty(b)
def constructOutput(self, fnTxt): fnDir, fnResults = os.path.split(fnTxt) tokens = fnResults.split('-') if len(tokens) > 1: subset = tokens[1].split('.')[0] else: subset = "" outputSet = SetOfDatabaseID.create(path=self._getPath(), suffix=subset) for line in open(fnTxt, "r"): line = line.strip() if line == "": continue elif line.startswith("# Structural equivalences"): break elif line.startswith("#"): continue else: tokens = line.split() pdbId = DatabaseID() tokens2 = tokens[1].split('-') pdbId.setDatabase("pdb") pdbId.setDbId(tokens[1]) pdbId._pdbId = pwobj.String(tokens2[0]) if len(tokens2) > 1: pdbId._chain = pwobj.String(tokens2[1]) pdbId._PDBLink = pwobj.String( "https://www.rcsb.org/structure/%s" % tokens2[0]) pdbId._DaliZscore = pwobj.Float(float(tokens[2])) pdbId._DaliRMSD = pwobj.Float(float(tokens[3])) pdbId._DaliSuperpositionLength = pwobj.Integer(int(tokens[4])) pdbId._DaliSeqLength = pwobj.Integer(int(tokens[5])) pdbId._DaliSeqIdentity = pwobj.Float(float(tokens[6])) pdbId._DaliDescription = pwobj.String(" ".join(tokens[7:])) outputSet.append(pdbId) outputDict = {'outputDatabaseIds%s' % subset: outputSet} self.protocol._defineOutputs(**outputDict) self.protocol._defineSourceRelation(self.protocol.inputStructure, outputSet)
def __init__(self, **kwargs): pwobj.Object.__init__(self, **kwargs) self.micId = pwobj.Integer(kwargs.get('micId', None)) self.micName = pwobj.String(kwargs.get('micName', None)) # list particle x coordinate def _floatList(key): fl = pwobj.CsvList(pType=float) fl.set(kwargs.get(key, [])) return fl self.x = _floatList('xCoord') # list particle y coordinate self.y = _floatList('yCoord') # list particle defocus self.defocus = _floatList('defocus') # list particle defocus difference self.defocusDiff = _floatList('defocusDiff') self.stdev = pwobj.Float() # defocus stdev self.n = pwobj.Integer() # number particles in the micrograph
def __init__(self, filename=None, poses=None, ctfs=None, dim=None, samplingRate=None, **kwargs): EMObject.__init__(self, **kwargs) self.filename = pwobj.String(filename) self.poses = pwobj.String(poses) self.ctfs = pwobj.String(ctfs) self.samplingRate = pwobj.Float(samplingRate) self.dim = pwobj.Integer(dim)
def __init__(self, location=None, **kwargs): """ Params: :param location: Could be a valid location: (index, filename) or filename """ MockObject.__init__(self, **kwargs) # Image location is composed by an index and a filename self._index = pwobj.Integer(0) self._filename = pwobj.String() self._samplingRate = pwobj.Float() self._ctfModel = None self._acquisition = None if location: self.setLocation(location)
def _getLocation(particle): if imagesStack is not None: mic = singleMic else: micKey = _getMicKey(particle) if micKey not in micDict: mic = Micrograph() mic.setFileName(join(imagesPrefix, 'particles_%s.mrc' % micKey)) mic.counter = pwobj.Integer(0) micDict[micKey] = mic else: mic = micDict[micKey] # Count one more particle assigned to this micrograph mic.counter.increment() return (mic.counter.get(), mic.getFileName())
def test_basicObjectInProject(self): prot = self.newProtocol(ProtOutputTest, objLabel='to generate basic input') print("working dir: %s" % prot.getWorkingDir()) # Define a negative output for later tests prot._defineOutputs(negative=pwobj.Integer(-20)) self.launchProtocol(prot) # Default value is 10 so output is 20 self.assertOutput(prot) # Second protocol to test linking prot2 = self.newProtocol(ProtOutputTest, objLabel='to read basic input') # Set the pointer for the integer prot2.iBoxSize.setPointer(pwobj.Pointer(prot, extended="oBoxSize")) self.launchProtocol(prot2) self.assertOutput(prot2, value=40) # Test validation: only positive numbers are allowed prot3 = self.newProtocol(ProtOutputTest, objLabel='invalid input', iBoxSize=-10) # We expect this to fail with self.assertRaises(Exception): self.launchProtocol(prot3) # Test validation: pointer value is validated prot4 = self.newProtocol(ProtOutputTest, objLabel='invalid pointer input') # Now use negative pointer output prot4.iBoxSize.setPointer(pwobj.Pointer(prot, extended="negative")) # We expect this to fail with self.assertRaises(Exception): self.launchProtocol(prot4)
def __init__(self, train_data_dir=None, patch_size=None, **kwargs): EMObject.__init__(self, **kwargs) self._train_data_dir = pwobj.String(train_data_dir) self._patch_size = pwobj.Integer(patch_size)
def test_SqliteMapper(self): fn = self.getOutputPath("basic.sqlite") mapper = pwmapper.SqliteMapper(fn) # Insert a Float f = pwobj.Float(5.4) mapper.insert(f) # Insert an pwobj.Integer i = pwobj.Integer(1) mapper.insert(i) # Insert two pwobj.Boolean b = pwobj.Boolean(False) b2 = pwobj.Boolean(True) mapper.insert(b) mapper.insert(b2) # Test storing pointers p = pwobj.Pointer(b) mapper.insert(p) # Store csv list strList = ['1', '2', '3'] csv = pwobj.CsvList() csv += strList mapper.insert(csv) # Test normal List iList = pwobj.List() mapper.insert(iList) # Insert the list when empty i1 = pwobj.Integer(4) i2 = pwobj.Integer(3) iList.append(i1) iList.append(i2) mapper.update(iList) # now update with some items inside pList = pwobj.PointerList() p1 = pwobj.Pointer(b) # p1.set(b) p2 = pwobj.Pointer(b2) # p2.set(b2) pList.append(p1) pList.append(p2) mapper.store(pList) # Test to add relations relName = 'testRelation' creator = f mapper.insertRelation(relName, creator, i, b) mapper.insertRelation(relName, creator, i, b2) mapper.insertRelation(relName, creator, b, p) mapper.insertRelation(relName, creator, b2, p) # Save changes to file mapper.commit() self.assertEqual(1, mapper.db.getVersion()) mapper.close() # TODO: Maybe some mapper test for backward compatibility can be # include in scipion-em, where we already have defined datasets # and reference old sqlite files # Test using SqliteDb class db = pwmapper.SqliteDb() db._createConnection(fn, timeout=1000) tables = ['Objects', 'Relations'] self.assertEqual(tables, db.getTables()) # Test getting the version, for the gold file it should be 0 self.assertEqual(1, db.getVersion()) db.close() # Reading test mapper2 = pwmapper.SqliteMapper(fn, pw.Config.getDomain().getMapperDict()) print("Checking that Relations table is updated and version to 1") self.assertEqual(1, mapper2.db.getVersion()) # Check that the new column is properly added after updated to version 1 colNamesGold = [u'id', u'parent_id', u'name', u'classname', u'value', u'label', u'comment', u'object_parent_id', u'object_child_id', u'creation', u'object_parent_extended', u'object_child_extended'] colNames = [col[1] for col in mapper2.db.getTableColumns('Relations')] self.assertEqual(colNamesGold, colNames) l = mapper2.selectByClass('Integer')[0] self.assertEqual(l.get(), 1) f2 = mapper2.selectByClass('Float')[0] self.assertEqual(f, f2.get()) b = mapper2.selectByClass('Boolean')[0] self.assertTrue(not b.get()) p = mapper2.selectByClass('Pointer')[0] self.assertEqual(b.get(), p.get()) csv2 = mapper2.selectByClass('CsvList')[0] self.assertTrue(list.__eq__(csv2, strList)) # Iterate over all objects allObj = mapper2.selectAll() iterAllObj = mapper2.selectAll(iterate=True) for a1, a2 in zip(allObj, iterAllObj): # Note compare the scalar objects, which have a well-defined comparison if isinstance(a1, pwobj.Scalar): self.assertEqual(a1, a2) # Test select all batch approach allBatch = mapper2.selectAllBatch() # Test relations childs = mapper2.getRelationChilds(relName, i) parents = mapper2.getRelationParents(relName, p) # In this case both childs and parent should be the same for c, p in zip(childs, parents): self.assertEqual(c, p, "Childs of object i, should be the parents of object p") relations = mapper2.getRelationsByCreator(creator) for row in relations: print(dict(row))
def __init__(self, **kwargs): EdBaseSet.__init__(self, **kwargs) self._numberOfSpots = pwobj.Integer(0) self._skipImages = pwobj.Integer() self._dialsModelPath = pwobj.String() self._dialsReflPath = pwobj.String()
def __init__(self, **args): pwprot.Protocol.__init__(self, **args) self.name = pwobj.String(args.get('name', None)) self.numberOfSleeps = pwobj.Integer(args.get('n', 1)) self.runMode = pwobj.Integer(pwprot.MODE_RESUME)
def createOutputStep(self, tsObjId, outputSetName): ts = self._getTiltSeries(tsObjId) tsId = ts.getTsId() objId = ts.getObjId() self.outputSetName = outputSetName extraPrefix = self._getExtraPath(tsId) defocusFilePath = os.path.join( extraPrefix, ts.getFirstItem().parseFileName(extension=".defocus")) if os.path.exists(defocusFilePath): self.getOutputSetOfCTFTomoSeries(self.outputSetName) defocusFileFlag = utils.getDefocusFileFlag(defocusFilePath) newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(ts) newCTFTomoSeries.setTiltSeries(ts) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setObjId(objId) newCTFTomoSeries.setIMODDefocusFileFlag(defocusFileFlag) # We need to create now all the attributes of this object in order # to append it to the set and be able to update it posteriorly. " newCTFTomoSeries.setNumberOfEstimationsInRange(None) output = getattr(self, self.outputSetName) output.append(newCTFTomoSeries) if defocusFileFlag == 0: " Plain estimation " defocusUDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 1: " Astigmatism estimation " defocusUDict, defocusVDict, defocusAngleDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 4: " Phase-shift information " defocusUDict, phaseShiftDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) else: raise Exception( "Defocus file flag do not supported. Only supported formats corresponding to flags 0, " "1, 4, 5, and 37.") for index, _ in enumerate(ts): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.setIndex(pwobj.Integer(index + 1)) if defocusFileFlag == 0: " Plain estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) elif defocusFileFlag == 1: " Astigmatism estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) elif defocusFileFlag == 4: " Phase-shift information " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) newCTFTomo._cutOnFreqList = pwobj.CsvList(pType=float) newCTFTomo.setCutOnFreqList(cutOnFreqDict[index + 1]) defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) newCTFTomo.completeInfoFromList() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList() newCTFTomoSeries.calculateDefocusUDeviation( defocusUTolerance=self.defocusUTolerance) newCTFTomoSeries.calculateDefocusVDeviation( defocusVTolerance=self.defocusVTolerance) if not (newCTFTomoSeries.getIsDefocusUDeviationInRange() and newCTFTomoSeries.getIsDefocusVDeviationInRange()): newCTFTomoSeries.setEnabled(False) newCTFTomoSeries.write(properties=False) output.update(newCTFTomoSeries) output.write() self._store()
def __init__(self, path=None, **kwargs): EMObject.__init__(self, **kwargs) self._path = pwobj.String(path) self._nbOfClasses = pwobj.Integer( ) # nb of classes corresponding to this model (background included)
def importSetOfCtfTomoSeries(self): inputSetOfTiltSeries = self.inputSetOfTiltSeries.get() self.getOutputSetOfCTFTomoSeries() for ts in inputSetOfTiltSeries: tsId = ts.getTsId() tsFileName = ts.getFirstItem().parseFileName(extension='') for ctfFile, _ in self.iterFiles(): defocusFilePath = ctfFile defocusFileName = os.path.basename( os.path.splitext(ctfFile)[0]) if tsFileName == defocusFileName: print("Parsing file: " + defocusFilePath) defocusFileFlag = utils.getDefocusFileFlag(defocusFilePath) newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(ts) newCTFTomoSeries.setTiltSeries(ts) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setIMODDefocusFileFlag(defocusFileFlag) # We need to create now all the attributes of this object in order to append it to the set and be # able to update it posteriorly. newCTFTomoSeries.setNumberOfEstimationsInRange(None) self.outputSetOfCTFTomoSeries.append(newCTFTomoSeries) if defocusFileFlag == 0: " Plain estimation " defocusUDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 1: " Astigmatism estimation " defocusUDict, defocusVDict, defocusAngleDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 4: " Phase-shift information " defocusUDict, phaseShiftDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) else: raise Exception( "Defocus file flag do not supported. Only supported formats corresponding to flags 0, " "1, 4, 5, and 37.") for index, _ in enumerate(ts): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.setIndex(pwobj.Integer(index + 1)) if defocusFileFlag == 0: " Plain estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) elif defocusFileFlag == 1: " Astigmatism estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) elif defocusFileFlag == 4: " Phase-shift information " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) newCTFTomo._cutOnFreqList = pwobj.CsvList( pType=float) newCTFTomo.setCutOnFreqList(cutOnFreqDict[index + 1]) defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) newCTFTomo.completeInfoFromList() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList( ) newCTFTomoSeries.write(properties=False) self.outputSetOfCTFTomoSeries.update(newCTFTomoSeries) self.outputSetOfCTFTomoSeries.write() self._store()
def __init__(self, **kwargs): MockSet.__init__(self, **kwargs) self._micrographsPointer = pwobj.Pointer() self._boxSize = pwobj.Integer()