def prepareRecon(self): processdir = self.params['rundir'] stackdir = self.params['tiltseriesdir'] thickness = int(self.params['thickness']) # Make Sample Tomogram for etomo manual positioning and exit aligndir = self.alignerdata['alignrun']['path']['path'] templatedir = os.path.join(os.path.dirname(apImod.__file__), 'data') yspacing_fraction = 0.66 apImod.sampleRecon(stackdir, processdir, aligndir, self.seriesname, 10, 0.66, thickness, self.excludelist) stackpath = os.path.join(stackdir, self.seriesname + ".st") yspacing_pixel = apFile.getMrcFileShape( stackpath)[1] * yspacing_fraction * 0.5 has_rotation = False if self.alignerdata['protomo']: if self.alignerdata['refine_cycle']['cycle'] > 0: has_rotation = True apImod.makeFilesForETomoSampleRecon(processdir, stackdir, aligndir, templatedir, self.seriesname, thickness, self.pixelsize, yspacing_pixel, has_rotation) paramfile = os.path.join(processdir, '%s_sample.params' % (self.params['runname'])) apParam.dumpParameters(self.params, paramfile) return
def projectFullZ(processdir, runname, seriesname, bin=1, rotx=True, flipyz=False): """ # Command for projecting full tomogram to z-axis # # Tomography reconstruction y and z are usually flipped # full tomogram mrc file axes [x,z,y] # clip average command need [x,y,z] clip flipyz 09feb18c_002_full.rec temp.mrc clip avg -2d -iz 0-199 temp.mrc projection.mrc """ inputparams = { 'recon': os.path.join(processdir, seriesname + "_full.rec"), 'temp': os.path.join(processdir, "temp.rec"), 'project': os.path.join(processdir, seriesname + "_zproject.mrc"), } fullshape = apFile.getMrcFileShape(inputparams['recon']) commands = [] if rotx or flipyz: op = '' if rotx: op += ' rotx' if flipyz: op += ' flipyz' lookup = {'y': 0, 'z': 1} inputparams['3d'] = inputparams['temp'] commands.append("$clip" + op + " %s %s" % ( inputparams['recon'], inputparams['temp'], )) else: lookup = {'y': 1, 'z': 0} inputparams['3d'] = inputparams['recon'] # limit slices for projection to 200 to save time. zcenter = int(fullshape[lookup['z']] / 2) zstart = max(0, zcenter - 100) zend = min(fullshape[lookup['z']] - 1, zcenter + 99) commands.append( "$clip avg -2d -iz %d-%d %s %s" % ( zstart, zend, inputparams['3d'], inputparams['project'], ), ) writeCommandAndRun( processdir, 'projectZ', commands, [inputparams['temp'], inputparams['project'], 'projectZ.log']) if bin > 1: # unbin the projection a = mrc.read(inputparams['project']) b = apImage.scaleImage(a, bin) mrc.write(b, inputparams['project']) return inputparams['project']
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 projectFullZ(processdir, runname, seriesname,bin=1,rotx=True,flipyz=False): """ # Command for projecting full tomogram to z-axis # # Tomography reconstruction y and z are usually flipped # full tomogram mrc file axes [x,z,y] # clip average command need [x,y,z] clip flipyz 09feb18c_002_full.rec temp.mrc clip avg -2d -iz 0-199 temp.mrc projection.mrc """ inputparams = { 'recon': os.path.join(processdir, seriesname+"_full.rec"), 'temp': os.path.join(processdir, "temp.rec"), 'project': os.path.join(processdir, seriesname+"_zproject.mrc"), } fullshape = apFile.getMrcFileShape(inputparams['recon']) commands = [] if rotx or flipyz: op = '' if rotx: op += ' rotx' if flipyz: op += ' flipyz' lookup = {'y':0,'z':1} inputparams['3d'] = inputparams['temp'] commands.append( "$clip"+op+" %s %s" % (inputparams['recon'],inputparams['temp'], ) ) else: lookup = {'y':1,'z':0} inputparams['3d'] = inputparams['recon'] # limit slices for projection to 200 to save time. zcenter = int(fullshape[lookup['z']] / 2) zstart = max(0,zcenter - 100) zend = min(fullshape[lookup['z']]-1,zcenter + 99) commands.append( "$clip avg -2d -iz %d-%d %s %s" % (zstart,zend, inputparams['3d'],inputparams['project'], ), ) writeCommandAndRun(processdir,'projectZ',commands,[inputparams['temp'],inputparams['project'],'projectZ.log']) if bin > 1: # unbin the projection a = mrc.read(inputparams['project']) b = apImage.scaleImage(a,bin) mrc.write(b,inputparams['project']) return inputparams['project']
def trimVolume(processdir, runname, seriesname, volumename, center, offsetz, size,rotx=True): """ # Command for triming reconstructed volume # # Full Tomography reconstruction is X,Z,Y need to rotate around x # full tomogram array axes [z,y,x] # imod full_rec axes [y,z,x] # center and size axes [x,y,z] trimvol -x 390,460 -z 477,537 -rx 08aug14f_008_full.rec test.rec """ inputparams = { 'recon': os.path.join(processdir, seriesname+"_full.rec"), 'subvolume': os.path.join(processdir, runname+"/",volumename+"/",seriesname+"_"+volumename+".rec"), 'xrange0': max(1,center[0] - size[0]/2), 'yrange0': max(1,center[1] - size[1]/2), } if rotx: lookup = {'y':0,'z':1} else: lookup = {'y':1,'z':0} fullshape = apFile.getMrcFileShape(inputparams['recon']) center = list(center) center.append(fullshape[lookup['z']]/2+offsetz) inputparams['zrange0'] = max(1,center[2] - size[2]/2) inputparams['xrange1'] = min(fullshape[2],inputparams['xrange0'] + size[0]-1) inputparams['yrange1'] = min(fullshape[lookup['y']],inputparams['yrange0'] + size[1]-1) inputparams['zrange1'] = min(fullshape[lookup['z']],inputparams['zrange0'] + size[2]-1) if rotx: commands = [ "$trimvol -x %d,%d -y %d,%d -z %d,%d -rx %s %s" % (inputparams['xrange0'],inputparams['xrange1'], inputparams['zrange0'],inputparams['zrange1'], inputparams['yrange0'],inputparams['yrange1'], inputparams['recon'], inputparams['subvolume'], ), ] else: commands = [ "$trimvol -x %d,%d -y %d,%d -z %d,%d %s %s" % (inputparams['xrange0'],inputparams['xrange1'], inputparams['yrange0'],inputparams['yrange1'], inputparams['zrange0'],inputparams['zrange1'], inputparams['recon'], inputparams['subvolume'], ), ] writeCommandAndRun(processdir,'trimvol',commands,[inputparams['subvolume'],'trimvol.log'])
def prepareRecon(self): processdir = self.params['rundir'] stackdir = self.params['tiltseriesdir'] thickness = int(self.params['thickness']) # Make Sample Tomogram for etomo manual positioning and exit aligndir = self.alignerdata['alignrun']['path']['path'] templatedir = os.path.join(os.path.dirname(apImod.__file__),'data') yspacing_fraction = 0.66 apImod.sampleRecon(stackdir, processdir, aligndir, self.seriesname, 10, 0.66, thickness, self.excludelist) stackpath = os.path.join(stackdir, self.seriesname+".st") yspacing_pixel = apFile.getMrcFileShape(stackpath)[1] * yspacing_fraction * 0.5 has_rotation = False if self.alignerdata['protomo']: if self.alignerdata['refine_cycle']['cycle'] > 0: has_rotation = True apImod.makeFilesForETomoSampleRecon(processdir, stackdir,aligndir, templatedir, self.seriesname, thickness, self.pixelsize,yspacing_pixel,has_rotation) paramfile = os.path.join(processdir,'%s_sample.params' % (self.params['runname'])) apParam.dumpParameters(self.params, paramfile) return
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 trimVolume(processdir, runname, seriesname, volumename, center, offsetz, size, rotx=True): """ # Command for triming reconstructed volume # # Full Tomography reconstruction is X,Z,Y need to rotate around x # full tomogram array axes [z,y,x] # imod full_rec axes [y,z,x] # center and size axes [x,y,z] trimvol -x 390,460 -z 477,537 -rx 08aug14f_008_full.rec test.rec """ inputparams = { 'recon': os.path.join(processdir, seriesname + "_full.rec"), 'subvolume': os.path.join(processdir, runname + "/", volumename + "/", seriesname + "_" + volumename + ".rec"), 'xrange0': max(1, center[0] - size[0] / 2), 'yrange0': max(1, center[1] - size[1] / 2), } if rotx: lookup = {'y': 0, 'z': 1} else: lookup = {'y': 1, 'z': 0} fullshape = apFile.getMrcFileShape(inputparams['recon']) center = list(center) center.append(fullshape[lookup['z']] / 2 + offsetz) inputparams['zrange0'] = max(1, center[2] - size[2] / 2) inputparams['xrange1'] = min(fullshape[2], inputparams['xrange0'] + size[0] - 1) inputparams['yrange1'] = min(fullshape[lookup['y']], inputparams['yrange0'] + size[1] - 1) inputparams['zrange1'] = min(fullshape[lookup['z']], inputparams['zrange0'] + size[2] - 1) if rotx: commands = [ "$trimvol -x %d,%d -y %d,%d -z %d,%d -rx %s %s" % ( inputparams['xrange0'], inputparams['xrange1'], inputparams['zrange0'], inputparams['zrange1'], inputparams['yrange0'], inputparams['yrange1'], inputparams['recon'], inputparams['subvolume'], ), ] else: commands = [ "$trimvol -x %d,%d -y %d,%d -z %d,%d %s %s" % ( inputparams['xrange0'], inputparams['xrange1'], inputparams['yrange0'], inputparams['yrange1'], inputparams['zrange0'], inputparams['zrange1'], inputparams['recon'], inputparams['subvolume'], ), ] writeCommandAndRun(processdir, 'trimvol', commands, [inputparams['subvolume'], 'trimvol.log'])