Пример #1
0
 def summary(self):
     message = []
     from protlib_xmipp import getMdSize
     size = getMdSize(self.Input['micrographs'])
     message.append("Movies aligned <%d>" % (size))
     message.append("Input directory: [%s]" % self.PrevRun.WorkingDir)
     return message
Пример #2
0
 def validate(self):
     errors = []
     N1=getMdSize(self.Operand1)
     Operation=self.Operation
     checkDimensions=False
     if Operation=='column' or Operation=='slice' or Operation=='row':
         if not self.Operand2.isdigit():
             errors.append('You should give a number for the column, slice or row')
     elif Operation=='dot product':
         if self.Operand2.isdigit():
             errors.append('Second operand cannot be a number')
         else:
             checkDimensions=True
     elif Operation=='plus' or Operation=='minus' or Operation=='multiply' or Operation=='divide' or Operation=='minimum' or \
        Operation=='maximum':
         if not self.Operand2.isdigit():
             checkDimensions=True
     if checkDimensions:
         md1=MetaData(self.Operand1)
         md2=MetaData(self.Operand2)
         x1, y1, z1, _, _ = MetaDataInfo(md1)    
         x2, y2, z2, _, _ = MetaDataInfo(md2)
         if x1!=x2 or y1!=y2 or z1!=z2:
             errors.append("Image/Volume sizes in the two operands are not the same")    
         if md2.size()>1:
             if md2.size()!=md1.size():
                 errors.append("The number of images/volumes in the two operands are not the same")
     return errors
def getBestVolumes(log,WorkingDir,NRansac,NumVolumes,UseAll):
    volumes = []
    inliers = []
    
    for n in range(NRansac):
        fnAngles = os.path.join(WorkingDir,"tmp/angles_ransac%05d"%n+".xmd")
        md=MetaData("inliers@"+fnAngles)
        numInliers=md.getValue(MDL_WEIGHT,md.firstObject())
        volumes.append(fnAngles)
        inliers.append(numInliers)
    
    index = sorted(range(inliers.__len__()), key=lambda k: inliers[k])
    fnBestAngles = ''
    threshold=getCCThreshold(WorkingDir)
 
    i=NRansac-1
    indx = 0
    while i>=0 and indx<NumVolumes:
        fnBestAngles = volumes[index[i]]
        fnBestAnglesOut=os.path.join(WorkingDir,"volumeProposed%05d"%indx+".xmd")
        copyFile(log,fnBestAngles,fnBestAnglesOut)
        print("Best volume "+str(indx)+" = "+fnBestAngles)
        if not UseAll:
            runJob(log,"xmipp_metadata_utilities","-i %s -o %s --query select \"maxCC>%f \" --mode append" %(fnBestAnglesOut,fnBestAnglesOut,threshold))
            if getMdSize(fnBestAnglesOut) > 0:
                indx += 1
        else:
            indx += 1
        i -= 1
        
    # Remove unnecessary files
    for n in range(NRansac):
        fnAngles = os.path.join(WorkingDir,"tmp/angles_ransac%05d"%n+".xmd")
        deleteFile(log, fnAngles)
Пример #4
0
    def summary(self):
        message=[]
        if self.DoGenerateReferences:
            N=self.NumberOfReferences
        else:
            from protlib_xmipp import getMdSize
            N = getMdSize(self.RefMd)
        message.append("MLTomo on [%s] with %d references" % (self.VolumeList, N))

        return message
Пример #5
0
 def summary(self):
     message=[]
     message.append(("Classification of [%s]"%self.InSelFile)+" into "+str(self.NumberOfReferences)+" classes")
     levelFiles=glob.glob(self.WorkingDir+"/extra/level_??/level_classes.xmd")
     if not levelFiles:
         message.append("No class file has been generated")
     else:
         import time
         levelFiles.sort()
         lastLevelFile=levelFiles[-1]
         date=time.ctime(os.path.getmtime(lastLevelFile))
         lastLevel=int(re.search('level_(\d\d)',lastLevelFile).group(1))
         iteration = getMdSize("info@"+lastLevelFile)
         try:
             size = getMdSize("classes@"+lastLevelFile)
             message.append("Last iteration is %s from level %d with %d classes (at %s)"%(iteration,lastLevel, size,date))
         except:
             pass
     return message
Пример #6
0
def postCl2d(log, WorkingDir, NumberOfReferences):
    levelDirs=glob.glob(os.path.join(WorkingDir,"extra/level_??"))
    createLink(log,os.path.join(WorkingDir,"extra/images.xmd"),os.path.join(WorkingDir,"images.xmd"))
    if levelDirs:
        levelDirs.sort()
        lastLevelDir=levelDirs[-1]
        fnLastLevelFile=os.path.join(lastLevelDir,"level_classes.xmd")
        from protlib_xmipp import getMdSize
        size = getMdSize("classes@"+fnLastLevelFile)
        if size == NumberOfReferences:
            createLink(log, fnLastLevelFile, os.path.join(WorkingDir,"classes.xmd"))
Пример #7
0
 def summary(self):
     micrographs, particles = countParticles(self.ExtraDir)
     if self.TiltPairs: 
         suffix = "tilt pairs"
         items = "pairs"
         micrographs /= 2
         particles /= 2
     else: 
         suffix = "micrographs"
         items = "particles"        
     from protlib_xmipp import getMdSize
     size = getMdSize(self.MicrographsMd)
     summary = ["Input: [%s] with <%u> %s" % (self.importDir, size, suffix),         
                "Number of %(items)s manually picked: <%(particles)d> (from <%(micrographs)d> micrographs)" % locals()]
     md=xmipp.MetaData(self.MicrographsMd)
     if not md.containsLabel(xmipp.MDL_CTF_MODEL):
         summary.append(redStr("There is no CTF information in the input micrographs: "))
         summary.append("[%s]"%self.MicrographsMd)
     
     return summary
Пример #8
0
 def preprocess(self):
     import launch_job,xmipp
     if self.DoFilter:
         slope=max(self.Highpass/2,0.01)
         fnOut=self.WorkingDir+'/preprocessedImages.stk'
         self.selFileToUse=fnOut
         if not self.doStep1 and os.path.exists(fnOut):
             numberOfImages=xmipp.getImageSize(fnOut)[3]
             from protlib_xmipp import getMdSize
             size = getMdSize(self.InSelFile)
             if size != numberOfImages:
                 self.doStep1 = True
         if not stepPerformed("Step 1",self.WorkingDir + "/status.txt"):
             self.doStep1 = True
         if self.doStep1:
             params= '-i '+str(self.InSelFile)+\
                     ' --fourier_mask raised_cosine '+str(slope)+\
                     ' -o '+fnOut
             if self.Highpass>0 and self.Lowpass>0:
                 params+=" --band_pass "+str(self.Highpass)+" "+str(self.Lowpass)
             elif self.Highpass>0:
                 params+=" --high_pass "+str(self.Highpass)
             elif self.Lowpass>0:
                 params+=" --low_pass "+str(self.Lowpass)
             launchJob("xmipp_fourier_filter",
                                   params,
                                   self.log,
                                   False,
                                   1,
                                   1,
                                   self.SystemFlavour)
             # Update status    
             if os.path.exists(self.WorkingDir+'/preprocessedImages.stk'):
                 fh=open(self.WorkingDir + "/status.txt", "a")
                 fh.write("Step 1: Preprocessing finished at " + time.asctime() + "\n")
                 fh.close()
     else:
         self.selFileToUse=self.InSelFile
def subtractionScript(_log
                      ,DocFileExp
                      ,referenceStackDoc
                      ,subtractedStack
                      ,resultsImagesName
                      ):
    md = MetaData(DocFileExp)#experimental images
    mdRotations = MetaData(md) #rotations
    
    # Save Metadata with just rotations (shifts will be applied when reading)
    mdRotations.setValueCol(MDL_SHIFT_X, 0.)
    mdRotations.setValueCol(MDL_SHIFT_Y, 0.)
    mdRotations.operate('anglePsi=-anglePsi')
    
    mdResults = MetaData(mdRotations)
    mdResults.operate('anglePsi=0')
    
    #reference projection for a given defocus group
    mdRef = MetaData(referenceStackDoc) #reference library
    
    imgExp = Image()
    imgRef = Image()
    imgSub = Image()
    
    stackResults = resultsImagesName+'.stk'
    
    if (os.path.exists(stackResults)):
        from protlib_xmipp import getMdSize
        idResults = getMdSize(stackResults)
    else:
        idResults = 0
        
    xmdResults = resultsImagesName+'.xmd'
    if (os.path.exists(xmdResults)):
        xmdOldResults = MetaData(xmdResults)
        xmdOldResults.unionAll(mdResults)
        mdResults = MetaData(xmdOldResults)
    
    for id in md:
        angRot = md.getValue(MDL_ANGLE_ROT, id)
        angTilt = md.getValue(MDL_ANGLE_TILT, id)
        psi = md.getValue(MDL_ANGLE_PSI, id)
        
        # Search for the closest idRef
        dist = -1.
        distMin = 999.
        for idRef in mdRef:
            angRotRef  = mdRef.getValue(MDL_ANGLE_ROT, idRef)
            angTiltRef = mdRef.getValue(MDL_ANGLE_TILT, idRef)
            
            dist = abs(float(angRotRef) - float(angRot)) +  abs(float(angTiltRef) - float(angTilt))
            if(dist < distMin or dist == -1):
                refNum = idRef
                distMin = dist
                    
        # Apply alignment as follows: shifts firt (while reading), then rotations
        imgExp.readApplyGeo(md, id, True, DATA, ALL_IMAGES, False) # only_apply_shifts = true
        imgExp.applyGeo(mdRotations, id, False, False)  
        
        imgRef.readApplyGeo(mdRef,refNum, False, DATA, ALL_IMAGES,False)
        imgSub = imgExp - imgRef
        imgSub.write('%06d@%s'%(id,subtractedStack))
        imgExp.write('%06d@%s'%(id,subtractedStack+'exp'))
        imgRef.write('%06d@%s'%(id,subtractedStack+'ref'))
        
        mdRotations.setValue(MDL_IMAGE, '%06d@%s'%(id,subtractedStack), id)
        
        # write protocols results
        imgSub.write('%06d@%s'%(id + idResults, stackResults))
        mdResults.setValue(MDL_IMAGE, '%06d@%s'%(id + idResults, stackResults), id + idResults)
        
    
    mdRotations.operate('anglePsi=0')
    mdRotations.write(subtractedStack.replace('.stk','.xmd'))
    
    mdResults.write(xmdResults)