def start(self): tomogram = self.params['rundir']+'/'+self.tomodata['name']+'.rec' if not os.path.isfile(tomogram): tomogram = self.params['rundir']+'/'+self.tomodata['name']+'.mrc' if not os.path.isfile(tomogram): apDisplay.printError("tomogram not exist") apTomo.makeMovie(tomogram,self.params['maxsize']) apTomo.makeProjection(tomogram,self.params['maxsize'])
def start(self): commit = self.params['commit'] description = self.params['description'] processdir = self.params['fulltomodir'] runname = self.params['runname'] offsetz = self.params['offsetz'] subbin = self.params['bin'] invert = self.params['invert'] fulltomodata = apTomo.getFullTomoData(self.params['fulltomoId']) #subvolume making if (self.params['selexonId'] is not None or self.params['stackId']) and fulltomodata is not None: sessiondata = fulltomodata['session'] seriesname = fulltomodata['name'].rstrip('_full') fullbin = fulltomodata['bin'] if not fullbin: apDisplay.printWarning("no binning in full tomogram, something is wrong, use alignment bin for now") fullbin = fulltomodata['aligner']['alignrun']['bin'] fulltomopath = os.path.join(fulltomodata['reconrun']['path']['path'], seriesname+"_full.rec") fulltomoheader = mrc.readHeaderFromFile(fulltomopath) fulltomoshape = fulltomoheader['shape'] if self.params['sizez'] > fulltomoshape[1]*fullbin : self.params['sizez'] = fulltomoshape[1]*fullbin subrunname = self.params['subrunname'] volumeindex = apTomo.getLastVolumeIndex(fulltomodata) + 1 dimension = {'x':int(self.params['sizex']),'y':int(self.params['sizey']),'z':int(self.params['sizez'])} zprojimagedata = fulltomodata['zprojection'] apDisplay.printMsg("getting pixelsize") pixelsize = apTomo.getTomoPixelSize(zprojimagedata) * fullbin * subbin gtransform = [1,0,0,1,0,0] if self.params['selexonId']: particles = apParticle.getParticles(zprojimagedata, self.params['selexonId']) if self.params['stackId']: particles,stackparticles = apStack.getImageParticles(zprojimagedata, self.params['stackId']) stackdata = apStack.getOnlyStackData(self.params['stackId']) for p, particle in enumerate(particles): print particle['xcoord'],particle['ycoord'],fullbin center = apTomo.transformParticleCenter(particle,fullbin,gtransform) size = (dimension['x']/fullbin,dimension['y']/fullbin,dimension['z']/fullbin) volumename = 'volume%d'% (volumeindex,) volumedir = os.path.join(processdir,subrunname+'/',volumename+'/') apParam.createDirectory(volumedir) apImod.trimVolume(processdir, subrunname,seriesname,volumename,center,offsetz,size,True) long_volumename = seriesname+'_'+volumename subvolumepath = os.path.join(processdir, runname+"/",volumename+"/",long_volumename+".rec") if subbin > 1 or invert: apTomo.modifyVolume(subvolumepath,subbin,invert) if commit: subtomorundata = apTomo.insertSubTomoRun(sessiondata, self.params['selexonId'],self.params['stackId'],subrunname,invert,subbin) subtomodata = apTomo.insertSubTomogram(fulltomodata,subtomorundata, particle,offsetz,dimension, volumedir,long_volumename,volumeindex,pixelsize, description) apTomo.makeMovie(subvolumepath) apTomo.makeProjection(subvolumepath) volumeindex += 1
def start(self): commit = self.params['commit'] processdir = self.params['fulltomodir'] runname = self.params['runname'] subbin = self.params['bin'] invert = self.params['invert'] self.fulltomodata = apTomo.getFullTomoData(self.params['fulltomoId']) if self.fulltomodata is None: return #subvolume making self.seriesname = self.fulltomodata['name'].rstrip('_full') self.fulltomoshape = self.getFullTomoShape() sessiondata = self.fulltomodata['session'] self.fullbin = self.fulltomodata['bin'] if not self.fullbin: apDisplay.printWarning( "no binning in full tomogram, something is wrong, use alignment bin for now" ) self.fullbin = self.fulltomodata['aligner']['alignrun']['bin'] volumeindex = apTomo.getLastVolumeIndex(self.fulltomodata) + 1 zprojimagedata = self.fulltomodata['zprojection'] apDisplay.printMsg("getting pixelsize") pixelsize = apTomo.getTomoPixelSize( zprojimagedata) * self.fullbin * subbin particles = self.getParticles(zprojimagedata) for p, particle in enumerate(particles): size, offsetz = self.recon3D(particle, volumeindex) volumedir = os.path.dirname(self.subvolumepath) # not include .rec long_volumename = os.path.basename(self.subvolumepath)[:-4] # size is the subtomogram dimension tuple after full tomogram binning if commit: subtomorundata = apTomo.insertSubTomoRun( sessiondata, self.getParticleSelectionRunId(), self.getStackId(), self.params['subrunname'], invert, subbin) description = self.updateDescription() subtomodata = apTomo.insertSubTomogram( self.fulltomodata, subtomorundata, particle, offsetz, { 'x': size[0], 'y': size[1], 'z': size[2] }, volumedir, long_volumename, volumeindex, pixelsize, description) apTomo.makeMovie(self.subvolumepath) apTomo.makeProjection(self.subvolumepath) volumeindex += 1
def start(self): commit = self.params['commit'] processdir = self.params['fulltomodir'] runname = self.params['runname'] subbin = self.params['bin'] invert = self.params['invert'] self.fulltomodata = apTomo.getFullTomoData(self.params['fulltomoId']) if self.fulltomodata is None: return #subvolume making self.seriesname = self.fulltomodata['name'].rstrip('_full') self.fulltomoshape = self.getFullTomoShape() sessiondata = self.fulltomodata['session'] self.fullbin = self.fulltomodata['bin'] if not self.fullbin: apDisplay.printWarning("no binning in full tomogram, something is wrong, use alignment bin for now") self.fullbin = self.fulltomodata['aligner']['alignrun']['bin'] volumeindex = apTomo.getLastVolumeIndex(self.fulltomodata) + 1 zprojimagedata = self.fulltomodata['zprojection'] apDisplay.printMsg("getting pixelsize") pixelsize = apTomo.getTomoPixelSize(zprojimagedata) * self.fullbin * subbin particles = self.getParticles(zprojimagedata) for p, particle in enumerate(particles): size,offsetz = self.recon3D(particle,volumeindex) volumedir = os.path.dirname(self.subvolumepath) # not include .rec long_volumename = os.path.basename(self.subvolumepath)[:-4] # size is the subtomogram dimension tuple after full tomogram binning if commit: subtomorundata = apTomo.insertSubTomoRun(sessiondata, self.getParticleSelectionRunId(),self.getStackId(),self.params['subrunname'],invert,subbin) description = self.updateDescription() subtomodata = apTomo.insertSubTomogram(self.fulltomodata,subtomorundata, particle,offsetz,{'x':size[0],'y':size[1],'z':size[2]}, volumedir,long_volumename,volumeindex,pixelsize, description) apTomo.makeMovie(self.subvolumepath) apTomo.makeProjection(self.subvolumepath) volumeindex += 1
def start(self): cleanlist = [] # imod needs the recon files named as .rec It may need some fix later if self.params["name"] is None: self.setNewFileName() apDisplay.printColor("Naming tomogram as: " + self.params["name"], "cyan") newtomopath = os.path.join(self.params["rundir"], self.params["name"] + ".rec") origtomopath = self.params["file"] origxfpath = self.params["oldxffile"] apParam.createDirectory(self.params["aligndir"]) newxfpath = os.path.join(self.params["aligndir"], self.params["newxffile"]) order = self.params["order"] voltransform = self.params["transform"] bin = self.params["bin"] self.getImageShapeFromTiltSeries() self.getOriginalVolumeShape() if os.path.isfile(newtomopath): uploaded_before = self.checkExistingFile() if uploaded_before: return else: currenttomopath = origtomopath if self.params["full"]: ### full tomogram upload, may need to pad to the image size if self.params["order"] == "XZY" and not voltransform: apDisplay.printMsg("Default full tomogram orientation with original handness") else: if voltransform: apDisplay.printMsg("Transforming original tomogram....") currenttomopath = apImod.transformVolume(origtomopath, voltransform) cleanlist.append(currenttomopath) ### padding the XZY tomogram to the image size currentheader = mrc.readHeaderFromFile(currenttomopath) currentshape = currentheader["shape"] currentxyshape = currentshape[0], currentshape[2] imageshape = self.imageshape if currentxyshape[0] < imageshape[0] / bin or currentxyshape[1] < imageshape[1] / bin: currenttomopath = apImod.pad(currenttomopath, currentxyshape, imageshape, bin, "XZY") cleanlist.append(currenttomopath) else: ### subtomogram simple upload, just copy file to Tomo folder if self.params["order"] == "XYZ" and not voltransform: apDisplay.printMsg("Default sub tomogram orientation") else: if voltransform: apDisplay.printMsg("Transforming original tomogram....") currenttomopath = apImod.transformVolume(origtomopath, voltransform) cleanlist.append(currenttomopath) ### simple upload, just copy file to Tomo folder apDisplay.printMsg("Copying original tomogram to a new location: " + newtomopath) shutil.copyfile(currenttomopath, newtomopath) if origxfpath and os.path.isfile(origxfpath): apDisplay.printMsg("Copying original alignment to a new location: " + newxfpath) shutil.copyfile(origxfpath, newxfpath) if self.params["image"]: shutil.copyfile(self.params["image"], self.params["rundir"] + "/snapshot.png") ### inserting tomogram tomoheader = mrc.readHeaderFromFile(newtomopath) self.params["shape"] = tomoheader["shape"] if self.params["full"]: seriesname = "%s_%03d" % (self.params["sessionname"], self.params["tiltseriesnumber"]) self.params["zprojfile"] = apImod.projectFullZ( self.params["rundir"], self.params["runname"], seriesname, bin, True, False ) else: apTomo.makeMovie(newtomopath) apTomo.makeProjection(newtomopath) apTomo.uploadTomo(self.params) ### clean up for tmpfilepath in cleanlist: apFile.removeFile(tmpfilepath)
def start(self): cleanlist = [] # imod needs the recon files named as .rec It may need some fix later if self.params['name'] is None: self.setNewFileName() apDisplay.printColor("Naming tomogram as: " + self.params['name'], "cyan") newtomopath = os.path.join(self.params['rundir'], self.params['name'] + ".rec") origtomopath = self.params['file'] origxfpath = self.params['oldxffile'] apParam.createDirectory(self.params['aligndir']) newxfpath = os.path.join(self.params['aligndir'], self.params['newxffile']) order = self.params['order'] voltransform = self.params['transform'] bin = self.params['bin'] self.getImageShapeFromTiltSeries() self.getOriginalVolumeShape() if os.path.isfile(newtomopath): uploaded_before = self.checkExistingFile() if uploaded_before: return else: currenttomopath = origtomopath if self.params['full']: ### full tomogram upload, may need to pad to the image size if self.params['order'] == 'XZY' and not voltransform: apDisplay.printMsg( "Default full tomogram orientation with original handness" ) else: if voltransform: apDisplay.printMsg( "Transforming original tomogram....") currenttomopath = apImod.transformVolume( origtomopath, voltransform) cleanlist.append(currenttomopath) ### padding the XZY tomogram to the image size currentheader = mrc.readHeaderFromFile(currenttomopath) currentshape = currentheader['shape'] currentxyshape = currentshape[0], currentshape[2] imageshape = self.imageshape if currentxyshape[0] < imageshape[0] / bin or currentxyshape[ 1] < imageshape[1] / bin: currenttomopath = apImod.pad(currenttomopath, currentxyshape, imageshape, bin, 'XZY') cleanlist.append(currenttomopath) else: ### subtomogram simple upload, just copy file to Tomo folder if self.params['order'] == 'XYZ' and not voltransform: apDisplay.printMsg("Default sub tomogram orientation") else: if voltransform: apDisplay.printMsg( "Transforming original tomogram....") currenttomopath = apImod.transformVolume( origtomopath, voltransform) cleanlist.append(currenttomopath) ### simple upload, just copy file to Tomo folder apDisplay.printMsg( "Copying original tomogram to a new location: " + newtomopath) shutil.copyfile(currenttomopath, newtomopath) if origxfpath and os.path.isfile(origxfpath): apDisplay.printMsg( "Copying original alignment to a new location: " + newxfpath) shutil.copyfile(origxfpath, newxfpath) if self.params['image']: shutil.copyfile(self.params['image'], self.params['rundir'] + '/snapshot.png') ### inserting tomogram tomoheader = mrc.readHeaderFromFile(newtomopath) self.params['shape'] = tomoheader['shape'] if self.params['full']: seriesname = "%s_%03d" % (self.params['sessionname'], self.params['tiltseriesnumber']) self.params['zprojfile'] = apImod.projectFullZ( self.params['rundir'], self.params['runname'], seriesname, bin, True, False) else: apTomo.makeMovie(newtomopath) apTomo.makeProjection(newtomopath) apTomo.uploadTomo(self.params) ### clean up for tmpfilepath in cleanlist: apFile.removeFile(tmpfilepath)
def start(self): subtomorunq = appiondata.ApSubTomogramRunData() subtomorundata = subtomorunq.direct_query(self.params['subtomoId']) volshape, totalbin, pixelsize = apTomo.getSubvolumeInfo(subtomorundata) if volshape is None: apDisplay.printError('No subvolume exists for the subtomoId') sessionname = subtomorundata['session']['name'] stackq = appiondata.ApStackData() stackdata = stackq.direct_query(self.params['stackId']) diameter = apStack.getStackParticleDiameter(stackdata) diameterpixel = diameter * 1e-10 / pixelsize halfwidth = diameterpixel / 4 ztolerance = halfwidth zbackgroundrange = max(((volshape[0] - diameterpixel * 3) / 2, 10)) if self.params['commit']: avgrundata = apTomo.insertTomoAverageRun( self.params['runname'], self.params['rundir'], subtomorundata, stackdata, halfwidth, self.params['description'], ) profiles = {} sumvol = numpy.zeros(volshape) substacktype, conditionstackdata = apStack.findSubStackConditionData( stackdata) if substacktype in ['clustersub', 'alignsub']: alignstack = apStack.getAlignStack(substacktype, conditionstackdata) alignpackage = apAlignment.getAlignPackage(alignstack['alignrun']) stackprtls = apStack.getStackParticlesFromId(stackdata.dbid) i = 0 for stackp in stackprtls: alignp = apAlignment.getAlignParticle(stackp, alignstack) shift = apAlignment.getAlignShift(alignp, alignpackage) subtomodata = apTomo.getSubTomogramData(subtomorundata, stackp) subtomofile = os.path.join(subtomodata['path']['path'], subtomodata['name'] + '.rec') subvolume = apTomo.getTomoVolume(subtomodata) if subvolume is not None: zcenter = volshape[0] / 2 profile = apTomo.getParticleCenterZProfile( subvolume, shift, halfwidth, zbackgroundrange) subtomoid = subtomodata.dbid profiles[subtomoid] = profile center = apTomo.gaussianCenter(profile) if center > zcenter - ztolerance and center < zcenter + ztolerance: i += 1 shiftz = zcenter - center transformedvolume = apTomo.transformTomo( subvolume, subtomofile, alignpackage, alignp, shiftz, totalbin) ## write transformed mrc file to check the result filename = os.path.join( self.params['rundir'], './transformed%05d.mrc' % subtomoid) mrc.write(transformedvolume, filename) sumvol += transformedvolume t = numpy.sum(transformedvolume, axis=0) filename = os.path.join(self.params['rundir'], './p%05d.mrc' % subtomoid) mrc.write(transformedvolume, filename) if self.params['commit']: apTomo.insertTomoAvgParticle( avgrundata, subtomodata, alignp, shiftz) if i < 1: apDisplay.printError('no subtomogram qualifies for averaging') else: avgvol = sumvol / i avgvolfilename = sessionname + "_" + self.params['runname'] + ".mrc" avgvolpath = os.path.join(self.params['rundir'], avgvolfilename) mrc.write(avgvol, avgvolpath) if not os.path.isfile(avgvolpath): apDisplay.printError("tomogram not exist") apTomo.makeMovie(avgvolpath, self.params['maxsize']) apTomo.makeProjection(avgvolpath, self.params['maxsize']) proshape = profile.shape for id in profiles.keys(): out = open('profile_%05d.txt' % id, 'w') for z in range(0, proshape[0]): str = "%5d\t" % z str += "%6.3f\t" % profiles[id][z] str += "\n" out.write(str) out.close()
def start(self): subtomorunq = appiondata.ApSubTomogramRunData() subtomorundata = subtomorunq.direct_query(self.params['subtomoId']) volshape,totalbin,pixelsize = apTomo.getSubvolumeInfo(subtomorundata) if volshape is None: apDisplay.printError('No subvolume exists for the subtomoId') sessionname = subtomorundata['session']['name'] stackq = appiondata.ApStackData() stackdata = stackq.direct_query(self.params['stackId']) diameter = apStack.getStackParticleDiameter(stackdata) diameterpixel = diameter * 1e-10 / pixelsize halfwidth = diameterpixel / 4 ztolerance = halfwidth zbackgroundrange = max(((volshape[0] - diameterpixel*3)/2,10)) if self.params['commit']: avgrundata = apTomo.insertTomoAverageRun(self.params['runname'], self.params['rundir'], subtomorundata, stackdata, halfwidth, self.params['description'], ) profiles = {} sumvol = numpy.zeros(volshape) substacktype,conditionstackdata = apStack.findSubStackConditionData(stackdata) if substacktype in ['clustersub','alignsub']: alignstack = apStack.getAlignStack(substacktype,conditionstackdata) alignpackage = apAlignment.getAlignPackage(alignstack['alignrun']) stackprtls = apStack.getStackParticlesFromId(stackdata.dbid) i = 0 for stackp in stackprtls: alignp = apAlignment.getAlignParticle(stackp,alignstack) shift = apAlignment.getAlignShift(alignp,alignpackage) subtomodata = apTomo.getSubTomogramData(subtomorundata,stackp) subtomofile = os.path.join(subtomodata['path']['path'],subtomodata['name']+'.rec') subvolume = apTomo.getTomoVolume(subtomodata) if subvolume is not None: zcenter = volshape[0] / 2 profile = apTomo.getParticleCenterZProfile(subvolume,shift,halfwidth,zbackgroundrange) subtomoid = subtomodata.dbid profiles[subtomoid] = profile center = apTomo.gaussianCenter(profile) if center > zcenter - ztolerance and center < zcenter + ztolerance: i += 1 shiftz = zcenter - center transformedvolume = apTomo.transformTomo(subvolume,subtomofile,alignpackage,alignp,shiftz,totalbin) ## write transformed mrc file to check the result filename = os.path.join(self.params['rundir'],'./transformed%05d.mrc' %subtomoid) mrc.write(transformedvolume,filename) sumvol += transformedvolume t = numpy.sum(transformedvolume,axis=0) filename = os.path.join(self.params['rundir'],'./p%05d.mrc' %subtomoid) mrc.write(transformedvolume,filename) if self.params['commit']: apTomo.insertTomoAvgParticle(avgrundata,subtomodata,alignp,shiftz) if i < 1: apDisplay.printError('no subtomogram qualifies for averaging') else: avgvol = sumvol / i avgvolfilename = sessionname+"_"+self.params['runname']+".mrc" avgvolpath = os.path.join(self.params['rundir'],avgvolfilename) mrc.write(avgvol,avgvolpath) if not os.path.isfile(avgvolpath): apDisplay.printError("tomogram not exist") apTomo.makeMovie(avgvolpath,self.params['maxsize']) apTomo.makeProjection(avgvolpath,self.params['maxsize']) proshape = profile.shape for id in profiles.keys(): out = open('profile_%05d.txt'%id,'w') for z in range(0,proshape[0]): str = "%5d\t" % z str += "%6.3f\t" % profiles[id][z] str += "\n" out.write(str) out.close()