Exemplo n.º 1
0
def MRCtoSPI(infile, rundir):
    # convert file to spider file
    tmpspifile = apParam.randomString(8) + ".spi"
    tmpspifile = os.path.join(rundir, tmpspifile)
    emancmd = "proc3d %s %s spidersingle" % (infile, tmpspifile)
    apEMAN.executeEmanCmd(emancmd, verbose=True)
    return tmpspifile
def imagicToMrc(params, msg=True):
        # convert imagic stack to mrc "stack"
        outstack = os.path.join(params['rundir'],'start.mrc')
        params['stackfile']=outstack

        # if mrc stack exists, don't overwrite
        # TO DO: check if existing stack is correct
        if os.path.exists(outstack):
                apDisplay.printWarning(outstack + " exists, not overwriting")
                return

        # first get stack info
        stackdata = apStack.getOnlyStackData(params['stackid'], msg=False)
        stackfile = os.path.splitext(os.path.join(stackdata['path']['path'],stackdata['name']))

        # make sure to use the 'img' file, which contains the binary data
        stackimg = stackfile[0]+'.img'

        # get box size
        box = apStack.getStackBoxsize(params['stackid'], msg=False)
        nump = apStack.getNumberStackParticlesFromId(params['stackid'])

        ## create a new MRC header
        header = mrc.newHeader()
        mrc.updateHeaderDefaults(header)

        # fill with stack params
        header['nx']=box
        header['ny']=box
        header['nz']=nump
        header['mode']=2
        header['mx']=box
        header['my']=box
        header['mz']=nump
        header['xlen']=box
        header['ylen']=box
        header['zlen']=nump
        header['amin']=0.0
        header['amax']=0.0
        header['amean']=0.0
        header['rms']=0.0
        header['xorigin']=0.0
        header['yorigin']=0.0
        header['zorigin']=0.0

        # write header to temporary file
        hbytes = mrc.makeHeaderData(header)
        tmpheadername = apParam.randomString(8)+'.mrc'
        f = open(tmpheadername,'w')
        f.write(hbytes)
        f.close()

        if msg is True:
                apDisplay.printMsg('saving MRC stack file:')
                apDisplay.printMsg(os.path.join(params['rundir'],outstack))
        catcmd = "cat %s %s > %s" % (tmpheadername, stackimg, outstack)
        print catcmd
        proc = subprocess.Popen(catcmd, shell=True)
        proc.wait()
        os.remove(tmpheadername)
def MRCtoSPI(infile, rundir):
	# convert file to spider file
	tmpspifile = apParam.randomString(8)+".spi"
	tmpspifile = os.path.join(rundir,tmpspifile)
	emancmd = "proc3d %s %s spidersingle" %(infile,tmpspifile)
	apEMAN.executeEmanCmd(emancmd, verbose=True)
	return tmpspifile
Exemplo n.º 4
0
def exclude_classes_from_frealign9_parfiles(inparfilebase, outlist, minocc,
                                            *classlist):
    '''
        inparfilebase is the base name of the parameter file, w/ iteration number, but w/o class number
        e.g. for parameter file input_20_r1.par, inparfilebase is input_20
        
        classlist refers to a list with class numbers (starting with 1), e.g. [0,1,4]

        outlist is a list containing the particle numbers within the relevant classes (starts with 0)
        '''

    if minocc < 50:
        apDisplay.printWarning(
            "minimum occupancy is < 50% ... are you sure you want to include these particles?"
        )

    combined = []
    outbase = apParam.randomString(10)
    for i in classlist:
        parfile = "%s_r%d.par" % (inparfilebase, i)
        exclude_class_from_frealign9_parfile(parfile,
                                             "%s_%d.lst" % (outbase, i),
                                             minocc=minocc)
        f = open("%s_%d.lst" % (outbase, i), "r")
        lines = f.readlines()
        f.close()
        os.remove("%s_%d.lst" % (outbase, i))
        stripped = [int(l.strip()) for l in lines]
        combined.extend(stripped)
    combined.sort()

    ### check for duplicates
    last = -1
    for i in reversed(range(0, len(combined))):
        if combined[i] == combined[i - 1]:
            tmp = combined.pop(i)
    ### write to file
    outlistf = open(outlist, "w")
    for i in combined:
        outlistf.write("%d\n" % i)
    outlistf.close()
def exclude_classes_from_frealign9_parfiles(inparfilebase, outlist, minocc, *classlist):
        '''
        inparfilebase is the base name of the parameter file, w/ iteration number, but w/o class number
        e.g. for parameter file input_20_r1.par, inparfilebase is input_20
        
        classlist refers to a list with class numbers (starting with 1), e.g. [0,1,4]

        outlist is a list containing the particle numbers within the relevant classes (starts with 0)
        '''
        
        if minocc < 50:
                apDisplay.printWarning("minimum occupancy is < 50% ... are you sure you want to include these particles?")      
        
        combined = []
        outbase = apParam.randomString(10)
        for i in classlist:
                parfile = "%s_r%d.par" % (inparfilebase, i)
                exclude_class_from_frealign9_parfile(parfile, "%s_%d.lst" % (outbase,i), minocc=minocc)
                f = open("%s_%d.lst" % (outbase,i), "r")
                lines = f.readlines()
                f.close()
                os.remove("%s_%d.lst" % (outbase,i))
                stripped = [int(l.strip()) for l in lines]
                combined.extend(stripped)
        combined.sort()
        
        ### check for duplicates
        last = -1
        for i in reversed(range(0,len(combined))):
                if combined[i] == combined[i-1]:
                        tmp = combined.pop(i)
        ### write to file
        outlistf = open(outlist, "w")
        for i in combined:
                outlistf.write("%d\n" %i)
        outlistf.close()
def imagicToMrc(params, msg=True):
    # convert imagic stack to mrc "stack"
    outstack = os.path.join(params['rundir'], 'start.mrc')
    params['stackfile'] = outstack

    # if mrc stack exists, don't overwrite
    # TO DO: check if existing stack is correct
    if os.path.exists(outstack):
        apDisplay.printWarning(outstack + " exists, not overwriting")
        return

    # first get stack info
    stackdata = apStack.getOnlyStackData(params['stackid'], msg=False)
    stackfile = os.path.splitext(
        os.path.join(stackdata['path']['path'], stackdata['name']))

    # make sure to use the 'img' file, which contains the binary data
    stackimg = stackfile[0] + '.img'

    # get box size
    box = apStack.getStackBoxsize(params['stackid'], msg=False)
    nump = apStack.getNumberStackParticlesFromId(params['stackid'])

    ## create a new MRC header
    header = mrc.newHeader()
    mrc.updateHeaderDefaults(header)

    # fill with stack params
    header['nx'] = box
    header['ny'] = box
    header['nz'] = nump
    header['mode'] = 2
    header['mx'] = box
    header['my'] = box
    header['mz'] = nump
    header['xlen'] = box
    header['ylen'] = box
    header['zlen'] = nump
    header['amin'] = 0.0
    header['amax'] = 0.0
    header['amean'] = 0.0
    header['rms'] = 0.0
    header['xorigin'] = 0.0
    header['yorigin'] = 0.0
    header['zorigin'] = 0.0

    # write header to temporary file
    hbytes = mrc.makeHeaderData(header)
    tmpheadername = apParam.randomString(8) + '.mrc'
    f = open(tmpheadername, 'w')
    f.write(hbytes)
    f.close()

    if msg is True:
        apDisplay.printMsg('saving MRC stack file:')
        apDisplay.printMsg(os.path.join(params['rundir'], outstack))
    catcmd = "cat %s %s > %s" % (tmpheadername, stackimg, outstack)
    print catcmd
    proc = subprocess.Popen(catcmd, shell=True)
    proc.wait()
    os.remove(tmpheadername)