def visualizeClasses(self, e=None): prot = self.protocol classDir = prot.getClassDir() classAvg = 'classavg' classVar = 'classvar' classDoc = 'docclass' params = { '[class_dir]': classDir, '[desired-classes]': self.numberOfClasses.get(), '[particles]': prot._params['particles'] + '@******', '[class_doc]': join(classDir, classDoc + '***'), '[class_avg]': join(classDir, classAvg + '***'), '[class_var]': join(classDir, classVar + '***'), } prot.runTemplate('mda/classavg.msa', prot.getExt(), params) particles = prot.inputParticles.get() particles.load() sampling = particles.getSamplingRate() setFn = prot._getTmpPath('classes2D.sqlite') cleanPath(setFn) classes2D = SetOfClasses2D(filename=setFn) classes2D.setImages(particles) # We need to first create a map between the particles index and # the assigned class number classDict = {} for classId in range(1, self.numberOfClasses.get() + 1): docClass = prot._getPath(classDir, classDoc + '%03d.stk' % classId) doc = SpiderDocFile(docClass) for values in doc.iterValues(): imgIndex = int(values[0]) classDict[imgIndex] = classId doc.close() updateItem = lambda p, i: p.setClassId(classDict[i]) def updateClass(cls): rep = cls.getRepresentative() rep.setSamplingRate(particles.getSamplingRate()) avgFn = prot._getPath(classDir, classAvg + '%03d.stk' % cls.getObjId()) rep.setLocation(1, avgFn) particlesRange = range(1, particles.getSize() + 1) classes2D.classifyItems(updateItemCallback=updateItem, updateClassCallback=updateClass, itemDataIterator=iter(particlesRange)) classes2D.write() classes2D.close() return [ ClassesView(self.getProject(), prot.strId(), classes2D.getFileName(), particles.strId()) ]
def _iterAngles(self, it): """ Iterate over the angular distribution for a given iteration. """ # Get the alignment files of each group for this iteration files = glob(self._getFinalPath('align_%02d_???.stk' % it)) for anglesFile in files: fscDoc = SpiderDocFile(anglesFile) for values in fscDoc: yield values[1], values[2] fscDoc.close()
def visualizeClasses(self, e=None): prot = self.protocol classDir = prot.getClassDir() classAvg = 'classavg' classVar = 'classvar' classDoc = 'docclass' params = {'[class_dir]': classDir, '[desired-classes]': self.numberOfClasses.get(), '[particles]': prot._params['particles'] + '@******', '[class_doc]': join(classDir, classDoc + '***'), '[class_avg]': join(classDir, classAvg + '***'), '[class_var]': join(classDir, classVar + '***'), } prot.runTemplate('mda/classavg.msa', prot.getExt(), params) particles = prot.inputParticles.get() particles.load() sampling = particles.getSamplingRate() setFn = prot._getTmpPath('classes2D.sqlite') cleanPath(setFn) classes2D = SetOfClasses2D(filename=setFn) classes2D.setImages(particles) # We need to first create a map between the particles index and # the assigned class number classDict = {} for classId in range(1, self.numberOfClasses.get()+1): docClass = prot._getPath(classDir, classDoc + '%03d.stk' % classId) doc = SpiderDocFile(docClass) for values in doc.iterValues(): imgIndex = int(values[0]) classDict[imgIndex] = classId doc.close() updateItem = lambda p, i: p.setClassId(classDict[i]) def updateClass(cls): rep = cls.getRepresentative() rep.setSamplingRate(particles.getSamplingRate()) avgFn = prot._getPath(classDir, classAvg + '%03d.stk' % cls.getObjId()) rep.setLocation(1, avgFn) particlesRange = range(1, particles.getSize()+1) classes2D.classifyItems(updateItemCallback=updateItem, updateClassCallback=updateClass, itemDataIterator=iter(particlesRange)) classes2D.write() classes2D.close() return [ClassesView(self.getProject(), prot.strId(), classes2D.getFileName(), particles.strId())]
def visualizeClasses(self, e=None): prot = self.protocol classDir = prot.getClassDir() classAvg = 'classavg' classVar = 'classvar' classDoc = 'docclass' ext = prot.getExt() params = {'[class_dir]': classDir, '[desired-classes]': self.numberOfClasses.get(), '[particles]': prot._params['particles'] + '@******', '[class_doc]': join(classDir, classDoc + '***'), '[class_avg]': join(classDir, classAvg + '***'), '[class_var]': join(classDir, classVar + '***'), } prot.runTemplate('mda/classavg.msa', prot.getExt(), params) particles = prot.inputParticles.get() particles.load() sampling = particles.getSamplingRate() setFn = self._getPath('classes2D.sqlite') cleanPath(setFn) classes2D = SetOfClasses2D(filename=setFn) classes2D.setImages(particles) for classId in range(1, self.numberOfClasses.get()+1): class2D = Class2D() class2D.setObjId(classId) avgImg = Particle() avgImg.setSamplingRate(sampling) avgFn = prot._getPath(classDir, classAvg + '%03d.stk' % classId) avgImg.setLocation(1, avgFn) #avgImg.setLocation(classId, 'classavg.stk') class2D.setRepresentative(avgImg) classes2D.append(class2D) docClass = prot._getPath(classDir, classDoc + '%03d.stk' % classId) doc = SpiderDocFile(docClass) for values in doc.iterValues(): imgId = int(values[0]) img = particles[imgId] class2D.append(img) classes2D.update(class2D) classes2D.write() classes2D.close() return [ClassesView(self.getProject(), prot.strId(), classes2D.getFileName(), prot.inputParticles.get().strId())]
def _iterAngles(self, it): """ Iterate over the angular distribution for a given iteration. """ # Get the alignment files of each group for this iteration files = glob(self._getFinalPath('align_%02d_???.stk' % it)) for anglesFile in files: fscDoc = SpiderDocFile(anglesFile) for values in fscDoc: theta = values[1] phi = values[2] if theta > 90: theta = abs(180. - theta) phi += 180 yield phi, theta fscDoc.close()
def writeSetOfImages(imgSet, stackFn, selFn): """ This function will write a SetOfMicrographs as a Spider stack and selfile. Params: imgSet: the SetOfMicrograph instance. stackFn: the filename where to write the stack. selFn: the filename of the Spider selection file. """ doc = SpiderDocFile(selFn, 'w+') for i in range(imgSet.getSize()): doc.writeValues(i+1) imgSet.writeStack(stackFn, applyTransform=True) doc.close() convertEndian(stackFn, imgSet.getSize())
def writeSetOfImages(imgSet, stackFn, selFn): """ This function will write a SetOfMicrographs as a Spider stack and selfile. Params: imgSet: the SetOfMicrograph instance. stackFn: the filename where to write the stack. selFn: the filename of the Spider selection file. """ ih = ImageHandler() doc = SpiderDocFile(selFn, 'w+') for i, img in enumerate(imgSet): ih.convert(img, (i+1, stackFn)) doc.writeValues(i+1) doc.close() convertEndian(stackFn, imgSet.getSize())
def _plotFSC(self, a, fscFile): resolution = [] fsc = [] fscDoc = SpiderDocFile(fscFile) for values in fscDoc: resolution.append(1/values[1]) fsc.append(values[2]) self.maxfsc = max(fsc) self.minInv = min(resolution) self.maxInv = max(resolution) a.plot(resolution, fsc) from matplotlib.ticker import FuncFormatter a.xaxis.set_major_formatter(FuncFormatter(self._formatFreq)) a.set_ylim([-0.1, 1.1]) fscDoc.close()
def _plotFSC(self, a, fscFile): resolution = [] fsc = [] fscDoc = SpiderDocFile(fscFile) for values in fscDoc: resolution.append(1 / values[1]) fsc.append(values[2]) self.maxfsc = max(fsc) self.minInv = min(resolution) self.maxInv = max(resolution) a.plot(resolution, fsc) from matplotlib.ticker import FuncFormatter a.xaxis.set_major_formatter(FuncFormatter(self._formatFreq)) a.set_ylim([-0.1, 1.1]) fscDoc.close()
def writeSetOfImages(imgSet, stackFn, selFn): """ This function will write a SetOfMicrographs as a Spider stack and selfile. Params: imgSet: the SetOfMicrograph instance. stackFn: the filename where to write the stack. selFn: the filename of the Spider selection file. """ doc = SpiderDocFile(selFn, 'w+') for i in range(imgSet.getSize()): doc.writeValues(i + 1) imgSet.writeStack(stackFn, applyTransform=True) doc.close() convertEndian(stackFn, imgSet.getSize())