def createOutputStep(self):
     """ Create the SetOfClass from the docfiles with the images-class
     assigment, the averages for each class.
     """
     particles = self.inputParticles.get()
     sampling = particles.getSamplingRate()
     classes2D = self._createSetOfClasses2D(particles)
         
     for classId in range(1, self.numberOfClasses.get()+1):
         class2D = Class2D()
         class2D.setObjId(classId)
         
         avgImg = Particle()
         avgImg.setSamplingRate(sampling)
         avgFn = self._getPath(self.getClassDir(), 'classavg%03d.stk' % classId)
         avgImg.setLocation(1, avgFn)
         
         class2D.setRepresentative(avgImg)
         classes2D.append(class2D)
         
         docClass = self._getPath(self.getClassDir(), 
                                  'docclass%03d.stk' % classId)
         doc = SpiderDocFile(docClass)
         
         for values in doc.iterValues():
             imgId = int(values[0])
             img = particles[imgId]
             class2D.append(img)
             
     self._defineOutputs(outputClasses=classes2D)
     self._defineSourceRelation(self.inputParticles, classes2D)
Пример #2
0
 def _fillClassesFromNodes(self, classes, nodeList):
     """ Create the SetOfClasses2D from the images of each node
     in the dendogram. 
     """
     img = Particle()
     sampling = classes.getSamplingRate()
     
     for node in nodeList:
         if node.path:
             #print "node.path: ", node.path
             class2D = Class2D()
             avg = Particle()
             #avg.copyObjId(class2D)
             avg.setLocation(node.avgCount, self.dendroAverages)
             avg.setSamplingRate(sampling)
             
             class2D.setRepresentative(avg)
             class2D.setSamplingRate(sampling)
             classes.append(class2D)
             #print "class2D.id: ", class2D.getObjId()
             for i in node.imageList:
                 #img.setObjId(i) # FIXME: this is wrong if the id is different from index
                 img.cleanObjId()
                 img.setLocation(int(i), self.dendroImages)
                 class2D.append(img)
             
             classes.update(class2D)
Пример #3
0
    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())]