def refactorCTFDefocusPhaseShiftEstimationInfo(ctfInfoIMODTable): """ This method takes a table containing the information of an IMOD-based CTF estimation containing defocus, and phase shift information (6 columns) and produces a new set of dictionaries containing the same information in a format readable for Scipion. Flag 4. """ if len(ctfInfoIMODTable[0]) == 6: defocusUDict = {} phaseShiftDict = {} for element in ctfInfoIMODTable: # Segregate information from range for index in range(int(element[0]), int(element[1]) + 1): # Defocus U info if index in defocusUDict.keys(): defocusUDict[index].append(pwobj.Float(element[4])) else: defocusUDict[index] = [pwobj.Float(element[4])] # Phase shift info if index in phaseShiftDict.keys(): phaseShiftDict[index].append(pwobj.Float(element[5])) else: phaseShiftDict[index] = [pwobj.Float(element[5])] else: raise Exception("Misleading file format, CTF estimation with astigmatism and phase shift should be 6 columns " "long") return defocusUDict, phaseShiftDict
def _setMotionValues(self, movie, mic): """ Parse motion values from the 'corrected_micrographs.star' file generated for each movie. """ fn = self._getMovieExtraFn(movie, 'corrected_micrographs.star') table = md.Table(fileName=fn) row = table[0] mic._rlnAccumMotionTotal = pwobj.Float(row.rlnAccumMotionTotal) mic._rlnAccumMotionEarly = pwobj.Float(row.rlnAccumMotionEarly) mic._rlnAccumMotionLate = pwobj.Float(row.rlnAccumMotionLate)
def createOutputStep(self): out_vol = Volume() in_vol = self.inputVol.get() out_vol.setSamplingRate(in_vol.getSamplingRate()) out_vol.setFileName(self._getExtraPath("shift_volume.mrc")) self._defineOutputs(outputVolume=out_vol) self._defineOutputs(shiftX=pwobj.Float(self.shiftx), shiftY=pwobj.Float(self.shifty), shiftZ=pwobj.Float(self.shiftz)) self._defineSourceRelation(in_vol, out_vol)
def createOutput(self): volume = Volume() volume.setFileName(self.fnVolSym) volume.copyInfo(self.inputVolume.get()) self._defineOutputs(outputVolume=volume) self._defineTransformRelation(self.inputVolume, self.outputVolume) rot0, tilt0 = self.getAngles() self._defineOutputs(rotSym=pwobj.Float(rot0), tiltSym=pwobj.Float(tilt0))
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 refactorCTFDefocusAstigmatismPhaseShiftCutOnFreqEstimationInfo(ctfInfoIMODTable): """ This method takes a table containing the information of an IMOD-based CTF estimation containing defocus, astigmatism, phase shift information and cut-on frequency (8 columns) and produces a new set of dictionaries containing the same information in a format readable for Scipion. Flag 37. """ if len(ctfInfoIMODTable[0]) == 9: defocusUDict = {} defocusVDict = {} defocusAngleDict = {} phaseShiftDict = {} cutOnFreqDict = {} for element in ctfInfoIMODTable: # Segregate information from range for index in range(int(element[0]), int(element[1]) + 1): # Defocus U info if index in defocusUDict.keys(): defocusUDict[index].append(pwobj.Float(element[4])) else: defocusUDict[index] = [pwobj.Float(element[4])] # Defocus V info if index in defocusVDict.keys(): defocusVDict[index].append(pwobj.Float(element[5])) else: defocusVDict[index] = [pwobj.Float(element[5])] # Defocus angle info if index in defocusAngleDict.keys(): defocusAngleDict[index].append(pwobj.Float(element[6])) else: defocusAngleDict[index] = [pwobj.Float(element[6])] # Phase shift info if index in phaseShiftDict.keys(): phaseShiftDict[index].append(pwobj.Float(element[7])) else: phaseShiftDict[index] = [pwobj.Float(element[7])] # Cut-on frequency info if index in cutOnFreqDict.keys(): cutOnFreqDict[index].append(pwobj.Float(element[8])) else: cutOnFreqDict[index] = [pwobj.Float(element[8])] else: raise Exception("Misleading file format, CTF estiation with astigmatism, phase shift and cut-on frequency " "should be 8 columns long") return defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict
def createOutput(self): Ts = self.inputVolume.get().getSamplingRate() self.runJob("xmipp_image_header","-i %s --sampling_rate %f" %(self.fnVolSym,Ts)) volume = Volume() volume.setFileName(self.fnVolSym) volume.copyInfo(self.inputVolume.get()) self._defineOutputs(outputVolume=volume) self._defineTransformRelation(self.inputVolume, self.outputVolume) rot0, tilt0 = self.getAngles() self._defineOutputs(rotSym=pwobj.Float(rot0), tiltSym=pwobj.Float(tilt0))
def createOutput(self): volume = Volume() volume.setFileName(self._getPath('volume_symmetrized.vol')) #volume.setSamplingRate(self.inputVolume.get().getSamplingRate()) volume.copyInfo(self.inputVolume.get()) self._defineOutputs(outputVolume=volume) self._defineTransformRelation(self.inputVolume, self.outputVolume) md = MetaData(self._getExtraPath('fineParams.xmd')) objId = md.firstObject() self._defineOutputs(deltaRot=pwobj.Float( md.getValue(MDL_ANGLE_ROT, objId)), deltaZ=pwobj.Float(md.getValue(MDL_SHIFT_Z, objId)))
def createOutput(self): volume = Volume() volume.setFileName(self.fnVolSym) Ts = self.inputVolume.get().getSamplingRate() self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (self.fnVolSym, Ts)) volume.copyInfo(self.inputVolume.get()) self._defineOutputs(outputVolume=volume) self._defineTransformRelation(self.inputVolume, self.outputVolume) md = MetaData(self._getFileName('fine')) objId = md.firstObject() self._defineOutputs(deltaRot=pwobj.Float( md.getValue(MDL_ANGLE_ROT, objId)), deltaZ=pwobj.Float(md.getValue(MDL_SHIFT_Z, objId)))
def createOutputStep(self): """create output with the new particles""" self.ix = 0 inputParticles = self.inputParticles.get() outputSet = self._createSetOfParticles() outputSet.copyInfo(inputParticles) if self.boxSizeBool.get(): outputmd = self._getExtraPath("center_particles.xmd") else: outputmd = self._getExtraPath("crop_particles.xmd") readSetOfParticles(outputmd, outputSet) self._defineOutputs(outputParticles=outputSet) self._defineOutputs(shiftX=pwobj.Float(self.x), shiftY=pwobj.Float(self.y), shiftZ=pwobj.Float(self.z)) self._defineSourceRelation(inputParticles, outputSet)
def sortDockingResults(smallList): ds = [] le = [] leSA = [] leLn = [] for small in smallList: ds.append(small.dockingScore.get()) le.append(small.ligandEfficiency.get()) leSA.append(small.ligandEfficiencySA.get()) leLn.append(small.ligandEfficiencyLn.get()) iN = 100.0 / len(ds) ds = np.asarray(ds) le = np.asarray(le) leSA = np.asarray(leSA) leLn = np.asarray(leLn) h = np.zeros(len(ds)) i = 0 for small in smallList: hds = np.sum(ds >= small.dockingScore.get()) * iN hle = np.sum(le >= small.ligandEfficiency.get()) * iN hleSA = np.sum(leSA >= small.ligandEfficiencySA.get()) * iN hleLn = np.sum(leLn >= small.ligandEfficiencyLn.get()) * iN hi = -0.25 * (hds + hle + hleSA + hleLn) small.Hrank = pwobj.Float(hi) h[i] = hi i += 1 return np.argsort(h)
def __init__(self, **kwargs): MockSet.__init__(self, **kwargs) self._samplingRate = pwobj.Float() self._hasCtf = pwobj.Boolean(kwargs.get('ctf', False)) self._isPhaseFlipped = pwobj.Boolean(False) self._isAmplitudeCorrected = pwobj.Boolean(False) self._acquisition = MockAcquisition() self._firstDim = MockImageDim() # Dimensions of the first image
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 _defineParams(self, form): form.addSection(label='General parameters') form.addParam('inputVolume', PointerParam, pointerClass="Volume", label='Input volume') form.addParam('symOrder',IntParam, default=3, label='Symmetry order', help="3 for a three-fold symmetry axis, " "4 for a four-fold symmetry axis, ...") form.addParam('searchMode', EnumParam,label='Search mode', choices=['Global','Local','Global+Local'], default=self.GLOBAL_LOCAL_SEARCH) form.addParam('rot', FloatParam, default=0, condition='searchMode==%d' % self.LOCAL_SEARCH, label='Initial rotational angle', help="In degrees") form.addParam('tilt', FloatParam, default=0, condition='searchMode==%d' % self.LOCAL_SEARCH, label='Initial tilt angle', help="In degrees. tilt=0 is a top axis while " "tilt=90 defines a side axis") rot = form.addLine('Rotational angle', condition='searchMode!=%d' % self.LOCAL_SEARCH, help='Minimum, maximum and step values for ' 'rotational angle range, all in degrees.') rot.addParam('rot0', FloatParam, default=0, label='Min') rot.addParam('rotF', FloatParam, default=360, label='Max') rot.addParam('rotStep', FloatParam, default=5, label='Step') tilt = form.addLine('Tilt angle', condition='searchMode!=%d' % self.LOCAL_SEARCH, help='In degrees. tilt=0 is a top axis while ' 'tilt=90 defines a side axis') tilt.addParam('tilt0', FloatParam, default=0, label='Min') tilt.addParam('tiltF', FloatParam, default=180, label='Max') tilt.addParam('tiltStep', FloatParam, default=5, label='Step') self.rotSym = pwobj.Float() self.tiltSym = pwobj.Float() form.addParallelSection(threads=4, mpi=0)
def refactorCTFDefocusEstimationInfo(ctfInfoIMODTable): """ This method takes a table containing the information of an IMOD-based CTF estimation containing only defocus information (5 columns) and produces a new dictionary containing the same information in a format readable for Scipion. Flag 0. """ if len(ctfInfoIMODTable[0]) == 5: defocusUDict = {} for element in ctfInfoIMODTable: # Segregate information from range for index in range(int(element[0]), int(element[1]) + 1): if index in defocusUDict.keys(): defocusUDict[index].append(pwobj.Float(element[4])) else: defocusUDict[index] = [pwobj.Float(element[4])] else: raise Exception("Misleading file format, CTF estimation with no astigmatism should be 5 columns long") return defocusUDict
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, 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 createOutput(self): smallDict = {} for small in self.inputLibrary.get(): fnSmall = small.getFileName() fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0] if not fnBase in smallDict: smallDict[fnBase]=fnSmall grid = self.inputGrid.get() fnStruct = grid.structureFile.get() if hasattr(grid,"bindingSiteScore"): bindingSiteScore = grid.bindingSiteScore.get() else: bindingSiteScore = None if hasattr(grid,"bindingSiteDScore"): bindingSiteDScore = grid.bindingSiteDScore.get() else: bindingSiteDScore = None smallList = [] posesDir = self._getExtraPath('poses') makePath(posesDir) fhCsv = open(self._getPath('job_pv.csv')) fnPv = self._getPath('job_pv.maegz') i = 0 for line in fhCsv.readlines(): if i>1: tokens = line.split(',') small = SmallMolecule(smallMolFilename=smallDict[tokens[0]]) small.dockingScore = pwobj.Float(tokens[1]) small.ligandEfficiency = pwobj.Float(tokens[2]) small.ligandEfficiencySA = pwobj.Float(tokens[3]) small.ligandEfficiencyLn = pwobj.Float(tokens[4]) small.poseFile = pwobj.String("%d@%s"%(i,fnPv)) small.structFile = pwobj.String(fnStruct) if bindingSiteScore: small.bindingSiteScore = pwobj.Float(bindingSiteScore) if bindingSiteDScore: small.bindingSiteDScore = pwobj.Float(bindingSiteDScore) smallList.append(small) i+=1 fhCsv.close() idxSorted=sortDockingResults(smallList) outputSet = SetOfSmallMolecules().create(path=self._getPath()) for idx in idxSorted: small=smallList[idx] outputSet.append(small) self._defineOutputs(outputSmallMolecules=outputSet) self._defineSourceRelation(self.inputGrid, outputSet) self._defineSourceRelation(self.inputLibrary, outputSet) mae = SchrodingerPoses(filename=fnPv) self._defineOutputs(outputPoses=mae) self._defineSourceRelation(self.inputGrid, mae) self._defineSourceRelation(self.inputLibrary, mae)
def _fillVolSetFromIter(self, volSet, rLev=None, it=None): it = self._lastIter() if it is None else it rLev = self._rLev if rLev is None else rLev volSet.setSamplingRate(self._getInputParticles().getSamplingRate()) modelFn = self._getFileName('model', ruNum=rLev, iter=it) print('modelFn: ', modelFn) modelStar = md.MetaData('model_classes@' + modelFn) idList = [] volFnList = [] clsDistList = [] accRotList = [] accTransList = [] resoList = [] for row in md.iterRows(modelStar): accurracyRot = row.getValue('rlnAccuracyRotations') if accurracyRot <= 90: fn = row.getValue('rlnReferenceImage') print('Volume: ', fn) fnMrc = fn + ":mrc" itemId = self._getClassId(fn) classDistrib = row.getValue('rlnClassDistribution') accurracyTras = row.getValue('rlnAccuracyTranslations') resol = row.getValue('rlnEstimatedResolution') idList.append(itemId) volFnList.append(fnMrc) clsDistList.append(classDistrib) accRotList.append(accurracyRot) accTransList.append(accurracyTras) resoList.append(resol) std = self.std if hasattr(self, 'std') else None score = self._estimateScore(accRotList, clsDistList, None, std) threshold = 1 / float(self.numOfVols.get()) print("score: ", score) for i, s in enumerate(score): vol = Volume() self._invertScaleVol(volFnList[i]) vol.setFileName(self._getOutputVolFn(volFnList[i])) vol.setObjId(idList[i]) if s <= threshold: vol._objEnabled = False vol._cmScore = pwObj.Float(s) vol._rlnClassDistribution = Float(clsDistList[i]) vol._rlnAccuracyRotations = Float(accRotList[i]) vol._rlnAccuracyTranslations = Float(accTransList[i]) vol._rlnEstimatedResolution = Float(resoList[i]) volSet.append(vol)
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 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 __init__(self, **kwargs): MockObject.__init__(self, **kwargs) self._magnification = pwobj.Float(kwargs.get('magnification', None)) # Microscope voltage in kV self._voltage = pwobj.Float(kwargs.get('voltage', None)) # Spherical aberration in mm self._sphericalAberration = pwobj.Float(kwargs.get('sphericalAberration', None)) self._amplitudeContrast = pwobj.Float(kwargs.get('amplitudeContrast', None)) self._doseInitial = pwobj.Float(kwargs.get('doseInitial', 0)) self._dosePerFrame = pwobj.Float(kwargs.get('dosePerFrame', None))
def test_copyAttributes(self): """ Check that after copyAttributes, the values were properly copied. """ c1 = Complex(imag=10., real=11.) c2 = Complex(imag=0., real=1.0001) # Float values are different, should not be equal self.assertFalse(c1.equalAttributes(c2)) c2.copyAttributes(c1, 'imag', 'real') self.assertTrue(c1.equalAttributes(c2), 'Complex c1 and c2 have not equal attributes' '\nc1: %s\nc2: %s\n' % (c1, c2)) c1.score = pwobj.Float(1.) # If we copyAttributes again, score dynamic attribute should # be set in c2 c2.copyAttributes(c1, 'score') self.assertTrue(hasattr(c2, 'score'))
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 __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 refactorCTFDesfocusAstigmatismEstimationInfo(ctfInfoIMODTable): """ This method takes a table containing the information of an IMOD-based CTF estimation containing defocus and astigmatism information (7 columns) and produces a set of dictionaries table containing the same information in a format readable for Scipion. Flag 1. """ if len(ctfInfoIMODTable[0]) == 7: defocusUDict = {} defocusVDict = {} defocusAngleDict = {} for element in ctfInfoIMODTable: # Segregate information from range for index in range(int(element[0]), int(element[1]) + 1): # Defocus U info if index in defocusUDict.keys(): defocusUDict[index].append(pwobj.Float(element[4])) else: defocusUDict[index] = [pwobj.Float(element[4])] # Defocus V info if index in defocusVDict.keys(): defocusVDict[index].append(pwobj.Float(element[5])) else: defocusVDict[index] = [pwobj.Float(element[5])] # Defocus angle info if index in defocusAngleDict.keys(): defocusAngleDict[index].append(pwobj.Float(element[6])) else: defocusAngleDict[index] = [pwobj.Float(element[6])] else: raise Exception("Misleading file format, CTF estimation with astigmatism should be 7 columns long") return defocusUDict, defocusVDict, defocusAngleDict
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 _updateZScore(self, img, imgRow): zscore = imgRow.getValue(md.RLN_SELECT_PARTICLES_ZSCORE) img._rlnSelectParticlesZscore = pwobj.Float(zscore)
def rotateAstimatism(self, tsObjId): getTMTS = self.getTMSetOfTiltSeries.get()[tsObjId] tsId = getTMTS.getTsId() # inputCtfTomoSeries = self.inputSetOfCtfTomoSeries.get()[tsObjId] match = False for inputCtfTomoSeries in self.inputSetOfCtfTomoSeries.get(): if tsId == inputCtfTomoSeries.getTsId(): match = True self.getOutputSetOfCTFTomoSeries() newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(inputCtfTomoSeries) newCTFTomoSeries.setTiltSeries(getTMTS) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setObjId(tsObjId) newCTFTomoSeries.setIMODDefocusFileFlag(inputCtfTomoSeries.getIMODDefocusFileFlag()) newCTFTomoSeries.setNumberOfEstimationsInRange(inputCtfTomoSeries.getNumberOfEstimationsInRange()) self.outputSetOfCTFTomoSeries.append(newCTFTomoSeries) for index, (tiltImageGetTM, inputCtfTomo) in enumerate(zip(getTMTS, inputCtfTomoSeries)): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.copyInfo(inputCtfTomo) rotationAngle = utils.calculateRotationAngleFromTM(tiltImageGetTM) if newCTFTomo.hasAstigmatismInfoAsList(): defocusAngleList = pwobj.CsvList(pType=float) for angle in inputCtfTomo.getDefocusAngleList().split(','): defocusAngleList.append(pwobj.Float(round(float(angle)+rotationAngle,2))) newCTFTomo.setDefocusAngleList(defocusAngleList) newCTFTomo.completeInfoFromList() else: newCTFTomo.setDefocusAngle(pwobj.Float(inputCtfTomo.getDefocusAngle() + rotationAngle)) newCTFTomo.standardize() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList() newCTFTomoSeries.setIsDefocusUDeviationInRange(inputCtfTomoSeries.getIsDefocusUDeviationInRange()) newCTFTomoSeries.setIsDefocusVDeviationInRange(inputCtfTomoSeries.getIsDefocusVDeviationInRange()) if not (newCTFTomoSeries.getIsDefocusUDeviationInRange() and newCTFTomoSeries.getIsDefocusVDeviationInRange()): newCTFTomoSeries.setEnabled(False) newCTFTomoSeries.write(properties=False) self.outputSetOfCTFTomoSeries.update(newCTFTomoSeries) self.outputSetOfCTFTomoSeries.write() self._store() if not match: raise Exception("There is no matching CtfTomoSeries for a tilt-series %s" % (tsId))
def createOutputStep(self): outputSetBest = SetOfSmallMolecules().create(path=self._getPath(), suffix='Best') outputSet = SetOfSmallMolecules().create(path=self._getPath()) for smallMol in self.inputLibrary.get(): fnSmall = smallMol.getFileName() fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0] fnSmallDir = self._getExtraPath(fnBase) fnDlg = os.path.join(fnSmallDir, fnBase + ".dlg") if os.path.exists(fnDlg): args = " -d . -b -o bestDock.txt" self.runJob(bioinformatics_plugin.getMGLPath('bin/pythonsh'), bioinformatics_plugin.getADTPath( 'Utilities24/summarize_results4.py') + args, cwd=fnSmallDir) args = " -d . -o bestCluster.txt" self.runJob(bioinformatics_plugin.getMGLPath('bin/pythonsh'), bioinformatics_plugin.getADTPath( 'Utilities24/summarize_results4.py') + args, cwd=fnSmallDir) args = " -f %s.dlg -o %s_top.pdbqt" % (fnBase, fnBase) self.runJob(bioinformatics_plugin.getMGLPath('bin/pythonsh'), bioinformatics_plugin.getADTPath( 'Utilities24/write_lowest_energy_ligand.py') + args, cwd=fnSmallDir) newSmallMol = SmallMolecule() newSmallMol.copy(smallMol) fh = open(os.path.join(fnSmallDir, "bestDock.txt")) lineNo = 0 for line in fh.readlines(): if lineNo == 1: tokens = line.split(',') newSmallMol.dockingScoreLE = pwobj.Float( tokens[4].strip()) newSmallMol.ligandEfficiency = pwobj.Float( tokens[-1].strip()) newSmallMol.smallMoleculeFilePose = pwobj.String( os.path.join(fnSmallDir, "%s_top.pdbqt" % fnBase)) lineNo += 1 fh.close() outputSetBest.append(newSmallMol) fh = open(os.path.join(fnSmallDir, "bestCluster.txt")) lineNo = 0 for line in fh.readlines(): if lineNo >= 1: newSmallMol = SmallMolecule() newSmallMol.copy(smallMol) newSmallMol.cleanObjId() tokens = line.split(',') newSmallMol.dockingScoreLE = pwobj.Float( tokens[2].strip()) newSmallMol.ligandEfficiency = pwobj.Float( tokens[-1].strip()) outputSet.append(newSmallMol) lineNo += 1 fh.close() self._defineOutputs(outputSmallMolecules=outputSet) self._defineSourceRelation(self.inputGrid, outputSet) self._defineSourceRelation(self.inputLibrary, outputSet) self._defineOutputs(outputSmallMoleculesBest=outputSetBest) self._defineSourceRelation(self.inputGrid, outputSetBest) self._defineSourceRelation(self.inputLibrary, outputSetBest)