Beispiel #1
0
def alignParticlesInLST(lstfile,outstack):
        import EMAN
        ### create a stack of particles aligned according to an LST file
        images=EMAN.readImages(lstfile,-1,-1,0)
        for i in images:
                i.edgeNormalize()
                i.rotateAndTranslate()
                if i.isFlipped():
                        i.hFlip()
                i.writeImage(outstack,-1)
Beispiel #2
0
def alignParticlesInLST(lstfile,outstack):
        import EMAN
        ### create a stack of particles aligned according to an LST file
        images=EMAN.readImages(lstfile,-1,-1,0)
        for i in images:
                i.edgeNormalize()
                i.rotateAndTranslate()
                if i.isFlipped():
                        i.hFlip()
                i.writeImage(outstack,-1)
def alignParticlesInLST(lstfile,outstack):
        import EMAN
        ### create a stack of particles aligned according to an LST file
        apDisplay.printMsg("aligning particles in '%s', saving to stack: %s"%(lstfile,outstack))        
        images=EMAN.readImages(lstfile,-1,-1,0)
        for i in images:
                i.edgeNormalize()
                i.rotateAndTranslate()
                if i.isFlipped():
                        i.hFlip()
                i.writeImage(outstack,-1)
def alignParticlesInLST(lstfile, outstack):
    import EMAN
    ### create a stack of particles aligned according to an LST file
    apDisplay.printMsg("aligning particles in '%s', saving to stack: %s" %
                       (lstfile, outstack))
    images = EMAN.readImages(lstfile, -1, -1, 0)
    for i in images:
        i.edgeNormalize()
        i.rotateAndTranslate()
        if i.isFlipped():
            i.hFlip()
        i.writeImage(outstack, -1)
Beispiel #5
0
def main():
	if len(sys.argv) != 3:
		print "Usage::  %s <input particles file name> <output particles file name>"%(sys.argv[0])
		sys.exit(-1)
	input = sys.argv[1]
	output = sys.argv[2]
	
	stack=EMAN.readImages(input,-1,-1)
	i = 0
	for image in stack:
		print "Working on image %s"%(i)
		new_image = speckle_filter(image)
		new_image.writeImage(output,i)
		i=i+1
def makeClassAverages(lst, outputstack, e, mask):
    import EMAN
    #align images in class
    print "creating class average from", lst, "to", outputstack
    images = EMAN.readImages(lst, -1, -1, 0)
    for image in images:
        image.rotateAndTranslate()
        if image.isFlipped():
            image.hFlip()

    #make class average
    avg = EMAN.EMData()
    avg.makeMedian(images)

    #write class average
    avg.setRAlign(e)
    avg.setNImg(len(images))
    avg.applyMask(mask, 0)
    avg.writeImage(outputstack, -1)
def makeClassAverages(lst, outputstack,e,mask):
        import EMAN
        #align images in class
        print "creating class average from",lst,"to",outputstack
        images=EMAN.readImages(lst,-1,-1,0)
        for image in images:
                image.rotateAndTranslate()
                if image.isFlipped():
                        image.hFlip()

        #make class average
        avg=EMAN.EMData()
        avg.makeMedian(images)

        #write class average
        avg.setRAlign(e)
        avg.setNImg(len(images))
        avg.applyMask(mask,0)
        avg.writeImage(outputstack,-1)
def makeClassAverages(lst, outputstack, classdata, params):
    #align images in class
    images = EMAN.readImages(lst, -1, -1, 0)
    for image in images:
        image.rotateAndTranslate()
        if image.isFlipped():
            image.hFlip()

    #make class average
    avg = EMAN.EMData()
    avg.makeMedian(images)

    #write class average
    e = EMAN.Euler()
    alt = classdata['euler1'] * math.pi / 180
    az = classdata['euler2'] * math.pi / 180
    phi = 0.0
    e.setAngle(alt, az, phi)
    avg.setRAlign(e)
    avg.setNImg(len(images))
    avg.applyMask(params['mask'], 0)
    avg.writeImage(outputstack, -1)
def makeClassAverages(lst, outputstack, classdata, params):
    # align images in class
    images = EMAN.readImages(lst, -1, -1, 0)
    for image in images:
        image.rotateAndTranslate()
        if image.isFlipped():
            image.hFlip()

    # make class average
    avg = EMAN.EMData()
    avg.makeMedian(images)

    # write class average
    e = EMAN.Euler()
    alt = classdata["euler1"] * math.pi / 180
    az = classdata["euler2"] * math.pi / 180
    phi = 0.0
    e.setAngle(alt, az, phi)
    avg.setRAlign(e)
    avg.setNImg(len(images))
    avg.applyMask(params["mask"], 0)
    avg.writeImage(outputstack, -1)
        def makeClassAverages(self, classlist, outputstack, classdata, maskrad):
                #align images in class
                #print classlist
                images = EMAN.readImages(classlist, -1, -1, 0)
                for image in images:
                        image.rotateAndTranslate()
                        if image.isFlipped():
                                image.hFlip()

                #make class average
                avg = EMAN.EMData()
                avg.makeMedian(images)

                #write class average
                e = EMAN.Euler()
                alt = classdata['euler1']*math.pi/180
                az  = classdata['euler2']*math.pi/180
                phi = 0.0 #classdata['euler3']*math.pi/180
                e.setAngle(alt, az, phi)
                avg.setRAlign(e)
                avg.setNImg(len(images))
                avg.applyMask(maskrad, 0)

                avg.writeImage(outputstack,-1)
Beispiel #11
0
#!/usr/bin/env python
import EMAN
import sys
from sys import argv
import os
import math

RD = 180.0 / math.pi

if len(argv) < 3:
    print "fsctest.py <refs> <ref #> <ptcl file> <ptcl #>"
    sys.exit(1)

refs = EMAN.readImages(argv[1], -1, -1)
ptcl = EMAN.EMData()
ptcl.readImage(argv[3], int(argv[4]))
ptcl.edgeNormalize()
ptclf = ptcl.copy(0, 0)
ptclf.vFlip()


for i in refs:
    i.normalize()

ali = ptcl.RTFAlign(refs[int(argv[2])], ptclf, 1)
ali.refineAlign(i)
fsc = (1.0 + ali.fscmp(refs[int(argv[2])], None)) * 500.0
print fsc
if __name__ == '__main__':
    # write command & time to emanlog if exists:
    if os.path.exists('refine.log'):
        cmd = string.join(sys.argv, ' ')
        apEMAN.writeEMANTime('refine.log', cmd)
    #Parse inputs
    args = sys.argv[1:]
    params = createDefaults()
    parseInput(args, params)

    if params['coranmask'] is None:
        params['coranmask'] = params['mask']

    #Determine box size
    tmpimg = EMAN.readImages('start.hed', 1, 1)
    params['boxsize'] = tmpimg[0].xSize()

    #Set up for coran
    params['corandir'] = params['corandir'] + str(params['iter'])
    if os.path.exists(params['corandir']):
        print "WARNING!!! %s exists and is being overwritten" % params[
            'corandir']
        shutil.rmtree(params['corandir'])
        os.mkdir(params['corandir'])
    else:
        os.mkdir(params['corandir'])
    classfile = 'cls.' + str(params['iter']) + '.tar'
    shutil.copy(classfile, os.path.join(params['corandir'], classfile))
    shutil.copy('proj.hed', os.path.join(params['corandir'], 'proj.hed'))
    shutil.copy('proj.img', os.path.join(params['corandir'], 'proj.img'))
Beispiel #13
0
def createClassAverages(stack,
                        projs,
                        apmq,
                        numprojs,
                        boxsz,
                        outclass="classes",
                        rotated=False,
                        shifted=False,
                        dataext=".spi"):
    """
        creates EMAN-style class average file "classes.hed" & "classes.img"
        and variance files "variances.hed" & "variances.img"
        from spider classification
        """
    apFile.removeFile(outclass)
    outf = spyder.fileFilter(outclass)
    outvf = "tmpvar"
    apmqlist = readDocFile(apmq)
    mySpi = spyder.SpiderSession(dataext=dataext, logo=False, log=False)

    # create file containing the number of particles matched to each projection
    mySpi.toSpiderQuiet(
        "VO MQ",
        "0.0",
        spyder.fileFilter(apmq),
        str(numprojs),
        "cls*****",
        "numinclass",
    )
    mySpi.close()
    os.remove("numinclass%s" % dataext)

    # create class average file
    mySpi = spyder.SpiderSession(dataext=dataext, logo=False, log=False)
    for i in range(0, numprojs):
        clsfile = readDocFile("cls%05d%s" % (i + 1, dataext))
        if clsfile == []:
            apDisplay.printMsg("class %d has no particles" % (i + 1))
            mySpi.toSpiderQuiet(
                "BL",
                "%s@%d" % (outf, (i + 1)),
                "(%d,%d)" % (boxsz, boxsz),
                "N",
                "(0.0)",
            )
            mySpi.toSpiderQuiet(
                "BL",
                "%s@%d" % (outvf, (i + 1)),
                "(%d,%d)" % (boxsz, boxsz),
                "N",
                "(0.0)",
            )
        else:
            mySpi.toSpiderQuiet("DE", "_2@")
            mySpi.toSpiderQuiet("MS", "_2@", "%d,%d,1" % (boxsz, boxsz),
                                str(len(clsfile)))
            for p in range(0, len(clsfile)):
                mySpi.toSpiderQuiet("DE", "_1")
                # get the particle
                part = int(float(clsfile[p][2])) - 1
                pimg = spyder.fileFilter(stack) + "@%d" % (part + 1)

                rot = float(apmqlist[part][4])
                shx = float(apmqlist[part][5])
                shy = float(apmqlist[part][6])
                if shifted is True:
                    shx = 0
                    shy = 0
                if rotated is True:
                    rot = 0
                p_out = "_2@%d" % (p + 1)
                rotAndShiftImg(pimg, "_1", rot, shx, shy, inMySpi=mySpi)
                # mirror
                if int(float(apmqlist[part][2])) < 0:
                    mirrorImg("_1", p_out, inMySpi=mySpi)
                else:
                    mySpi.toSpiderQuiet("CP", "_1", p_out)
            if len(clsfile) == 1:
                mySpi.toSpiderQuiet("CP", "_2@1", "%s@%d" % (outf, (i + 1)))
                mySpi.toSpiderQuiet(
                    "BL",
                    "%s@%d" % (outvf, (i + 1)),
                    "(%d,%d)" % (boxsz, boxsz),
                    "N",
                    "(0.0)",
                )
            else:
                mySpi.toSpiderQuiet("AS R", "_2@*****", "1-%d" % len(clsfile),
                                    "A", "%s@%d" % (outf, (i + 1)),
                                    "%s@%d" % (outvf, i + 1))
    mySpi.close()

    # convert the class averages to EMAN class averages
    # read classes & projections for EMAN classes output
    if os.path.exists('variances.hed'):
        os.remove('variances.hed')
    if os.path.exists('variances.img'):
        os.remove('variances.img')
    if os.path.exists('classes.hed'):
        os.remove('classes.hed')
    if os.path.exists('classes.img'):
        os.remove('classes.img')
    ### I would prefer to use apImagicFile.readImagic, writeImagic
    variances = EMAN.readImages(outvf + dataext, -1, -1, 0)
    averages = EMAN.readImages(outf + dataext, -1, -1, 0)
    projections = EMAN.readImages(projs, -1, -1, 0)
    for i in range(0, numprojs):
        # copy projection to class average file
        projections[i].writeImage('classes.hed')
        projections[i].writeImage('variances.hed')
        # get num of particles in class
        clsfile = readDocFile("cls%05d%s" % (i + 1, dataext))
        averages[i].setNImg(len(clsfile))
        averages[i].writeImage('classes.hed', -1)
        variances[i].setNImg(len(clsfile))
        variances[i].writeImage('variances.hed', -1)
        os.remove("cls%05d%s" % (i + 1, dataext))
    os.remove(outf + dataext)
    return
if __name__== '__main__':
	# write command & time to emanlog if exists:
	if os.path.exists('refine.log'):
		cmd = string.join(sys.argv,' ')
		apEMAN.writeEMANTime('refine.log',cmd)
	#Parse inputs
	args=sys.argv[1:]
	params=createDefaults()
	parseInput(args,params)
	
	if params['coranmask'] is None:
		params['coranmask'] = params['mask']
		
	#Determine box size
	tmpimg=EMAN.readImages('start.hed',1,1)
	params['boxsize']=tmpimg[0].xSize()

	#Set up for coran
	params['corandir']=params['corandir']+str(params['iter'])
	if os.path.exists(params['corandir']):
		print "WARNING!!! %s exists and is being overwritten" % params['corandir']
		shutil.rmtree(params['corandir'])
		os.mkdir(params['corandir'])
	else:
		os.mkdir(params['corandir'])
	classfile='cls.'+str(params['iter'])+'.tar'
	shutil.copy(classfile,os.path.join(params['corandir'],classfile))
	shutil.copy('proj.hed',os.path.join(params['corandir'],'proj.hed'))
	shutil.copy('proj.img',os.path.join(params['corandir'],'proj.img'))
	os.chdir(params['corandir'])
def createClassAverages(stack,projs,apmq,numprojs,boxsz,outclass="classes",rotated=False,shifted=False,dataext=".spi"):
	"""
	creates EMAN-style class average file "classes.hed" & "classes.img"
	and variance files "variances.hed" & "variances.img"
	from spider classification
	"""
	apFile.removeFile(outclass)
	outf=spyder.fileFilter(outclass)
	outvf="tmpvar"
	apmqlist = readDocFile(apmq)
	mySpi = spyder.SpiderSession(dataext=dataext, logo=False, log=False)

	# create file containing the number of particles matched to each projection
	mySpi.toSpiderQuiet(
		"VO MQ",
		"0.0",
		spyder.fileFilter(apmq),
		str(numprojs),
		"cls*****",
		"numinclass",
	)
	mySpi.close()
	os.remove("numinclass%s" % dataext)

	# create class average file
	mySpi = spyder.SpiderSession(dataext=dataext, logo=False, log=False)
	for i in range(0,numprojs):
		clsfile = readDocFile("cls%05d%s" % (i+1,dataext))
		if clsfile == []:
			apDisplay.printMsg("class %d has no particles" %(i+1))
			mySpi.toSpiderQuiet("BL","%s@%d" % (outf,(i+1)),"(%d,%d)" % (boxsz,boxsz),"N","(0.0)",)
			mySpi.toSpiderQuiet("BL","%s@%d" % (outvf,(i+1)),"(%d,%d)" % (boxsz,boxsz),"N","(0.0)",)
		else:
			mySpi.toSpiderQuiet("DE","_2@")
			mySpi.toSpiderQuiet("MS","_2@","%d,%d,1" % (boxsz,boxsz), str(len(clsfile)))
			for p in range(0,len(clsfile)):
				mySpi.toSpiderQuiet("DE","_1")
				# get the particle
				part = int(float(clsfile[p][2]))-1
				pimg = spyder.fileFilter(stack)+"@%d"%(part+1)
				
				rot=float(apmqlist[part][4])
				shx=float(apmqlist[part][5])
				shy=float(apmqlist[part][6])
				if shifted is True:
					shx=0
					shy=0
				if rotated is True:
					rot=0
				p_out="_2@%d" % (p+1)
				rotAndShiftImg(
					pimg,
					"_1",
					rot,
					shx,
					shy,
					inMySpi=mySpi
				)
				# mirror
				if int(float(apmqlist[part][2])) < 0:
					mirrorImg("_1",p_out,inMySpi=mySpi)
				else:
					mySpi.toSpiderQuiet("CP","_1",p_out)
			if len(clsfile) == 1:
				mySpi.toSpiderQuiet("CP","_2@1","%s@%d" % (outf,(i+1)))
				mySpi.toSpiderQuiet("BL","%s@%d" % (outvf,(i+1)),"(%d,%d)" % (boxsz,boxsz),"N","(0.0)",)
			else:
				mySpi.toSpiderQuiet("AS R","_2@*****","1-%d" % len(clsfile), "A","%s@%d" % (outf,(i+1)),"%s@%d" % (outvf,i+1))
	mySpi.close()

	# convert the class averages to EMAN class averages
	# read classes & projections for EMAN classes output
	if os.path.exists('variances.hed'):
		os.remove('variances.hed')
	if os.path.exists('variances.img'):
		os.remove('variances.img')
	if os.path.exists('classes.hed'):
		os.remove('classes.hed')
	if os.path.exists('classes.img'):
		os.remove('classes.img')
	### I would prefer to use apImagicFile.readImagic, writeImagic
	variances = EMAN.readImages(outvf+dataext,-1,-1,0)
	averages = EMAN.readImages(outf+dataext,-1,-1,0)
	projections=EMAN.readImages(projs,-1,-1,0)
	for i in range (0,numprojs):
		# copy projection to class average file
		projections[i].writeImage('classes.hed')
		projections[i].writeImage('variances.hed')
		# get num of particles in class
		clsfile=readDocFile("cls%05d%s" % (i+1,dataext))
		averages[i].setNImg(len(clsfile))
		averages[i].writeImage('classes.hed',-1)
		variances[i].setNImg(len(clsfile))
		variances[i].writeImage('variances.hed',-1)
		os.remove("cls%05d%s" % (i+1,dataext))
	os.remove(outf+dataext)
	return
Beispiel #16
0
for i in argv[1:]:
    s = i.split("=")

    if s[0] == "classes":
        Ncls = int(s[1])
    elif s[0] == "average":
        averageout = s[1]
    elif s[0] == "clsfiles":
        clsfiles = 1
    elif s[0] == "listout":
        listout = s[1]
    elif s[0] == "nosingle":
        nosingle = 1
    elif s[0] == "stack":
        data = EMAN.readImages(s[1], -1, -1)
        stackname = s[1]
    elif s[0] == "list":
        fin = open(s[1], "r")
        fsp = fin.readlines()
        fin.close()
        for i in fsp:
            x = EMAN.EMData()
            x.readImage(i.strip())
            data.append(x)
    else:
        print "Unknown argument ", i
        exit(1)

if len(data) == 0:
    print "No data to classify. Please specify stack= or list=."