Exemplo n.º 1
0
    def _visualize(self, obj, **kwargs):
        cls = type(obj)
        if issubclass(cls, SetOfNormalModes):
            fn = obj.getFileName()
            from .viewer_nma import OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD
            objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD)
            self._views.append(
                ObjectView(self._project,
                           self.protocol.strId(),
                           fn,
                           obj.strId(),
                           viewParams={OBJCMDS: objCommands},
                           **kwargs))

        elif issubclass(cls, XmippProtCTFMicrographs):
            if obj.hasAttribute('outputCTF'):
                ctfSet = obj.outputCTF
            else:
                mics = obj.inputMicrographs.get()
                ctfSet = self.__createTemporaryCtfs(obj, mics)

            if ctfSet.isEmpty():
                self._views.append(
                    self.infoMessage("No CTF estimation has finished yet"))
            else:
                self.getCTFViews(ctfSet)

        elif (issubclass(cls, XmippProtExtractParticles)
              or issubclass(cls, XmippProtScreenParticles)):
            particles = obj.outputParticles
            self._visualize(particles)

            fn = obj._getPath('images.xmd')
            if os.path.exists(fn):  # it doesnt unless cls is Xmipp
                md = xmippLib.MetaData(fn)
                # If Zscore on output images plot Zscore particle sorting
                if md.containsLabel(xmippLib.MDL_ZSCORE):
                    from plotter import XmippPlotter
                    xplotter = XmippPlotter(
                        windowTitle="Zscore particles sorting")
                    xplotter.createSubPlot("Particle sorting",
                                           "Particle number", "Zscore")
                    xplotter.plotMd(md, False, mdLabelY=xmippLib.MDL_ZSCORE)
                    self._views.append(xplotter)
                # If VARscore on output images plot VARscore particle sorting
                if md.containsLabel(xmippLib.MDL_SCORE_BY_VAR):
                    from plotter import XmippPlotter
                    xplotter = XmippPlotter(
                        windowTitle="Variance particles sorting")
                    xplotter.createSubPlot("Variance Histogram", "Variance",
                                           "Number of particles")
                    xplotter.plotMd(md,
                                    False,
                                    mdLabelY=xmippLib.MDL_SCORE_BY_VAR,
                                    nbins=100)
                    self._views.append(xplotter)

        elif issubclass(cls, XmippProtDeepDenoising):
            fn = obj.outputParticles.getFileName()
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               VISIBLE:
                               'enabled id _filename '
                               '_xmipp_corrDenoisedProjection '
                               '_xmipp_corrDenoisedNoisy '
                               '_xmipp_imageOriginal _xmipp_imageRef',
                               SORT_BY:
                               'id',
                               MODE:
                               MODE_MD
                           }))

        elif issubclass(cls, XmippProtMovieGain):
            self._visualize(obj.outputMovies)
            movieGainMonitor = MonitorMovieGain(
                obj,
                workingDir=obj.workingDir.get(),
                samplingInterval=60,
                monitorTime=300,
                stddevValue=0.04,
                ratio1Value=1.15,
                ratio2Value=4.5)
            self._views.append(MovieGainMonitorPlotter(movieGainMonitor))

        elif issubclass(cls, XmippProtRotSpectra):
            self._visualize(
                obj.outputClasses,
                viewParams={
                    'columns': obj.SomXdim.get(),
                    RENDER: ' spectraPlot._filename average._filename',
                    ZOOM: 30,
                    VISIBLE:
                    'enabled id _size average._filename spectraPlot._filename',
                    'labels': 'id _size',
                    SORT_BY: 'id'
                })

        elif issubclass(cls, XmippProtKerdensom):
            self._visualize(obj.outputClasses,
                            viewParams={
                                'columns': obj.SomXdim.get(),
                                'render':
                                'average._filename _representative._filename',
                                'labels': '_size',
                                'sortby': 'id'
                            })

        elif issubclass(cls, XmippProtCompareReprojections):
            fn = obj.outputParticles.getFileName()
            labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY'
            labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename"
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               SORT_BY: '_xmipp_cost asc',
                               RENDER: labelRender,
                               MODE: MODE_MD
                           }))

        elif issubclass(cls, XmippProtCompareAngles):
            fn = obj.outputParticles.getFileName()
            labels = 'id enabled _index _filename _xmipp_shiftDiff _xmipp_angleDiff'
            labelRender = "_filename"
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               SORT_BY: '_xmipp_angleDiff asc',
                               RENDER: labelRender,
                               MODE: MODE_MD
                           }))

        elif issubclass(cls, XmippParticlePickingAutomatic):
            micSet = obj.getInputMicrographs()
            mdFn = getattr(micSet, '_xmippMd', None)
            inTmpFolder = False
            if mdFn:
                micsfn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                micsfn = self._getTmpPath(micSet.getName() +
                                          '_micrographs.xmd')
                writeSetOfMicrographs(micSet, micsfn)
                inTmpFolder = True

            posDir = obj._getExtraPath()
            memory = showj.getJvmMaxMemory()
            launchSupervisedPickerGUI(micsfn,
                                      posDir,
                                      obj,
                                      mode='review',
                                      memory=memory,
                                      inTmpFolder=inTmpFolder)

        elif issubclass(cls, XmippProtParticleBoxsize):
            """ Launching a Coordinates viewer with only one coord in the center
                with the estimated boxsize.
            """
            micSet = obj.inputMicrographs.get()

            coordsFn = self._getTmpPath(micSet.getName() +
                                        '_coords_to_view.sqlite')
            if not os.path.exists(coordsFn):
                # Just creating the coords once
                coordsSet = SetOfCoordinates(filename=coordsFn)
                coordsSet.setBoxSize(obj.boxsize)
                for mic in micSet:
                    coord = Coordinate()
                    coord.setMicrograph(mic)
                    coord.setPosition(mic.getXDim() / 2, mic.getYDim() / 2)
                    coordsSet.append(coord)
                coordsSet.write()
            else:
                coordsSet = SetOfCoordinates(filename=coordsFn)
                coordsSet.loadAllProperties()

            coordsSet.setMicrographs(micSet)
            coordsSet.setName(micSet.getName())
            self._visualize(coordsSet)

        # We need this case to happens before the ProtParticlePicking one
        elif issubclass(cls, XmippProtAssignmentTiltPair):
            if obj.getOutputsSize() >= 1:
                coordsSet = obj.getCoordsTiltPair()
                self._visualize(coordsSet)

        elif issubclass(cls, XmippProtValidateNonTilt):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weight'
            self._views.append(
                ObjectView(self._project,
                           outputVols.strId(),
                           outputVols.getFileName(),
                           viewParams={
                               MODE: MODE_MD,
                               VISIBLE: labels,
                               ORDER: labels,
                               SORT_BY: 'weight desc',
                               RENDER: '_filename'
                           }))

        elif issubclass(cls, XmippProtMultiRefAlignability):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weightAlignabilityPrecision weightAlignabilityAccuracy'
            self._views.append(
                ObjectView(self._project,
                           outputVols.strId(),
                           outputVols.getFileName(),
                           viewParams={
                               MODE: MODE_MD,
                               VISIBLE: labels,
                               ORDER: labels,
                               SORT_BY: 'weightAlignabilityAccuracy desc',
                               RENDER: '_filename'
                           }))

            fn = obj.outputParticles.getFileName()
            labels = 'id enabled _index _filename _xmipp_scoreAlignabilityAccuracy _xmipp_scoreAlignabilityPrecision'
            labelRender = "_filename"
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               SORT_BY:
                               '_xmipp_scoreAlignabilityAccuracy desc',
                               RENDER: labelRender,
                               MODE: MODE_MD
                           }))

            fn = obj._getExtraPath('vol001_pruned_particles_alignability.xmd')
            md = xmippLib.MetaData(fn)
            from .plotter import XmippPlotter
            plotter = XmippPlotter()
            plotter.createSubPlot('Soft-alignment validation plot',
                                  'Angular Precision', 'Angular Accuracy')
            plotter.plotMdFile(md,
                               xmippLib.MDL_SCORE_BY_ALIGNABILITY_PRECISION,
                               xmippLib.MDL_SCORE_BY_ALIGNABILITY_ACCURACY,
                               marker='.',
                               markersize=.55,
                               color='red',
                               linestyle='')
            self._views.append(plotter)

        elif issubclass(cls, XmippProtExtractParticlesPairs):
            self._visualize(obj.outputParticlesTiltPair)

        else:
            # Use default visualization defined in base class
            DataViewer._visualize(self, obj, **kwargs)

        return self._views
Exemplo n.º 2
0
    def _visualize(self, obj, **args):
        cls = type(obj)

        if issubclass(cls, Volume):
            fn = getImageLocation(obj)
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={RENDER: 'image',
                                                      SAMPLINGRATE: obj.getSamplingRate()}))
                 
        elif issubclass(cls, Image):
            fn = getImageLocation(obj)
            
            self._views.append(ObjectView(self._project, obj.strId(), fn))
            
        elif issubclass(cls, SetOfNormalModes):
            fn = obj.getFileName()
            objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD)
            self._views.append(ObjectView(self._project,  self.protocol.strId(),
                                          fn, obj.strId(),
                                          viewParams={OBJCMDS: objCommands}, **args))

        elif issubclass(cls, SetOfMovies):
            fn = obj.getFileName()
            # Enabled for the future has to be available
            labels = 'id _filename _samplingRate  '
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      MODE: MODE_MD, RENDER: "no"}))

        elif issubclass(cls, SetOfMicrographs):            
            fn = obj.getFileName()
            self._views.append(ObjectView(self._project, obj.strId(), fn, **args))
            

        elif issubclass(cls, MicrographsTiltPair):          
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(),
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      MODE: MODE_MD,
                                                      RENDER: '_untilted._filename _tilted._filename'}))
            
        elif issubclass(cls, ParticlesTiltPair):          
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(),
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels,
                                                      RENDER:'_untilted._filename _tilted._filename',
                                                      MODE: MODE_MD}))

        elif issubclass(cls, SetOfCoordinates):
            micSet = obj.getMicrographs()  # accessing mics to provide metadata file
            if micSet is None:
                raise Exception('visualize: SetOfCoordinates has no micrographs set.')
            
            mdFn = getattr(micSet, '_xmippMd', None)
            if mdFn:
                fn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                fn = self._getTmpPath(micSet.getName() + '_micrographs.xmd')
                writeSetOfMicrographs(micSet, fn)
            tmpDir = self._getTmpPath(obj.getName())
            cleanPath(tmpDir)
            makePath(tmpDir)
            # FIXME: (JMRT) We are always writing the SetOfCoordinates and removing
            # the tmpDir, we need to take into account if the user have pick
            # some particles in the tmpDir and have not save them, that now
            # will loose all picked particles.
            # A possible solution could be to alert that changes have not been
            # written during modification of tmpDir or create a new Xmipp picking
            # protocol to continue picking later without loosing the coordinates.
            writeSetOfCoordinates(tmpDir, obj)
            self._views.append(CoordinatesObjectView(self._project, fn, tmpDir, self.protocol, inTmpFolder=True))

        elif issubclass(cls, SetOfParticles):
            fn = obj.getFileName()
            labels = 'id enabled _index _filename _xmipp_zScore _xmipp_cumulativeSSNR _sampling '
            labels += '_ctfModel._defocusU _ctfModel._defocusV _ctfModel._defocusAngle _transform._matrix'
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      'sortby': '_xmipp_zScore asc',
                                                      RENDER:'_filename'}))
               
        elif issubclass(cls, SetOfVolumes):
            fn = obj.getFileName()
            labels = 'id enabled comment _filename '
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={MODE: MODE_MD,
                                                      ORDER: labels,
                                                      VISIBLE: labels,
                                                      RENDER: '_filename'}))
        
        elif issubclass(cls, SetOfClasses2D):
            fn = obj.getFileName()
            self._views.append(ClassesView(self._project, obj.strId(), fn, **args))
            
        elif issubclass(cls, SetOfClasses3D):
            fn = obj.getFileName()
            self._views.append(Classes3DView(self._project, obj.strId(), fn))
        
        if issubclass(cls, XmippProtCTFMicrographs):
            if obj.hasAttribute('outputCTF'):
                ctfSet = obj.outputCTF
            else:
                mics = obj.inputMicrographs.get()
                ctfSet = self.__createTemporaryCtfs(obj, mics)

            if ctfSet.isEmpty():
                self._views.append(self.infoMessage("No CTF estimation has finished yet"))
            else:
                self._views.append(CtfView(self._project, ctfSet))

        elif issubclass(cls, SetOfCTF):
            self._views.append(CtfView(self._project, obj))

        elif issubclass(cls, CoordinatesTiltPair):
            tmpDir = self._getTmpPath(obj.getName()) 
            makePath(tmpDir)

            mdFn = join(tmpDir, 'input_micrographs.xmd')
            writeSetOfMicrographsPairs(obj.getUntilted().getMicrographs(),
                                        obj.getTilted().getMicrographs(), 
                                        mdFn) 
            parentProtId = obj.getObjParentId()
            parentProt = self.getProject().mapper.selectById(parentProtId)
            extraDir = parentProt._getExtraPath()
            
 #           extraDir = parentProt._getExtraPath()
            #TODO: Review this if ever a non Xmipp CoordinatesTiltPair is available
            writeSetOfCoordinates(tmpDir, obj.getUntilted()) 
            writeSetOfCoordinates(tmpDir, obj.getTilted()) 
            launchTiltPairPickerGUI(mdFn, tmpDir, self.protocol)
         
        elif issubclass(cls, XmippProtExtractParticles) or issubclass(cls, XmippProtScreenParticles):
            particles = obj.outputParticles
            self._visualize(particles)
            
            fn = obj._getPath('images.xmd')
            md = xmipp.MetaData(fn) 
            # If Zscore on output images plot Zscore particle sorting
            if md.containsLabel(xmipp.MDL_ZSCORE):
                from plotter import XmippPlotter
                xplotter = XmippPlotter(windowTitle="Zscore particles sorting")
                xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore")
                xplotter.plotMd(md, False, mdLabelY=xmipp.MDL_ZSCORE)
                self._views.append(xplotter)
    
        elif issubclass(cls, XmippProtRotSpectra):
            self._visualize(obj.outputClasses,
                            viewParams={'columns': obj.SomXdim.get(),
                                        RENDER: ' spectraPlot._filename average._filename',
                                        ZOOM: 30,
                                        VISIBLE:  'enabled id _size average._filename spectraPlot._filename',
                                        'labels': 'id _size',
                                        SORT_BY: 'id'})
        
        elif issubclass(cls, XmippProtKerdensom):
            self._visualize(obj.outputClasses, viewParams={'columns': obj.SomXdim.get(),
                                                           'render': 'average._filename _representative._filename',
                                                           'labels': '_size',
                                                           'sortby': 'id'})
        

        
        elif issubclass(cls, XmippProtCompareReprojections):
                fn = obj.outputParticles.getFileName()
                labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY'
                labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename"
                self._views.append(ObjectView(self._project, obj.outputParticles.strId(), fn,
                                              viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      SORT_BY: '_xmipp_cost asc', RENDER:labelRender,
                                                      MODE: MODE_MD}))
            
        elif issubclass(cls, XmippParticlePickingAutomatic):
            micSet = obj.getInputMicrographs()
            mdFn = getattr(micSet, '_xmippMd', None)
            inTmpFolder = False
            if mdFn:
                micsfn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                micsfn = self._getTmpPath(micSet.getName() + '_micrographs.xmd')
                writeSetOfMicrographs(micSet, micsfn)
                inTmpFolder = True
                
            posDir = obj._getExtraPath()  
            memory = '%dg'%obj.memory.get(), 
            launchSupervisedPickerGUI(micsfn, posDir, obj, mode='review', memory=memory, inTmpFolder=inTmpFolder)

         # We need this case to happens before the ProtParticlePicking one
        elif issubclass(cls, XmippProtAssignmentTiltPair):
            if obj.getOutputsSize() >= 1:
                coordsSet = obj.getCoordsTiltPair()
                self._visualize(coordsSet)  
                
        elif issubclass(cls, ProtParticlePicking):
            if obj.getOutputsSize() >= 1:
                coordsSet = obj.getCoords()
                self._visualize(coordsSet)
            
        elif issubclass(cls, ProtMovieAlignment):
            outputMics = obj.outputMicrographs
            plotLabels = 'psdCorr._filename plotPolar._filename plotCart._filename'
            labels = plotLabels + ' _filename '
            objCommands = "'%s'" % (OBJCMD_MOVIE_ALIGNCARTESIAN)
            
            self._views.append(ObjectView(self._project, self.protocol.strId(), outputMics.getFileName(),
                                          viewParams={MODE: MODE_MD, ORDER: labels, VISIBLE: labels,
                                                      RENDER: plotLabels, ZOOM: 50,
                                                      OBJCMDS: objCommands}))
        
        elif issubclass(cls, XmippProtValidateNonTilt):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weight'
            self._views.append(ObjectView(self._project, outputVols.strId(), outputVols.getFileName(),
                                          viewParams={MODE: MODE_MD, VISIBLE:labels, ORDER: labels,
                                                      SORT_BY: 'weight desc', RENDER: '_filename'}))

        elif issubclass(cls, XmippProtExtractParticlesPairs):
            self._visualize(obj.outputParticlesTiltPair)

        return self._views
Exemplo n.º 3
0
    def _visualize(self, obj, **kwargs):
        cls = type(obj)

        if issubclass(cls, Volume):
            fn = getImageLocation(obj)
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           fn,
                           viewParams={
                               RENDER: 'image',
                               SAMPLINGRATE: obj.getSamplingRate()
                           }))

        elif issubclass(cls, Image):
            fn = getImageLocation(obj)
            self._views.append(ObjectView(self._project, obj.strId(), fn))

        elif issubclass(cls, SetOfNormalModes):
            fn = obj.getFileName()
            from nma.viewer_nma import OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD
            objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD)
            self._views.append(
                ObjectView(self._project,
                           self.protocol.strId(),
                           fn,
                           obj.strId(),
                           viewParams={OBJCMDS: objCommands},
                           **kwargs))

        elif issubclass(cls, SetOfMovies):
            fn = obj.getFileName()
            # Enabled for the future has to be available
            labels = 'id _filename _samplingRate  '
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               MODE: MODE_MD,
                               RENDER: "no"
                           }))

        elif issubclass(cls, SetOfMicrographs):
            self._views.append(MicrographsView(self._project, obj, **kwargs))

        elif issubclass(cls, MicrographsTiltPair):
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           obj.getFileName(),
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               MODE: MODE_MD,
                               RENDER: '_untilted._filename _tilted._filename'
                           }))

        elif issubclass(cls, ParticlesTiltPair):
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           obj.getFileName(),
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               RENDER: '_untilted._filename _tilted._filename',
                               MODE: MODE_MD
                           }))

        elif issubclass(cls, SetOfCoordinates):
            micSet = obj.getMicrographs(
            )  # accessing mics to provide metadata file
            if micSet is None:
                raise Exception(
                    'visualize: SetOfCoordinates has no micrographs set.')

            mdFn = getattr(micSet, '_xmippMd', None)
            if mdFn:
                fn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                fn = self._getTmpPath(micSet.getName() + '_micrographs.xmd')
                writeSetOfMicrographs(micSet, fn)
            tmpDir = self._getTmpPath(obj.getName())
            cleanPath(tmpDir)
            makePath(tmpDir)
            # FIXME: (JMRT) We are always writing the SetOfCoordinates and removing
            # the tmpDir, we need to take into account if the user have pick
            # some particles in the tmpDir and have not save them, that now
            # will loose all picked particles.
            # A possible solution could be to alert that changes have not been
            # written during modification of tmpDir or create a new Xmipp picking
            # protocol to continue picking later without loosing the coordinates.
            writeSetOfCoordinates(tmpDir, obj)
            self._views.append(
                CoordinatesObjectView(self._project,
                                      fn,
                                      tmpDir,
                                      self.protocol,
                                      inTmpFolder=True))

        elif issubclass(cls, SetOfParticles):
            fn = obj.getFileName()
            labels = 'id enabled _index _filename _xmipp_zScore _xmipp_cumulativeSSNR _sampling '
            labels += '_ctfModel._defocusU _ctfModel._defocusV _ctfModel._defocusAngle _transform._matrix'
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               'sortby': '_xmipp_zScore asc',
                               RENDER: '_filename'
                           }))

        elif issubclass(cls, SetOfVolumes):
            fn = obj.getFileName()
            labels = 'id enabled comment _filename '
            self._views.append(
                ObjectView(self._project,
                           obj.strId(),
                           fn,
                           viewParams={
                               MODE: MODE_MD,
                               ORDER: labels,
                               VISIBLE: labels,
                               RENDER: '_filename'
                           }))

        elif issubclass(cls, SetOfClasses2D):
            fn = obj.getFileName()
            self._views.append(
                ClassesView(self._project, obj.strId(), fn, **kwargs))

        elif issubclass(cls, SetOfClasses3D):
            fn = obj.getFileName()
            self._views.append(Classes3DView(self._project, obj.strId(), fn))

        elif issubclass(cls, SetOfImages):
            fn = obj.getFileName()
            self._views.append(
                ObjectView(self._project, obj.strId(), fn, **kwargs))

        if issubclass(cls, XmippProtCTFMicrographs):
            if obj.hasAttribute('outputCTF'):
                ctfSet = obj.outputCTF
            else:
                mics = obj.inputMicrographs.get()
                ctfSet = self.__createTemporaryCtfs(obj, mics)

            if ctfSet.isEmpty():
                self._views.append(
                    self.infoMessage("No CTF estimation has finished yet"))
            else:
                self._views.append(CtfView(self._project, ctfSet))

        elif issubclass(cls, SetOfCTF):
            self._views.append(CtfView(self._project, obj))

        elif issubclass(cls, CoordinatesTiltPair):
            tmpDir = self._getTmpPath(obj.getName())
            makePath(tmpDir)

            mdFn = join(tmpDir, 'input_micrographs.xmd')
            writeSetOfMicrographsPairs(obj.getUntilted().getMicrographs(),
                                       obj.getTilted().getMicrographs(), mdFn)
            parentProtId = obj.getObjParentId()
            parentProt = self.getProject().mapper.selectById(parentProtId)
            extraDir = parentProt._getExtraPath()

            #           extraDir = parentProt._getExtraPath()
            #TODO: Review this if ever a non Xmipp CoordinatesTiltPair is available
            writeSetOfCoordinates(tmpDir, obj.getUntilted())
            writeSetOfCoordinates(tmpDir, obj.getTilted())
            launchTiltPairPickerGUI(mdFn, tmpDir, self.protocol)

        elif (issubclass(cls, XmippProtExtractParticles)
              or issubclass(cls, XmippProtScreenParticles)):
            particles = obj.outputParticles
            self._visualize(particles)

            fn = obj._getPath('images.xmd')
            if os.path.exists(fn):  # it doesnt unless cls is Xmipp
                md = xmipp.MetaData(fn)
                # If Zscore on output images plot Zscore particle sorting
                if md.containsLabel(xmipp.MDL_ZSCORE):
                    from plotter import XmippPlotter
                    xplotter = XmippPlotter(
                        windowTitle="Zscore particles sorting")
                    xplotter.createSubPlot("Particle sorting",
                                           "Particle number", "Zscore")
                    xplotter.plotMd(md, False, mdLabelY=xmipp.MDL_ZSCORE)
                    self._views.append(xplotter)

        elif issubclass(cls, XmippProtRotSpectra):
            self._visualize(
                obj.outputClasses,
                viewParams={
                    'columns': obj.SomXdim.get(),
                    RENDER: ' spectraPlot._filename average._filename',
                    ZOOM: 30,
                    VISIBLE:
                    'enabled id _size average._filename spectraPlot._filename',
                    'labels': 'id _size',
                    SORT_BY: 'id'
                })

        elif issubclass(cls, XmippProtKerdensom):
            self._visualize(obj.outputClasses,
                            viewParams={
                                'columns': obj.SomXdim.get(),
                                'render':
                                'average._filename _representative._filename',
                                'labels': '_size',
                                'sortby': 'id'
                            })

        elif issubclass(cls, XmippProtCompareReprojections):
            fn = obj.outputParticles.getFileName()
            labels = 'id enabled _index _xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename _xmipp_cost _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _xmipp_continuousA _xmipp_continuousB _xmipp_continuousX _xmipp_continuousY'
            labelRender = "_xmipp_image._filename _xmipp_imageRef._filename _xmipp_imageResidual._filename _xmipp_imageCovariance._filename"
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               SORT_BY: '_xmipp_cost asc',
                               RENDER: labelRender,
                               MODE: MODE_MD
                           }))

        elif issubclass(cls, XmippParticlePickingAutomatic):
            micSet = obj.getInputMicrographs()
            mdFn = getattr(micSet, '_xmippMd', None)
            inTmpFolder = False
            if mdFn:
                micsfn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                micsfn = self._getTmpPath(micSet.getName() +
                                          '_micrographs.xmd')
                writeSetOfMicrographs(micSet, micsfn)
                inTmpFolder = True

            posDir = obj._getExtraPath()
            memory = '%dg' % obj.memory.get(),
            launchSupervisedPickerGUI(micsfn,
                                      posDir,
                                      obj,
                                      mode='review',
                                      memory=memory,
                                      inTmpFolder=inTmpFolder)

        # We need this case to happens before the ProtParticlePicking one
        elif issubclass(cls, XmippProtAssignmentTiltPair):
            if obj.getOutputsSize() >= 1:
                coordsSet = obj.getCoordsTiltPair()
                self._visualize(coordsSet)

        elif issubclass(cls, ProtParticlePicking):
            if obj.getOutputsSize() >= 1:
                coordsSet = obj.getCoords()
                self._visualize(coordsSet)

        elif issubclass(cls, XmippProtValidateNonTilt):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weight'
            self._views.append(
                ObjectView(self._project,
                           outputVols.strId(),
                           outputVols.getFileName(),
                           viewParams={
                               MODE: MODE_MD,
                               VISIBLE: labels,
                               ORDER: labels,
                               SORT_BY: 'weight desc',
                               RENDER: '_filename'
                           }))

        elif issubclass(cls, XmippProtMultiRefAlignability):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weightAlignabilityPrecision weightAlignabilityAccuracy'
            self._views.append(
                ObjectView(self._project,
                           outputVols.strId(),
                           outputVols.getFileName(),
                           viewParams={
                               MODE: MODE_MD,
                               VISIBLE: labels,
                               ORDER: labels,
                               SORT_BY: 'weightAlignabilityAccuracy desc',
                               RENDER: '_filename'
                           }))

            fn = obj.outputParticles.getFileName()
            labels = 'id enabled _index _filename _xmipp_scoreAlignabilityAccuracy _xmipp_scoreAlignabilityPrecision'
            labelRender = "_filename"
            self._views.append(
                ObjectView(self._project,
                           obj.outputParticles.strId(),
                           fn,
                           viewParams={
                               ORDER: labels,
                               VISIBLE: labels,
                               SORT_BY:
                               '_xmipp_scoreAlignabilityAccuracy desc',
                               RENDER: labelRender,
                               MODE: MODE_MD
                           }))

            fn = obj._getExtraPath('vol001_pruned_particles_alignability.xmd')
            md = xmipp.MetaData(fn)
            from plotter import XmippPlotter
            from pyworkflow.em.plotter import EmPlotter
            plotter = XmippPlotter()
            plotter.createSubPlot('Soft-alignment validation plot',
                                  'Angular Precision', 'Angular Accuracy')
            plotter.plotMdFile(md,
                               xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION,
                               xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY,
                               marker='.',
                               markersize=.55,
                               color='red',
                               linestyle='')
            self._views.append(plotter)

        elif issubclass(cls, XmippProtExtractParticlesPairs):
            self._visualize(obj.outputParticlesTiltPair)

        return self._views
Exemplo n.º 4
0
    def _visualize(self, obj, **args):
        cls = type(obj)
        def _getMicrographDir(mic):
            """ Return an unique dir name for results of the micrograph. """
            return obj._getExtraPath(removeBaseExt(mic.getFileName()))        
    
        def iterMicrographs(mics):
            """ Iterate over micrographs and yield
            micrograph name and a directory to process.
            """
            for mic in mics:
                micFn = mic.getFileName()
                micDir = _getMicrographDir(mic) 
                yield (micFn, micDir, mic)
    
        def visualizeCTFObjs(obj, setOfMics):
            
            if exists(obj._getPath("ctfs_temporary.sqlite")):
                os.remove(obj._getPath("ctfs_temporary.sqlite"))
            self.protocol._createFilenameTemplates()
            
            ctfSet = self.protocol._createSetOfCTF("_temporary")
            
            for fn, micDir, mic in iterMicrographs(setOfMics):
                ctfparam = self.protocol._getFileName('ctfparam', micDir=micDir)
                
                if exists(ctfparam) or exists('xmipp_default_ctf.ctfparam'):
                    if not os.path.exists(ctfparam):
                        ctfparam = 'xmipp_default_ctf.ctfparam'
                    
                    ctfModel = readCTFModel(ctfparam, mic)
                    self.protocol._setPsdFiles(ctfModel, micDir)
                    ctfSet.append(ctfModel)
            
            if ctfSet.getSize() < 1:
                raise Exception("Has not been completed the CTT estimation of any micrograph")
            else:
                ctfSet.write()
                ctfSet.close()
                self._visualize(ctfSet)

        if issubclass(cls, Volume):
            fn = getImageLocation(obj)
            self._views.append(DataView(fn, viewParams={RENDER: 'image', SAMPLINGRATE: obj.getSamplingRate()}))
                 
        elif issubclass(cls, Image):
            fn = getImageLocation(obj)
            
            self._views.append(ObjectView(self._project, obj.strId(), fn))
            
        elif issubclass(cls, SetOfNormalModes):
            fn = obj.getFileName()
            objCommands = "'%s' '%s'" % (OBJCMD_NMA_PLOTDIST, OBJCMD_NMA_VMD)
            self._views.append(ObjectView(self._project, self.protocol.strId(), fn, viewParams={OBJCMDS: objCommands}, **args))

        elif issubclass(cls, SetOfMovies):
            fn = obj.getFileName()
            # Enabled for the future has to be available
            labels = 'id _filename _samplingRate  '
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      MODE: MODE_MD, RENDER: "no"}))

        elif issubclass(cls, SetOfMicrographs):            
            fn = obj.getFileName()
            self._views.append(ObjectView(self._project, obj.strId(), fn, **args))
            

        elif issubclass(cls, MicrographsTiltPair):          
#             fnU = obj.getUntilted().getFileName()
#             fnT = obj.getTilted().getFileName()
#             self._views.append(ObjectView(self._project.getName(), obj.strId(), fnU, **args))            
#             self._views.append(ObjectView(self._project.getName(), obj.strId(), fnT, **args))
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(),
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      MODE: MODE_MD,
                                                      RENDER: '_untilted._filename _tilted._filename'}))
            
        elif issubclass(cls, ParticlesTiltPair):          
            labels = 'id enabled _untilted._filename _tilted._filename'
            self._views.append(ObjectView(self._project, obj.strId(), obj.getFileName(),
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, RENDER:'_untilted._filename _tilted._filename',
                                                      MODE: MODE_MD}))

                            
        elif issubclass(cls, SetOfCoordinates):
            micSet = obj.getMicrographs()  # accessing mics to provide metadata file
            if micSet is None:
                raise Exception('visualize: SetOfCoordinates has no micrographs set.')
            
            mdFn = getattr(micSet, '_xmippMd', None)
            tmpDir = self._getTmpPath(obj.getName())
            makePath(tmpDir)
            
            if mdFn:
                fn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                fn = self._getTmpPath(micSet.getName() + '_micrographs.xmd')
                writeSetOfMicrographs(micSet, fn)
            posDir = getattr(obj, '_xmippMd', None)  # extra dir istead of md file for SetOfCoordinates
            if posDir:
                copyTree(posDir.get(), tmpDir)
            else:
                writeSetOfCoordinates(tmpDir, obj)

            self._views.append(CoordinatesObjectView(self._project, fn, tmpDir))

        elif issubclass(cls, SetOfParticles):
            fn = obj.getFileName()
            labels = 'id enabled _index _filename _xmipp_zScore _xmipp_cumulativeSSNR _sampling '
            labels += '_ctfModel._defocusU _ctfModel._defocusV _ctfModel._defocusAngle _transform._matrix'
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      'sortby': '_xmipp_zScore asc', RENDER:'_filename'}))
               
        elif issubclass(cls, SetOfVolumes):
            fn = obj.getFileName()
            labels = 'id enabled comment _filename '
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={MODE: MODE_MD, ORDER: labels, VISIBLE: labels, RENDER: '_filename'}))
        
        elif issubclass(cls, SetOfClasses2D):
            fn = obj.getFileName()
            self._views.append(ClassesView(self._project, obj.strId(), fn, **args))
            
        elif issubclass(cls, SetOfClasses3D):
            fn = obj.getFileName()
            self._views.append(Classes3DView(self._project, obj.strId(), fn))
        
        if issubclass(cls, XmippProtCTFMicrographs) and not obj.hasAttribute("outputCTF"):
            mics = obj.inputMicrographs.get()
            visualizeCTFObjs(obj, mics)

        elif obj.hasAttribute("outputCTF"):
            self._visualize(obj.outputCTF)
        
        elif issubclass(cls, SetOfCTF):
            fn = obj.getFileName()
#            self._views.append(DataView(fn, viewParams={MODE: 'metadata'}))
            psdLabels = '_psdFile _xmipp_enhanced_psd _xmipp_ctfmodel_quadrant _xmipp_ctfmodel_halfplane'
            labels = 'id enabled label %s _defocusU _defocusV _defocusAngle _defocusRatio ' \
                     '_xmipp_ctfCritFirstZero _xmipp_ctfCritCorr13 _xmipp_ctfCritFitting _xmipp_ctfCritNonAstigmaticValidity ' \
                     '_xmipp_ctfCritCtfMargin _micObj._filename' % psdLabels #TODO:CHECK IF _xmipp_ctfCritNonAstigmaticValidity AND _xmipp_ctfCritCtfMargin exist sometimes. 
            self._views.append(ObjectView(self._project, obj.strId(), fn,
                                          viewParams={MODE: MODE_MD, ORDER: labels, VISIBLE: labels, ZOOM: 50, RENDER: psdLabels}))    

        elif issubclass(cls, CoordinatesTiltPair):
            tmpDir = self._getTmpPath(obj.getName()) 
            makePath(tmpDir)

            mdFn = join(tmpDir, 'input_micrographs.xmd')
            writeSetOfMicrographsPairs(obj.getUntilted().getMicrographs(),
                                        obj.getTilted().getMicrographs(), 
                                        mdFn) 
            parentProtId = obj.getObjParentId()
            parentProt = self.getProject().mapper.selectById(parentProtId)
            extraDir = parentProt._getExtraPath()
            
            extraDir = parentProt._getExtraPath()
            #TODO: Review this if ever a non Xmipp CoordinatesTiltPair is available
#             writeSetOfCoordinates(tmpDir, obj.getUntilted()) 
#             writeSetOfCoordinates(tmpDir, obj.getTilted()) 
            
            scipion =  "%s \"%s\" %s" % (self.getProject().port, self.getProject().getDbPath(), obj.strId())
            app = "xmipp.viewer.particlepicker.tiltpair.TiltPairPickerRunner"
            args = " --input %(mdFn)s --output %(extraDir)s --mode readonly --scipion %(scipion)s"%locals()
        
            runJavaIJapp("2g", app, args)
         
        elif issubclass(cls, XmippProtExtractParticles) or issubclass(cls, XmippProtScreenParticles):
            particles = obj.outputParticles
            self._visualize(particles)
            
            fn = obj._getPath('images.xmd')
            md = xmipp.MetaData(fn) 
            # If Zscore on output images plot Zscore particle sorting
            if md.containsLabel(xmipp.MDL_ZSCORE):
                from plotter import XmippPlotter
                xplotter = XmippPlotter(windowTitle="Zscore particles sorting")
                xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore")
                xplotter.plotMd(md, False, mdLabelY=xmipp.MDL_ZSCORE)
                self._views.append(xplotter)
    
        elif issubclass(cls, XmippProtRotSpectra):
            self._visualize(obj.outputClasses, viewParams={#'mode': 'rotspectra', 
                                                           'columns': obj.SomXdim.get(),
                                                           RENDER: 'average._filename spectraPlot._filename',
                                                           VISIBLE:  'enabled id _size average._filename spectraPlot._filename',
                                                           'labels': '_size',
                                                           SORT_BY: 'id'})
        
        elif issubclass(cls, XmippProtKerdensom):
            self._visualize(obj.outputClasses, viewParams={'columns': obj.SomXdim.get(),
                                                           'render': 'average._filename _representative._filename',
                                                           'labels': '_size',
                                                           'sortby': 'id'})
        
        elif issubclass(cls, XmippProtScreenClasses):
            if isinstance(obj.inputSet.get(), SetOfClasses2D):
                fn = obj.outputClasses
                labels = 'id enabled _size _representative._filename _xmipp_imageRef _xmipp_image1 _xmipp_maxCC'
                labelRender = "_representative._filename _xmipp_imageRef _xmipp_image1"
                self._visualize(fn, viewParams={ORDER: labels, 
                                                          VISIBLE: labels, 
                                                          SORT_BY: '_xmipp_maxCC desc', RENDER:labelRender,
                                                          MODE: MODE_MD})
            else:
                fn = obj.outputAverages.getFileName()
                labels = 'id enabled _filename _xmipp_imageRef _xmipp_image1 _xmipp_maxCC'
                labelRender = "_filename _xmipp_imageRef _xmipp_image1"
                self._views.append(ObjectView(self._project, obj.outputAverages.strId(), fn,
                                              viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      SORT_BY: '_xmipp_maxCC desc', RENDER:labelRender,
                                                      MODE: MODE_MD}))
        
        elif issubclass(cls, XmippProtProjectionOutliers):
            if isinstance(obj.inputSet.get(), SetOfClasses2D):
                fn = obj.outputClasses
                labels = 'id enabled _size _representative._index _representative._filename _xmipp_maxCC _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar'
                labelRender = "_representative._filename"
                self._visualize(fn, viewParams={ORDER: labels, 
                                                          VISIBLE: labels, 
                                                          SORT_BY: '_xmipp_zScoreResCov desc', RENDER:labelRender})
            else:
                fn = obj.outputAverages.getFileName()
                labels = 'id enabled _index _filename  _xmipp_maxCC _xmipp_zScoreResCov _xmipp_zScoreResMean _xmipp_zScoreResVar _transform._matrix'
                labelRender = "_filename"
                self._views.append(ObjectView(self._project, obj.outputAverages.strId(), fn,
                                              viewParams={ORDER: labels, 
                                                      VISIBLE: labels, 
                                                      SORT_BY: '_xmipp_zScoreResCov desc', RENDER:labelRender}))
            
        elif issubclass(cls, XmippProtParticlePicking):
            if obj.getOutputsSize() >= 1:
                self._visualize(obj.getCoords())
            
        elif issubclass(cls, XmippParticlePickingAutomatic):
            micSet = obj.getInputMicrographs()
            mdFn = getattr(micSet, '_xmippMd', None)
            if mdFn:
                micsfn = mdFn.get()
            else:  # happens if protocol is not an xmipp one
                micsfn = self._getTmpPath(micSet.getName() + '_micrographs.xmd')
                writeSetOfMicrographs(micSet, micsfn)
                
            posDir = getattr(obj.getCoords(), '_xmippMd').get()  # extra dir istead of md file for SetOfCoordinates
            launchSupervisedPickerGUI(2, micsfn, posDir, 'review', obj)

        elif issubclass(cls, XmippProtParticlePickingPairs):
            tmpDir = self._getTmpPath(obj.getName()) 
            makePath(tmpDir)

            mdFn = join(tmpDir, 'input_micrographs.xmd')
            writeSetOfMicrographsPairs(obj.outputCoordinatesTiltPair.getUntilted().getMicrographs(),
                                        obj.outputCoordinatesTiltPair.getTilted().getMicrographs(), 
                                        mdFn) 
            extraDir = obj._getExtraPath()
            launchTiltPairPickerGUI(obj.memory.get(), mdFn, extraDir, 'readonly', obj)

        elif issubclass(cls, ProtMovieAlignment):
            outputMics = obj.outputMicrographs
            plotLabels = 'psdCorr._filename plotPolar._filename plotCart._filename'
            labels = plotLabels + ' _filename '
            objCommands = "'%s' '%s' '%s'" % (OBJCMD_MOVIE_ALIGNPOLAR, OBJCMD_MOVIE_ALIGNCARTESIAN, OBJCMD_MOVIE_ALIGNPOLARCARTESIAN)
            
            self._views.append(ObjectView(self._project, outputMics.strId(), outputMics.getFileName(), viewParams={MODE: MODE_MD,
                                                      ORDER: labels, VISIBLE: labels, RENDER: plotLabels, 'zoom': 50,
                                                      OBJCMDS: objCommands}))
        
        elif issubclass(cls, XmippProtValidateNonTilt):
            outputVols = obj.outputVolumes
            labels = 'id enabled comment _filename weight'
            self._views.append(ObjectView(self._project, outputVols.strId(), outputVols.getFileName(), viewParams={MODE: MODE_MD,
                                                      VISIBLE:labels, ORDER: labels, SORT_BY: 'weight desc', RENDER: '_filename'}))

        elif issubclass(cls, XmippProtExtractParticlesPairs):
            self._visualize(obj.outputParticlesTiltPair)

        return self._views