Example #1
0
	def processAndSaveAllImages(self):
		print "Pre-processing images before picking\nNow is a good time to go get a candy bar"
		count = 0
		total = len(self.imgtree)
		for imgdata in self.imgtree:
			count += 1
			tiltdata = apTiltPair.getTiltPair(imgdata)
			if tiltdata is None:
				#reject it
				apDatabase.insertImgAssessmentStatus(imgdata, "notiltpair", False)
				continue

			#First the image
			imgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc')
			if os.path.isfile(imgpath):
				sys.stderr.write(".")
				#print "already processed: ",apDisplay.short(imgdata['filename'])
			else:
				sys.stderr.write("#")
				#print "processing: ",apDisplay.short(imgdata['filename'])
				apFindEM.processAndSaveImage(imgdata, params=self.params)

			#Now for its tilt pair
			tiltpath = os.path.join(self.params['rundir'], tiltdata['filename']+'.dwn.mrc')
			if os.path.isfile(tiltpath):
				sys.stderr.write(".")
				#print "already processed: ",apDisplay.short(tiltdata['filename'])
			else:
				sys.stderr.write("#")
				#print "processing: ",apDisplay.short(tiltdata['filename'])
				apFindEM.processAndSaveImage(tiltdata, params=self.params)

			if count % 30 == 0:
				sys.stderr.write(" %d left\n" % (total-count))

			### check if automation was already run
			outname1 = os.path.basename(imgdata['filename'])+"."+self.getExtension()
			outname2 = os.path.basename(tiltdata['filename'])+"."+self.getExtension()
			outfile1 = os.path.join(self.params['pickdatadir'], outname1)
			outfile2 = os.path.join(self.params['pickdatadir'], outname2)
			if os.path.isfile(outfile1):
				sys.stderr.write(",")
			else:
				### set important parameters
				picks1 =  self.getParticlePicks(imgdata, False)
				picks2 =  self.getParticlePicks(tiltdata, False)
				pixdiam = self.params['diam']/self.params['apix']/self.params['bin']
				tilt1 = apDatabase.getTiltAngleDeg(imgdata)
				tilt2 = apDatabase.getTiltAngleDeg(tiltdata)
				tiltdiff = abs(tilt2) - abs(tilt1)
				tiltaxis = self.params['inittiltaxis']
				### run tilt automation
				if self.params['autopick'] is True and self.params['importalign'] is False:
					if len(picks1) > 0 and len(picks2) > 0:
						autotilter = autotilt.autoTilt()
						result = autotilter.processTiltPair(imgpath, tiltpath, picks1, picks2,
							tiltdiff, outfile1, pixdiam, tiltaxis, msg=False)
						if os.path.isfile(outfile1):
							if os.path.exists(outfile2):
								os.remove(outfile2)
							os.symlink(os.path.basename(outfile1), outfile2)
					sys.stderr.write("%")
		apDisplay.printMsg("done")
		return
	parser.add_option("-o", "--outfile", dest="outfile",
		help="Particle picks and tilt parameters output file", metavar="FILE")
	parser.add_option("-d", "--diam", "--pixdiam", dest="pixdiam", type="float",
		help="Approximate diameter of particle in pixels", metavar="#")
	parser.add_option("-x", "--tiltaxis", dest="tiltaxis", type="float",
		help="Approximate tilt axis angle", metavar="#")
	params = apParam.convertParserToParams(parser)
	checkConflicts(params)


	### set important parameters
	imgfile1 = params['imgfile1']
	imgfile2 = params['imgfile2']
	picks1 = readPickFile(params['pickfile1'])
	picks2 = readPickFile(params['pickfile2'])
	theta = params['tiltangle']
	outfile = params['outfile']
	pixdiam = params['pixdiam']
	tiltaxis = params['tiltaxis']

	### run tilt automation
	autotilter = autotilt.autoTilt()
	result = autotilter.processTiltPair(imgfile1, imgfile2, picks1, picks2, theta, outfile, pixdiam, tiltaxis)

	if result is None:
		apDisplay.printWarning("Image processing failed")




                      dest="pixdiam",
                      type="float",
                      help="Approximate diameter of particle in pixels",
                      metavar="#")
    parser.add_option("-x",
                      "--tiltaxis",
                      dest="tiltaxis",
                      type="float",
                      help="Approximate tilt axis angle",
                      metavar="#")
    params = apParam.convertParserToParams(parser)
    checkConflicts(params)

    ### set important parameters
    imgfile1 = params['imgfile1']
    imgfile2 = params['imgfile2']
    picks1 = readPickFile(params['pickfile1'])
    picks2 = readPickFile(params['pickfile2'])
    theta = params['tiltangle']
    outfile = params['outfile']
    pixdiam = params['pixdiam']
    tiltaxis = params['tiltaxis']

    ### run tilt automation
    autotilter = autotilt.autoTilt()
    result = autotilter.processTiltPair(imgfile1, imgfile2, picks1, picks2,
                                        theta, outfile, pixdiam, tiltaxis)

    if result is None:
        apDisplay.printWarning("Image processing failed")
Example #4
0
    def runTiltAligner(self, imgdata, tiltdata):
        ### set tilt
        tilt1 = apDatabase.getTiltAngleDeg(imgdata)
        tilt2 = apDatabase.getTiltAngleDeg(tiltdata)
        theta = abs(tilt2) - abs(tilt1)

        ### pre-load particle picks
        picks1 = self.getParticlePicks(imgdata)
        picks2 = self.getParticlePicks(tiltdata)
        if len(picks1) < 10 or len(picks2) < 10:
            apDisplay.printWarning(
                "Not enough particles ot run program on image pair")
            self.badprocess = True
            return

        ### set image file 1
        imgname = imgdata['filename'] + ".dwn.mrc"
        imgpath = os.path.join(self.params['rundir'], imgname)

        ### set tilt file 2
        tiltname = tiltdata['filename'] + ".dwn.mrc"
        tiltpath = os.path.join(self.params['rundir'], tiltname)

        ### set out file
        outname1 = os.path.basename(
            imgdata['filename']) + "." + self.getExtension()
        outfile1 = os.path.join(self.params['pickdatadir'], outname1)
        outname2 = os.path.basename(
            tiltdata['filename']) + "." + self.getExtension()
        outfile2 = os.path.join(self.params['pickdatadir'], outname1)

        pixdiam = self.params['diam'] / self.params['apix'] / self.params['bin']
        tiltaxis = self.params['inittiltaxis']

        ### run tilt automation
        autotilter = autotilt.autoTilt()
        result = autotilter.processTiltPair(imgpath, tiltpath, picks1, picks2,
                                            theta, outfile1, pixdiam, tiltaxis)
        if result is None:
            apDisplay.printWarning("Image processing failed")
            self.badprocess = True
            return

        if os.path.isfile(outfile1) and outfile1 != outfile2:
            if os.path.exists(outfile2):
                os.remove(outfile2)
            os.symlink(os.path.basename(outfile1), outfile2)

        ### read alignment results
        if not os.path.isfile(outfile1):
            apDisplay.printWarning("Image processing failed")
            self.badprocess = True
            return
        self.data = tiltfile.readData(outfile1)
        self.currentpicks1 = numpy.asarray(self.data['picks1'])
        self.currentpicks2 = numpy.asarray(self.data['picks2'])

        #print self.data
        # 1. tilt data are copied to self.tiltparams by app
        # 2. particles picks are copied to self.peaks1 and self.peaks2 by app
        # 3. particle errors are copied to self.peakerrors by app
        # 4. assessment status is  copied to self.assess
        self.peaktree1 = apPeaks.convertListToPeaks(self.currentpicks1,
                                                    self.params)
        self.peaktree2 = apPeaks.convertListToPeaks(self.currentpicks2,
                                                    self.params)
        self.peakerrors = self.getRmsdArray()
        self.getOverlap(imgpath, tiltpath)
	def runTiltAligner(self, imgdata, tiltdata):
		### set tilt
		tilt1 = apDatabase.getTiltAngleDeg(imgdata)
		tilt2 = apDatabase.getTiltAngleDeg(tiltdata)
		theta = abs(tilt2) - abs(tilt1)

		### pre-load particle picks
		picks1 = self.getParticlePicks(imgdata)
		picks2 = self.getParticlePicks(tiltdata)
		if len(picks1) < 10 or len(picks2) < 10:
			apDisplay.printWarning("Not enough particles ot run program on image pair")
			self.badprocess = True
			return

		### set image file 1
		imgname  = imgdata['filename']+".dwn.mrc"
		imgpath  = os.path.join(self.params['rundir'], imgname)

		### set tilt file 2
		tiltname = tiltdata['filename']+".dwn.mrc"
		tiltpath = os.path.join(self.params['rundir'], tiltname)

		### set out file
		outname1 = os.path.basename(imgdata['filename'])+"."+self.getExtension()
		outfile1 = os.path.join(self.params['pickdatadir'], outname1)
		outname2 = os.path.basename(tiltdata['filename'])+"."+self.getExtension()
		outfile2 = os.path.join(self.params['pickdatadir'], outname1)

		pixdiam = self.params['diam']/self.params['apix']/self.params['bin']
		tiltaxis = self.params['inittiltaxis']

		### run tilt automation
		autotilter = autotilt.autoTilt()
		result = autotilter.processTiltPair(imgpath, tiltpath, picks1, picks2, theta, outfile1, pixdiam, tiltaxis)
		if result is None:
			apDisplay.printWarning("Image processing failed")
			self.badprocess = True
			return

		if os.path.isfile(outfile1) and outfile1 != outfile2:
			if os.path.exists(outfile2):
				os.remove(outfile2)
			os.symlink(os.path.basename(outfile1), outfile2)

		### read alignment results
		if not os.path.isfile(outfile1):
			apDisplay.printWarning("Image processing failed")
			self.badprocess = True
			return
		self.data = tiltfile.readData(outfile1)
		self.currentpicks1 = numpy.asarray(self.data['picks1'])
		self.currentpicks2 = numpy.asarray(self.data['picks2'])

		#print self.data
		# 1. tilt data are copied to self.tiltparams by app
		# 2. particles picks are copied to self.peaks1 and self.peaks2 by app
		# 3. particle errors are copied to self.peakerrors by app
		# 4. assessment status is  copied to self.assess
		self.peaktree1 = apPeaks.convertListToPeaks(self.currentpicks1, self.params)
		self.peaktree2 = apPeaks.convertListToPeaks(self.currentpicks2, self.params)
		self.peakerrors = self.getRmsdArray()
		self.getOverlap(imgpath, tiltpath)