Exemplo n.º 1
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)
 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)
Exemplo n.º 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())]
                              
Exemplo n.º 4
0
 def _fillParticlesFromNodes(self, particles, nodeList):
     """ Create the SetOfClasses2D from the images of each node
     in the dendogram. 
     """
     img = Particle()
     
     for node in nodeList:
         if node.path:
             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)
                 particles.append(img)
Exemplo n.º 5
0
 def createOutputStep(self):
     """ Register the output (the alignment and the aligned particles.)
     """
     particles = self.inputParticles.get()
     # Create the output average image
     avg = Particle()
     avg.copyInfo(self.inputParticles.get())
     avg.setLocation(NO_INDEX, self.getAverage())
     self._defineOutputs(outputAverage=avg)
     self._defineSourceRelation(particles, avg)
     
     imgSet = self._createSetOfParticles()
     imgSet.copyInfo(particles)
     imgSet.setAlignment2D()
     outputStk = self._getFileName('particlesAligned')
     imgSet.readStack(outputStk, 
                      postprocessImage=lambda img: img.setTransform(Transform()))
     self._defineOutputs(outputParticles=imgSet)
     self._defineTransformRelation(particles, imgSet)
Exemplo n.º 6
0
    def createOutputStep(self):
        """ Register the output (the alignment and the aligned particles.)
        """
        outputStk = self._getFileName('particlesAligned')
        if not exists(outputStk):
            raise Exception('Ouptput stack %s not produced. ' % outputStk)
        particles = self.inputParticles.get()
        # Create the output average image
        avg = Particle()
        avg.copyInfo(self.inputParticles.get())
        avg.setLocation(NO_INDEX, self.getAverage())
        self._defineOutputs(outputAverage=avg)
        self._defineSourceRelation(self.inputParticles, avg)

        imgSet = self._createSetOfParticles()
        imgSet.copyInfo(particles)
        imgSet.setAlignment2D()

        imgSet.copyItems(particles,
                         updateItemCallback=self._updateItem,
                         itemDataIterator=iter(
                             range(1,
                                   particles.getSize() + 1)))

        self._defineOutputs(outputParticles=imgSet)
        self._defineTransformRelation(self.inputParticles, imgSet)
Exemplo n.º 7
0
    def createOutputStep(self):
        """ Register the output (the alignment and the aligned particles.)
        """
        outputStk = self._getFileName('particlesAligned')
        if not exists(outputStk):
            raise Exception('Ouptput stack %s not produced. ' % outputStk)
        particles = self.inputParticles.get()
        # Create the output average image
        avg = Particle()
        avg.copyInfo(self.inputParticles.get())
        avg.setLocation(NO_INDEX, self.getAverage())
        self._defineOutputs(outputAverage=avg)
        self._defineSourceRelation(self.inputParticles, avg)
        
        imgSet = self._createSetOfParticles()
        imgSet.copyInfo(particles)
        imgSet.setAlignment2D()

        imgSet.copyItems(particles,
                         updateItemCallback=self._updateItem,
                         itemDataIterator=iter(range(1, particles.getSize()+1)))

        self._defineOutputs(outputParticles=imgSet)
        self._defineTransformRelation(self.inputParticles, imgSet)