예제 #1
0
def makeFilesForETomoSampleRecon(processdir, stackdir,aligndir, templatedir, seriesname, thickness, pixelsize,yspacing,has_rotation=False):
	'''
	Make or link local files required by etomo to redo sampling, creating tomopitch model, and reconstruct the volume.
	'''
	# etomo status file
	createETomoBoundaryModelEDF(processdir,templatedir,seriesname,thickness,pixelsize)
	# required by remaking sample tomograms inside etomo
	if has_rotation:
		apDisplay.printWarning('eTomo wants to regenerate global alignment from non-rotated local alignment.  This alignment with rotation will not work right')
	else:
		# prexf file is generated from database values if this function is called from tomomaker.  It is better not to change it if exists.
		prexf = seriesname+".prexf"
		alignprexf = os.path.join(aligndir,prexf)
		localprexf = os.path.join(processdir,prexf)
		apFile.safeCopy(alignprexf,localprexf)
		writeETomoNewstComTemplate(processdir, seriesname)
		rawtltname = '%s.rawtlt' % (seriesname)
		shutil.copy(os.path.join(stackdir,rawtltname),os.path.join(processdir,rawtltname))
	# required by tomopitch model making
	tomopitchname = 'tomopitch.com'
	imodcomdir = os.path.join(os.environ['IMOD_DIR'],'com')
	tomopitchpath = os.path.join(processdir,tomopitchname)
	shutil.copy(os.path.join(imodcomdir,tomopitchname),tomopitchpath)
	apFile.replaceUniqueLinePatternInTxtFile(tomopitchpath,'SpacingInY','SpacingInY\t%.1f\n' % yspacing)
	
	# required by "Final Aligned Stack" step
	stackname = '%s.st' % (seriesname)
	apFile.safeSymLink(os.path.join(stackdir,stackname),os.path.join(processdir,stackname))
	def start(self):
		
		### Set FSC resolution criterion
		self.fscResCriterion = 0.145
		
		### database entry parameters
		package_table = 'ApRelionIterData|relionParams'
		
		### set projection-matching path
		#self.projmatchpath = os.path.abspath(os.path.join(self.params['rundir'], "recon"))
		self.projmatchpath = os.path.abspath(self.params['rundir'])
	
		### determine which iterations to upload
		lastiter = self.findLastCompletedIteration()
		uploadIterations = self.verifyUploadIterations(lastiter)	

		for iteration in uploadIterations:
		
			apDisplay.printColor("uploading iteration %d" % iteration, "cyan")
			
			package_database_object = self.instantiateProjMatchParamsData(iteration)
			
			### move FSC file to results directory
			self.FSCExists = self.convertFSCFileForIteration(iteration)
				
			### create a text file with particle information
			self.createParticleDataFile(iteration, package_database_object)
					
			# Use Dmitrys code to combine the 2 halves mrcs
			### create mrc file of map for iteration and reference number

			half1vol = os.path.join(self.projmatchpath, "recon_it%.3d_half1_class001.mrc" % iteration)
			half2vol = os.path.join(self.projmatchpath, "recon_it%.3d_half2_class001.mrc" % iteration)
			newvol   = os.path.join(self.resultspath, "recon_%s_it%.3d_vol001.mrc" % (self.params['timestamp'], iteration))
			self.combineMRCs( half1vol, half2vol, newvol )
			if iteration == lastiter:
				oldvol = os.path.join(self.projmatchpath, "recon_class001.mrc")
				apFile.safeCopy(oldvol, newvol)
			
			### make chimera snapshot of volume
			self.createChimeraVolumeSnapshot(newvol, iteration)
			
			### instantiate database objects
			self.insertRefinementRunData(iteration)
			self.insertRefinementIterationData(iteration, package_table, package_database_object)

			###  make symlink only after successful insertion				
#			if os.path.isfile(newvol):
#				if os.path.isfile(oldvol):
#					apFile.removeFile(oldvol,True)
#				try:
#					os.symlink(newvol, oldvol)
#				except IOError, e:
#					print e

		### calculate Euler jumps
		self.calculateEulerJumpsAndGoodBadParticles(uploadIterations)	
	def start(self):
		
		### Set FSC resolution criterion
		self.fscResCriterion = 0.145
		
		### database entry parameters
		package_table = 'ApRelionIterData|relionParams'
		
		### set projection-matching path
		#self.projmatchpath = os.path.abspath(os.path.join(self.params['rundir'], "recon"))
		self.projmatchpath = os.path.abspath(self.params['rundir'])
	
		### determine which iterations to upload
		lastiter = self.findLastCompletedIteration()
		uploadIterations = self.verifyUploadIterations(lastiter)	

		for iteration in uploadIterations:
		
			apDisplay.printColor("uploading iteration %d" % iteration, "cyan")
			
			package_database_object = self.instantiateProjMatchParamsData(iteration)
			
			### move FSC file to results directory
			self.FSCExists = self.convertFSCFileForIteration(iteration)
				
			### create a text file with particle information
			self.createParticleDataFile(iteration, package_database_object)
					
			# Use Dmitrys code to combine the 2 halves mrcs
			### create mrc file of map for iteration and reference number

			half1vol = os.path.join(self.projmatchpath, "recon_it%.3d_half1_class001.mrc" % iteration)
			half2vol = os.path.join(self.projmatchpath, "recon_it%.3d_half2_class001.mrc" % iteration)
			newvol   = os.path.join(self.resultspath, "recon_%s_it%.3d_vol001.mrc" % (self.params['timestamp'], iteration))
			self.combineMRCs( half1vol, half2vol, newvol )
			if iteration == lastiter:
				oldvol = os.path.join(self.projmatchpath, "recon_class001.mrc")
				apFile.safeCopy(oldvol, newvol)
			
			### make chimera snapshot of volume
			self.createChimeraVolumeSnapshot(newvol, iteration)
			
			### instantiate database objects
			self.insertRefinementRunData(iteration)
			self.insertRefinementIterationData(iteration, package_table, package_database_object)

			###  make symlink only after successful insertion				
#			if os.path.isfile(newvol):
#				if os.path.isfile(oldvol):
#					apFile.removeFile(oldvol,True)
#				try:
#					os.symlink(newvol, oldvol)
#				except IOError, e:
#					print e

		### calculate Euler jumps
		self.calculateEulerJumpsAndGoodBadParticles(uploadIterations)	
예제 #4
0
def sampleRecon(stackdir,
                processdir,
                aligndir,
                seriesname,
                samplesize=10,
                sampleoffset=0.66,
                thickness=100,
                excludelist=[]):
    inputparams = {
        'alignedstack': seriesname + ".ali",
        'xf': seriesname + ".xf",
        'rawtilts': os.path.join(stackdir, seriesname + ".rawtlt"),
        'tilts': os.path.join(seriesname + ".tlt"),
        'tiltstack': os.path.join(stackdir, seriesname + ".st"),
        'recon': seriesname + "_full.rec",
        'scale': 250.0,
        'thickness': thickness,
    }
    alignxf = os.path.join(aligndir, seriesname + ".xf")
    linkxf = inputparams['xf']
    files_to_copy = [(alignxf, linkxf),
                     (inputparams['rawtilts'], inputparams['tilts'])]
    for filepair in files_to_copy:
        apFile.safeCopy(filepair[0], filepair[1])
    st_shape = apFile.getMrcFileShape(inputparams['tiltstack'])
    # shape is in (z, y, x) size for imod is in (x,y)
    inputparams['size'] = (st_shape[2], st_shape[1])
    total_tilts = st_shape[0]
    if samplesize == 'all' or samplesize > total_tilts:
        samplesize = total_tilts
    # calculate sampletilt range that reduces the process time
    sampletilt_start = max(int((total_tilts - samplesize) / 2.0), 1)
    sampletilt_end = min(sampletilt_start + samplesize - 1, total_tilts)
    # calculate the 3 offsets
    sampleoffset = int(st_shape[1] * sampleoffset / 2.0)
    st_y_center = int(st_shape[1] / 2.0)
    sampleoffsets = {'mid': 0, 'top': sampleoffset, 'bot': (-1) * sampleoffset}
    # write basic tilt.com without processdir
    comfilename = writeTiltCom(processdir, inputparams['alignedstack'],
                               inputparams['recon'], inputparams['tilts'],
                               inputparams['size'], inputparams['thickness'],
                               0.0, 0.0, (0, inputparams['scale']),
                               excludelist)
    # make commandlines
    commands = []
    for key in sampleoffsets.keys():
        commands.extend([
            '$newstack -size ,%d -offset 0,%d -xf %s %s %s' %
            (total_tilts, sampleoffsets[key], inputparams['xf'],
             inputparams['tiltstack'], inputparams['alignedstack']),
            '$sampletilt %d %d %d %s %s.rec tilt.com' %
            (sampletilt_start, sampletilt_end,
             sampleoffsets[key] + st_y_center, seriesname, key)
        ])
    writeCommandAndRun(processdir, 'sample', commands,
                       [inputparams['alignedstack'], 'sample.log'])
    def start(self):

        ### database entry parameters
        package_table = 'ApFrealignIterData|frealignParams'

        ### set projection-matching path
        self.projmatchpath = os.path.abspath(
            os.path.join(self.params['rundir'], "recon"))

        ### determine which iterations to upload
        lastiter = self.findLastCompletedIteration()
        uploadIterations = self.verifyUploadIterations(lastiter)

        for iteration in uploadIterations:

            apDisplay.printColor("uploading iteration %d" % iteration, "cyan")

            package_database_object = self.instantiateProjMatchParamsData(
                iteration)

            if not self.params['euleronly']:
                ### move FSC file to results directory
                self.FSCExists = self.convertFSCFileForIteration(iteration)

            ### create a text file with particle information
            self.createParticleDataFile(iteration, package_database_object)

            if not self.params['euleronly']:
                ### create mrc file of map for iteration and reference number
                oldvol = os.path.join(self.projmatchpath,
                                      "threed.%03da.mrc" % iteration)
                newvol = os.path.join(
                    self.resultspath, "recon_%s_it%.3d_vol001.mrc" %
                    (self.params['timestamp'], iteration))
                apFile.safeCopy(oldvol, newvol)

                ### make chimera snapshot of volume
                self.createChimeraVolumeSnapshot(newvol, iteration)

            ### instantiate database objects
            self.insertRefinementRunData(iteration)
            self.insertRefinementIterationData(iteration, package_table,
                                               package_database_object)

            ###  make symlink only after successful insertion
            if not self.params['euleronly'] and os.path.isfile(newvol):
                if os.path.isfile(oldvol):
                    apFile.removeFile(oldvol, True)
                try:
                    os.symlink(newvol, oldvol)
                except IOError, e:
                    print e
	def start(self):
		
		### database entry parameters
		package_table = 'ApFrealignIterData|frealignParams'
		
		### set projection-matching path
		self.projmatchpath = os.path.abspath(os.path.join(self.params['rundir'], "recon"))
	
		### determine which iterations to upload
		lastiter = self.findLastCompletedIteration()
		uploadIterations = self.verifyUploadIterations(lastiter)	

		for iteration in uploadIterations:
		
			apDisplay.printColor("uploading iteration %d" % iteration, "cyan")
			
			package_database_object = self.instantiateProjMatchParamsData(iteration)

			if not self.params['euleronly']:			
				### move FSC file to results directory
				self.FSCExists = self.convertFSCFileForIteration(iteration)
				
			### create a text file with particle information
			self.createParticleDataFile(iteration, package_database_object)
					
			if not self.params['euleronly']:			
				### create mrc file of map for iteration and reference number
				oldvol = os.path.join(self.projmatchpath, "threed.%03da.mrc" % iteration)
				newvol = os.path.join(self.resultspath, "recon_%s_it%.3d_vol001.mrc" % (self.params['timestamp'], iteration))
				apFile.safeCopy(oldvol, newvol)
			
				### make chimera snapshot of volume
				self.createChimeraVolumeSnapshot(newvol, iteration)
			
			### instantiate database objects
			self.insertRefinementRunData(iteration)
			self.insertRefinementIterationData(iteration, package_table, package_database_object)

			###  make symlink only after successful insertion				
			if not self.params['euleronly'] and os.path.isfile(newvol):
				if os.path.isfile(oldvol):
					apFile.removeFile(oldvol,True)
				try:
					os.symlink(newvol, oldvol)
				except IOError, e:
					print e
예제 #7
0
def makeFilesForETomoSampleRecon(processdir,
                                 stackdir,
                                 aligndir,
                                 templatedir,
                                 seriesname,
                                 thickness,
                                 pixelsize,
                                 yspacing,
                                 has_rotation=False):
    '''
        Make or link local files required by etomo to redo sampling, creating tomopitch model, and reconstruct the volume.
        '''
    # etomo status file
    createETomoBoundaryModelEDF(processdir, templatedir, seriesname, thickness,
                                pixelsize)
    # required by remaking sample tomograms inside etomo
    if has_rotation:
        apDisplay.printWarning(
            'eTomo wants to regenerate global alignment from non-rotated local alignment.  This alignment with rotation will not work right'
        )
    else:
        # prexf file is generated from database values if this function is called from tomomaker.  It is better not to change it if exists.
        prexf = seriesname + ".prexf"
        alignprexf = os.path.join(aligndir, prexf)
        localprexf = os.path.join(processdir, prexf)
        apFile.safeCopy(alignprexf, localprexf)
        writeETomoNewstComTemplate(processdir, seriesname)
        rawtltname = '%s.rawtlt' % (seriesname)
        shutil.copy(os.path.join(stackdir, rawtltname),
                    os.path.join(processdir, rawtltname))
    # required by tomopitch model making
    tomopitchname = 'tomopitch.com'
    imodcomdir = os.path.join(os.environ['IMOD_DIR'], 'com')
    tomopitchpath = os.path.join(processdir, tomopitchname)
    shutil.copy(os.path.join(imodcomdir, tomopitchname), tomopitchpath)
    apFile.replaceUniqueLinePatternInTxtFile(tomopitchpath, 'SpacingInY',
                                             'SpacingInY\t%.1f\n' % yspacing)

    # required by "Final Aligned Stack" step
    stackname = '%s.st' % (seriesname)
    apFile.safeSymLink(os.path.join(stackdir, stackname),
                       os.path.join(processdir, stackname))
예제 #8
0
def sampleRecon(stackdir, processdir, aligndir, seriesname, samplesize=10, sampleoffset=0.66, thickness=100, excludelist=[]):
	inputparams = {
		'alignedstack': seriesname+".ali",
		'xf': seriesname+".xf",
		'rawtilts': os.path.join(stackdir, seriesname+".rawtlt"),
		'tilts': os.path.join(seriesname+".tlt"),
		'tiltstack': os.path.join(stackdir, seriesname+".st"),
		'recon': seriesname+"_full.rec",
		'scale': 250.0,
		'thickness': thickness,
	}
	alignxf = os.path.join(aligndir, seriesname+".xf")
	linkxf = inputparams['xf']
	files_to_copy = [(alignxf,linkxf),(inputparams['rawtilts'],inputparams['tilts'])]
	for filepair in files_to_copy:
		apFile.safeCopy(filepair[0],filepair[1])
	st_shape = apFile.getMrcFileShape(inputparams['tiltstack'])
	# shape is in (z, y, x) size for imod is in (x,y)
	inputparams['size']=(st_shape[2],st_shape[1])
	total_tilts = st_shape[0]
	if samplesize == 'all' or samplesize > total_tilts:
		samplesize = total_tilts
	# calculate sampletilt range that reduces the process time
	sampletilt_start = max(int((total_tilts - samplesize)/2.0),1)
	sampletilt_end = min(sampletilt_start + samplesize - 1,total_tilts)
	# calculate the 3 offsets
	sampleoffset = int (st_shape[1] * sampleoffset / 2.0)
	st_y_center = int (st_shape[1] / 2.0)
	sampleoffsets = {'mid':0,'top':sampleoffset,'bot':(-1)*sampleoffset}
	# write basic tilt.com without processdir
	comfilename = writeTiltCom(processdir,inputparams['alignedstack'],inputparams['recon'],inputparams['tilts'],inputparams['size'],inputparams['thickness'],0.0,0.0,(0,inputparams['scale']),excludelist)
	# make commandlines
	commands = []
	for key in sampleoffsets.keys():
		commands.extend([
			'$newstack -size ,%d -offset 0,%d -xf %s %s %s' % (total_tilts,sampleoffsets[key],inputparams['xf'],inputparams['tiltstack'],inputparams['alignedstack']),
			'$sampletilt %d %d %d %s %s.rec tilt.com' % (sampletilt_start,sampletilt_end,sampleoffsets[key]+st_y_center,seriesname,key)
		])
	writeCommandAndRun(processdir,'sample',commands,[inputparams['alignedstack'],'sample.log'])
	def copyFrames(self,source,destination):
		apFile.safeCopy(source, destination)
예제 #10
0
def fakeOutput(imgname, ccmapfile, params):
    a = apImage.mrcToArray(imgname)
    a = numpy.zeros(a.shape)
    apImage.arrayToMrc(a, ccmapfile)
    apFile.safeCopy('/home/acheng/Projects/Gfindem/example.box',
                    getBoxFileName(ccmapfile))
예제 #11
0
def fakeOutput(imgname,ccmapfile,params):
	a = apImage.mrcToArray(imgname)
	a = numpy.zeros(a.shape)
	apImage.arrayToMrc(a,ccmapfile)
	apFile.safeCopy('/home/acheng/Projects/Gfindem/example.box', getBoxFileName(ccmapfile))