コード例 #1
0
 def checkResult(self, testfiles, outDir, random):
     error = ""
     try:
         from xmipp import FileName, Image, compareTwoFiles, compareTwoMetadataFiles
         for file in testfiles:
             file = join(outDir, file)
             fileGoldStd = file.replace(self.fnDir, 'goldStandard')
             result = True
             if not exists(file):
                 error += file + " was NOT produced\n"
             else:
                 if (random):
                     self.warning += file + " was created using a random seed, check skipped\n"
                     self.warningFlag = True
                 else:
                     fnGoldStd = FileName(fileGoldStd)
                     if fnGoldStd.isImage():
                         im1 = Image(fileGoldStd)
                         im2 = Image(file)
                         result = im1.equal(im2, 0.001)
                     elif fnGoldStd.isMetaData():
                         result = compareTwoMetadataFiles(file, fileGoldStd)
                     else:
                         result = compareTwoFiles(file, fileGoldStd, 0)
             if not result:
                 error += " file '%s' and '%s' are NOT identical\n" % (
                     file, fileGoldStd)
     except KeyboardInterrupt:
         raise
     except Exception, ex:
         error += " Error checking results: '%s'\n" % str(ex)
コード例 #2
0
ファイル: protlib_utils.py プロジェクト: josegutab/scipion
def createMetaDataFromPattern(pattern, isStack=False, label="image"):
    ''' Create a metadata from files matching pattern'''
    import glob
    files = glob.glob(pattern)
    files.sort()

    from xmipp import MetaData, FileName, getImageSize, MDL_ENABLED, str2Label
    label = str2Label(label) #Check for label value
    
    mD = MetaData()
    inFile = FileName()
    
    nSize = 1
    for file in files:
        fileAux=file
        if isStack:
            if file.endswith(".mrc"):
                fileAux=file+":mrcs"
            x, x, x, nSize = getImageSize(fileAux)
        if nSize != 1:
            counter = 1
            for jj in range(nSize):
                inFile.compose(counter, fileAux)
                objId = mD.addObject()
                mD.setValue(label, inFile, objId)
                mD.setValue(MDL_ENABLED, 1, objId)
                counter += 1
        else:
            objId = mD.addObject()
            mD.setValue(label, fileAux, objId)
            mD.setValue(MDL_ENABLED, 1, objId)
    return mD
コード例 #3
0
ファイル: test_programs.py プロジェクト: azazellochg/scipion
 def checkResult(self, testfiles, outDir, random):
     error = ""
     try:
         from xmipp import FileName, Image, compareTwoFiles, compareTwoMetadataFiles
         for file in testfiles:
             file = join(outDir, file)
             fileGoldStd = file.replace(self.fnDir, 'goldStandard')
             result = True
             if not exists(file):
                 error += file + " was NOT produced\n"
             else:
                 if (random):
                     self.warning += file + " was created using a random seed, check skipped\n"
                     self.warningFlag = True
                 else:
                     fnGoldStd = FileName(fileGoldStd)
                     if fnGoldStd.isImage():
                         im1 = Image(fileGoldStd)
                         im2 = Image(file)
                         result = im1.equal(im2, 0.001)
                     elif fnGoldStd.isMetaData():
                         result = compareTwoMetadataFiles(file, fileGoldStd)
                     else:
                         result = compareTwoFiles(file, fileGoldStd, 0)
             if not result:
                 error += " file '%s' and '%s' are NOT identical\n" % (file, fileGoldStd)
     except KeyboardInterrupt:
         raise
     except Exception, ex:
         error += " Error checking results: '%s'\n" % str(ex)
コード例 #4
0
ファイル: protlib_xmipp.py プロジェクト: josegutab/scipion
def estimateImageSize(input):
    memory = 0
    input = FileName(input)
    
    if input.exists() and input.isImage():
        (Xdim, Ydim, Zdim, Ndim) = xmipp.getImageSize(input)
        memory = Xdim * Ydim * Zdim * Ndim * 8
    
    return memory
コード例 #5
0
ファイル: protlib_xmipp.py プロジェクト: josegutab/scipion
def estimateFileNameSize(input):
    from xmipp import FileName
    if '@' in input:
        trueFn = input.split('@')[1]
    else:
        trueFn = input
    fn = FileName(trueFn);
    if fn.isMetaData():
        return estimateMDSize(fn)
    elif fn.isImage():
        return estimateImageSize(fn)
    else:
        return 0
コード例 #6
0
ファイル: protlib_xmipp.py プロジェクト: josegutab/scipion
def estimateMDSize(input):
    from xmipp import FileName
    memory = 0
    fn = FileName(input);
    
    if fn.exists():
        MD = xmipp.MetaData(input)
        if(MD.containsLabel(xmipp.MDL_IMAGE)):
            for id in MD:
                fnImg = MD.getValue(xmipp.MDL_IMAGE, id)
                idMemory = estimateImageSize(fnImg)
                memory = max(memory, idMemory)
    
    return memory
コード例 #7
0
ファイル: batch_export_emx.py プロジェクト: josegutab/scipion
    def run(self):
        xmdFileName = FileName(self.getParam('-i'))
        emxFileName = self.getParam('-o')
        if (emxFileName=='metadataXMIPP.emx'):
            emxFileName = xmdFileName.withoutExtension()+'.emx'
        mode         = self.getParam('-m')

        if exists(emxFileName):
           remove(emxFileName)
        emxData = EmxData()
        #create emx files with mic CTF information
        if mode   == 'micCTF':
            ctfMicXmippToEmx(emxData,xmdFileName)
        elif mode == 'micCTFChallenge':
            ctfMicXmippToEmxChallenge(emxData,xmdFileName)
        elif mode == 'coordinates':
            coorrXmippToEmx(emxData,xmdFileName)
        elif mode == 'alignment':
            alignXmippToEmx(emxData,xmdFileName)
        emxData.write(emxFileName)
コード例 #8
0
def importImages(log, InputFile, WorkingDir, DoCopy, ImportAll, SubsetMode, Nsubset):
    imagesFn = getImagesFilename(WorkingDir)
    fnInput = FileName(InputFile)    
    md = MetaData(InputFile)
    #check if micrographs or ctfparam exists
    doMic=False
    doCTFParam=False
    if md.containsLabel(MDL_MICROGRAPH):
        doMic = True
    if md.containsLabel(MDL_CTF_MODEL):
       doCTFParam = True
    
    if fnInput.isMetaData():        
        inputRelativePath = dirname(relpath(InputFile, '.'))
        projectPath = findProjectPath(InputFile)
        for id in md:
            imgFn = md.getValue(MDL_IMAGE, id)
            imgNo, imgFn = splitFilename(imgFn)
            imgFn = xmippRelpath(fixPath(imgFn, projectPath, inputRelativePath, '.'))
            if imgNo != None:
                imgFn = "%s@%s" % (imgNo, imgFn)
            md.setValue(MDL_IMAGE, imgFn, id)
	    #micrograph
	    if doMic:
		imgFn = md.getValue(MDL_MICROGRAPH, id)
		imgNo, imgFn = splitFilename(imgFn)
		imgFn = xmippRelpath(fixPath(imgFn, projectPath, inputRelativePath, '.'))
		if imgNo != None:
		    imgFn = "%s@%s" % (imgNo, imgFn)
		md.setValue(MDL_MICROGRAPH, imgFn, id)
	    #ctf param
	    if doCTFParam:
	        ctfFn =  md.getValue(MDL_CTF_MODEL, id)
		ctfFn = xmippRelpath(fixPath(ctfFn, projectPath, inputRelativePath, '.'))
		md.setValue(MDL_CTF_MODEL, ctfFn, id)
        outExt = '.stk'
    else:
        outExt = '.%s' % fnInput.getExtension()
    imagesStk = imagesFn.replace('.xmd', outExt)
    writeImagesMd(log, md, ImportAll, SubsetMode, Nsubset, imagesFn, imagesStk, DoCopy)
コード例 #9
0
    def actionsToBePerformedInsideLoop(self):
        _log = self.Log
        _dataBase = self.Db
        for indexCTFInsideLoop in range(1, self.defocusGroupNo+1):
            
            if(self.doScaleImages):
                inputSelfile = self.scaledImages +'.xmd'
            else:
                inputSelfile = self.getFilename('SubCurrentAnglesAllExpImgs')
                            
            if(self.DocFileExp == ''):
                DocFileExpAux = self.getFilename('SubCurrentAnglesCftGroups', ctf=indexCTFInsideLoop)
            else:
                DocFileExpAux = self.DocFileExp
                    
            if(self.defocusGroupNo > 1):
                
                
                if(self.doScaleImages):
                    _VerifyFiles = []
                    auxFilename = FileName(self.getFilename('SubCurrentAnglesCftGroups', ctf=indexCTFInsideLoop))
                    _VerifyFiles.append(auxFilename.removeBlockName())
                    id = self.Db.insertStep('joinImageCTFscale', verifyfiles = _VerifyFiles
                                            , CTFgroupName = self.getFilename('DocCTFsBlocks', ctf=indexCTFInsideLoop)
                                            , DocFileExp = DocFileExpAux
                                            , inputSelfile = inputSelfile
                                            )
                else: #No scale
                    _VerifyFiles = []
                    auxFilename = FileName(self.getFilename('SubCurrentAnglesCftGroups', ctf=indexCTFInsideLoop))
                    _VerifyFiles.append(auxFilename.removeBlockName())
                    id = self.Db.insertStep('joinImageCTF', verifyfiles = _VerifyFiles
                                            , CTFgroupName =  self.getFilename('DocCTFsBlocks', ctf=indexCTFInsideLoop)
                                            , DocFileExp = DocFileExpAux
                                            , inputSelfile = inputSelfile
                                            )                
            else: # No Ctf correction in ProjMatch 
                if(self.doScaleImages):
                    _VerifyFiles = []
                    id = self.Db.insertStep('joinImageCTFscale', verifyfiles = _VerifyFiles
                                            , CTFgroupName = self.localFilenameCurrentAngles
                                            , DocFileExp = DocFileExpAux
                                            , inputSelfile = inputSelfile
                                            )
                else:
                    _VerifyFiles = []
                    id = self.Db.insertStep('joinImageCTF', verifyfiles = _VerifyFiles
                                            , CTFgroupName = self.localFilenameCurrentAngles
                                            , DocFileExp = DocFileExpAux
                                            , inputSelfile = inputSelfile
                                            )

                
                
            #reconstruct each CTF group
            _VerifyFiles = []
            _VerifyFiles.append(self.getFilename('ReconstructedFileNamesIters', ctf=indexCTFInsideLoop))
            id = self.Db.insertStep('reconstructVolume', verifyfiles = _VerifyFiles
                                        , DocFileExp = DocFileExpAux
                                        , MpiJobSize = self.MpiJobSize
                                        , NumberOfMpi = self.NumberOfMpi
                                        , NumberOfThreads = self.NumberOfThreads
                                        , reconstructedVolume = self.getFilename('ReconstructedFileNamesIters', ctf=indexCTFInsideLoop)
                                        , SymmetryGroup = self.SymmetryGroup)
            
            
            #mask volume before projection
            _VerifyFiles = []
            auxFilename = FileName(self.getFilename('SubCurrentAnglesCftGroups', ctf=indexCTFInsideLoop))
            _VerifyFiles.append(self.getFilename('ReconstructedMaskedFileNamesIters', ctf=indexCTFInsideLoop))
            
            id = self.Db.insertStep('maskVolume', verifyfiles = _VerifyFiles
                                        , dRradiusMax = self.dRradiusMax
                                        , dRradiusMin = self.dRradiusMin
                                        , maskReconstructedVolume = self.getFilename('ReconstructedMaskedFileNamesIters', ctf=indexCTFInsideLoop)
                                        , reconstructedVolume = self.getFilename('ReconstructedFileNamesIters', ctf=indexCTFInsideLoop)
                                        , NumberOfMpi = self.NumberOfMpi
                                        , NumberOfThreads = self.NumberOfThreads)
            
            
            #project reconstructe4d volumes
            _VerifyFiles = []
            _VerifyFiles.append(self.getFilename('ReferenceStack', ctf=indexCTFInsideLoop))
            _VerifyFiles.append(self.getFilename('ReferenceStackDoc', ctf=indexCTFInsideLoop))
            _VerifyFiles.append(self.getFilename('ReferenceStackSampling', ctf=indexCTFInsideLoop))
            
            id = self.Db.insertStep('createProjections', verifyfiles = _VerifyFiles
                                        , AngSamplingRateDeg = self.AngSamplingRateDeg
                                        , DocFileExp = DocFileExpAux
                                        , maskReconstructedVolume = self.getFilename('ReconstructedMaskedFileNamesIters', ctf=indexCTFInsideLoop)
                                        , MaxChangeInAngles = self.MaxChangeInAngles
                                        , MpiJobSize = self.MpiJobSize
                                        , NumberOfMpi = self.NumberOfMpi
                                        , NumberOfThreads = self.NumberOfThreads
                                        , referenceStack = self.getFilename('ReferenceStack', ctf=indexCTFInsideLoop)
                                        , SymmetryGroup = self.SymmetryGroup)
                     
                     
            #project reconstructe4d volumes
            _VerifyFiles = []
            _VerifyFiles.append(self.getFilename('SubtractedStack', ctf=indexCTFInsideLoop))
            _VerifyFiles.append(self.getFilename('SubtractedStack', ctf=indexCTFInsideLoop)+'ref')
            _VerifyFiles.append(self.getFilename('SubtractedStack', ctf=indexCTFInsideLoop)+'exp')
            
            id = self.Db.insertStep('subtractionScript', verifyfiles = _VerifyFiles
                                        , DocFileExp = DocFileExpAux
                                        , referenceStackDoc = self.getFilename('ReferenceStackDoc', ctf=indexCTFInsideLoop)
                                        , subtractedStack = self.getFilename('SubtractedStack', ctf=indexCTFInsideLoop)
                                        , resultsImagesName = self.resultsImagesName)
                          
            self.Db.connection.commit()