Пример #1
0
    def commitToDatabase(self):
        processdir = self.params['rundir']
        runname = self.params['runname']
        # insertTomoRun
        self.fullrundata = apTomo.insertFullTomoRun(self.sessiondata,
                                                    processdir, runname,
                                                    self.params['method'])
        reconname = self.seriesname + "_full"
        if os.path.exists(os.path.join(processdir, reconname + '.rec')):
            #insertTomograma and z projection
            if 'bin' not in self.params.keys():
                self.params['bin'] = 1
            bin = self.params['bin']
            zerotiltimage = self.orig_imagelist[0]

            zprojectfile = apImod.projectFullZ(processdir, runname,
                                               self.seriesname, bin, True,
                                               False)
            q = leginon.leginondata.AcquisitionImageData()
            zimagedata = apTomo.uploadZProjection(runname, zerotiltimage,
                                                  zprojectfile)
            excludeimages = apTomo.getExcludedImageIds(self.ordered_imagelist,
                                                       self.excludelist)
            reconparamdata = self.getReconParams()
            self.fulltomodata = apTomo.insertFullTomogram(
                self.sessiondata, self.tiltdatalist[0], self.alignerdata,
                self.fullrundata, reconname, self.params['description'],
                zimagedata, self.params['thickness'], reconparamdata, bin,
                excludeimages)
        def commitToDatabase(self):
                processdir = self.params['rundir']
                runname = self.params['runname']
                # insertTomoRun
                self.fullrundata = apTomo.insertFullTomoRun(self.sessiondata,processdir,runname,self.params['method'])
                reconname = self.seriesname+"_full"
                if os.path.exists(os.path.join(processdir,reconname+'.rec')):
                        #insertTomograma and z projection
                        if 'bin' not in self.params.keys():
                                self.params['bin']=1
                        bin = self.params['bin']
                        zerotiltimage = self.orig_imagelist[0]

                        zprojectfile = apImod.projectFullZ(processdir, runname, self.seriesname,bin,True,False)
                        q=leginon.leginondata.AcquisitionImageData()
                        zimagedata = apTomo.uploadZProjection(runname,zerotiltimage,zprojectfile)
                        excludeimages = apTomo.getExcludedImageIds(self.ordered_imagelist,self.excludelist)
                        reconparamdata = self.getReconParams()
                        self.fulltomodata = apTomo.insertFullTomogram(self.sessiondata,self.tiltdatalist[0],self.alignerdata,
                                        self.fullrundata,reconname,self.params['description'],zimagedata,self.params['thickness'],reconparamdata,bin,excludeimages)
 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)
Пример #4
0
    def start(self):
        # set local parameters
        commit = self.params['commit']
        tiltdatalist = apTomo.getTiltdataList(self.params['tiltseries'],
                                              self.params['othertiltseries'])
        sessiondata = tiltdatalist[0]['session']
        description = self.params['description']
        runname = self.params['runname']
        alignmethod = self.params['alignmethod']
        reconbin = int(self.params['reconbin'])
        thickness_pixel = int(self.params['reconthickness'])
        markersize_nm = int(self.params['markersize'])
        markernumber = int(self.params['markernumber'])

        apDisplay.printMsg("getting imagelist")
        imagelist = apTomo.getImageList(tiltdatalist)
        tilts, ordered_imagelist, ordered_mrc_files, refimg = apTomo.orderImageList(
            imagelist)
        apDisplay.printMsg("getting pixelsize")
        pixelsize = apTomo.getTomoPixelSize(ordered_imagelist[refimg])
        imgshape = apTomo.getTomoImageShape(ordered_imagelist[refimg])
        #thickness_binnedpixel = int(thickness_nm * 1e-9 / (pixelsize * reconbin))
        markersize_pixel = int(markersize_nm * 1e-9 / pixelsize)
        processdir = os.path.abspath(self.params['rundir'])
        imodseriesname = apTomo.getFilename(tiltdatalist)
        seriesname = imodseriesname
        # Write tilt series stack images and tilt angles
        stackdir = self.params['tiltseriesdir']
        stackname = imodseriesname + ".st"
        apTomo.writeTiltSeriesStack(stackdir, stackname, ordered_mrc_files,
                                    1e10 * pixelsize)
        apRaptor.linkStToMrcExtension(stackdir, imodseriesname)
        apImod.writeRawtltFile(stackdir, imodseriesname, tilts)
        # Get Leginon tomography settings
        leginontomosettingslist = []
        for tiltdata in tiltdatalist:
            settingsdata = apTomo.getTomographySettings(sessiondata, tiltdata)
            leginontomosettingslist.append(settingsdata)
        aligndir = processdir
        # run the script and get alignment results when raptor can output alignment results in the future. raptoraligndata is None for now.
        returncode, raptoraligndata, raptorfailed = apRaptor.alignAndRecon(
            stackdir, stackname, processdir, markersize_pixel, reconbin,
            thickness_pixel, markernumber, commit)
        # Create Aligned Stack for record, not done in apRaptor yet, currently raptoraligndata is None
        if not raptorfailed:
            alifilename = imodseriesname + '.ali'
            alifilepath = os.path.join(aligndir, 'align', alifilename)
            print alifilepath
        # commit to database
        if commit:
            # parameters
            raptorparamsdata = apRaptor.insertRaptorParams(
                markersize_nm, markernumber)
            alignrun = apTomo.insertTomoAlignmentRun(
                sessiondata, None, None, None, raptorparamsdata, 1,
                self.params['runname'], self.params['rundir'],
                self.params['description'], raptorfailed)
            # to accomodate iterative alignment, one alignmentrun may have
            # used the aligner several times, for this case a single
            # aligner params data is inserted as in the case of Imod xcorr
            alignerdata = apTomo.insertAlignerParams(alignrun, self.params)
            #results
            if raptoraligndata:
                # if raptor has alignment result, it is converted to protomo
                # format which is more parameterized and saved
                prexgfile = os.path.join(aligndir, imodseriesname + '.prexg')
                shifts = apImod.readShiftPrexgFile(aligndir, imodseriesname)
                resulttltparams = apProTomo.convertShiftsToParams(
                    tilts, shifts, center)
                if resulttltparams:
                    modeldata = apProTomo.insertModel(alignerdata,
                                                      resulttltparams)
                    for i, imagedata in enumerate(ordered_imagelist):
                        apProTomo.insertTiltAlignment(alignerdata, imagedata,
                                                      i, resulttltparams[0][i],
                                                      center)
            # multiple tilt series in one alignrun
            for i in range(0, len(tiltdatalist)):
                if i == 0:
                    primary = True
                else:
                    primary = False
                # Record tilts in align run allows more than one tilt series to be
                # used in one align run.
                apTomo.insertTiltsInAlignRun(alignrun, tiltdatalist[i],
                                             leginontomosettingslist[i],
                                             primary)
            if not raptorfailed:
                apTomo.makeAlignStackMovie(alifilepath)
            os.chdir(processdir)

            # Full tomogram created with raptor is ???? handness?????
            if not raptorfailed:
                '''
				voltransform = '????'
				origtomopath = os.path.join(processdir, seriesname+"_full.rec")
				currenttomopath = apImod.transformVolume(origtomopath,voltransform)
				shutil.move(currenttomopath, origtomopath)
				'''
                zprojectfile = apImod.projectFullZ(processdir, runname,
                                                   seriesname, reconbin, False,
                                                   False)
                try:
                    zimagedata = apTomo.uploadZProjection(
                        runname, imagelist[0], zprojectfile)
                except:
                    zimagedata = None
                fullrundata = apTomo.insertFullTomoRun(sessiondata, processdir,
                                                       runname, 'imod-wbp')
                fulltomodata = apTomo.insertFullTomogram(
                    sessiondata, tiltdatalist[0], alignerdata, fullrundata,
                    runname, description, zimagedata, thickness_pixel,
                    reconbin)

                # if raptor succeeded, upload data and parameters to database
                session_time = sessiondata.timestamp
                description = self.params['description']
                raptordatabase = apRaptor.commitToJensenDatabase(
                    session_time, fulltomodata, stackdir, processdir,
                    stackname, description)
                if raptordatabase == 0:
                    apDisplay.printMsg(
                        "RAPTOR and uploading to Jensen database done.")
                else:
                    apDisplay.printWarning(
                        "Uploading to Jensen database failed.")
        def start(self):
                # set local parameters
                commit = self.params['commit']
                tiltdatalist = apTomo.getTiltdataList(self.params['tiltseries'],self.params['othertiltseries'])
                sessiondata = tiltdatalist[0]['session']
                description = self.params['description']
                runname = self.params['runname']
                alignmethod = self.params['alignmethod']
                reconbin = int(self.params['reconbin'])
                thickness_pixel = int(self.params['reconthickness'])
                markersize_nm = int(self.params['markersize'])
                markernumber = int(self.params['markernumber'])

                apDisplay.printMsg("getting imagelist")
                imagelist = apTomo.getImageList(tiltdatalist)
                tilts,ordered_imagelist,ordered_mrc_files,refimg = apTomo.orderImageList(imagelist)
                apDisplay.printMsg("getting pixelsize")
                pixelsize = apTomo.getTomoPixelSize(ordered_imagelist[refimg])
                imgshape = apTomo.getTomoImageShape(ordered_imagelist[refimg])
                #thickness_binnedpixel = int(thickness_nm * 1e-9 / (pixelsize * reconbin))
                markersize_pixel = int(markersize_nm * 1e-9 / pixelsize)
                processdir = os.path.abspath(self.params['rundir'])
                imodseriesname = apTomo.getFilename(tiltdatalist)
                seriesname = imodseriesname
                # Write tilt series stack images and tilt angles
                stackdir = self.params['tiltseriesdir']
                stackname = imodseriesname+".st"
                apTomo.writeTiltSeriesStack(stackdir,stackname,ordered_mrc_files,1e10*pixelsize)
                apRaptor.linkStToMrcExtension(stackdir,imodseriesname)
                apImod.writeRawtltFile(stackdir,imodseriesname,tilts)
                # Get Leginon tomography settings
                leginontomosettingslist = []
                for tiltdata in tiltdatalist:
                        settingsdata = apTomo.getTomographySettings(sessiondata,tiltdata)
                        leginontomosettingslist.append(settingsdata)
                aligndir = processdir
                # run the script and get alignment results when raptor can output alignment results in the future. raptoraligndata is None for now.
                returncode, raptoraligndata, raptorfailed = apRaptor.alignAndRecon(stackdir, stackname, processdir, markersize_pixel, reconbin, thickness_pixel, markernumber, commit)
                # Create Aligned Stack for record, not done in apRaptor yet, currently raptoraligndata is None
                if not raptorfailed:
                        alifilename = imodseriesname+'.ali'
                        alifilepath = os.path.join(aligndir,'align',alifilename)
                        print alifilepath
                # commit to database
                if commit:
                        # parameters
                        raptorparamsdata = apRaptor.insertRaptorParams(markersize_nm,markernumber)
                        alignrun = apTomo.insertTomoAlignmentRun(sessiondata,None,None,None,raptorparamsdata,1,self.params['runname'],self.params['rundir'],self.params['description'],raptorfailed)
                        # to accomodate iterative alignment, one alignmentrun may have 
                        # used the aligner several times, for this case a single 
                        # aligner params data is inserted as in the case of Imod xcorr
                        alignerdata = apTomo.insertAlignerParams(alignrun,self.params)
                        #results
                        if raptoraligndata:
                                # if raptor has alignment result, it is converted to protomo
                                # format which is more parameterized and saved
                                prexgfile = os.path.join(aligndir,imodseriesname+'.prexg')
                                shifts = apImod.readShiftPrexgFile(aligndir, imodseriesname)
                                resulttltparams = apProTomo.convertShiftsToParams(tilts,shifts,center)
                                if resulttltparams:
                                        modeldata = apProTomo.insertModel(alignerdata, resulttltparams)
                                        for i,imagedata in enumerate(ordered_imagelist):
                                                apProTomo.insertTiltAlignment(alignerdata,imagedata,i,resulttltparams[0][i],center)
                        # multiple tilt series in one alignrun
                        for i in range(0,len(tiltdatalist)):
                                if i == 0:
                                        primary = True
                                else:
                                        primary = False
                                # Record tilts in align run allows more than one tilt series to be
                                # used in one align run.
                                apTomo.insertTiltsInAlignRun(alignrun, tiltdatalist[i],leginontomosettingslist[i],primary)
                        if not raptorfailed:
                                apTomo.makeAlignStackMovie(alifilepath)
                        os.chdir(processdir)

                        # Full tomogram created with raptor is ???? handness?????
                        if not raptorfailed:
                                '''
                                voltransform = '????'
                                origtomopath = os.path.join(processdir, seriesname+"_full.rec")
                                currenttomopath = apImod.transformVolume(origtomopath,voltransform)
                                shutil.move(currenttomopath, origtomopath)
                                '''
                                zprojectfile = apImod.projectFullZ(processdir, runname, seriesname,reconbin,False,False)
                                try:
                                        zimagedata = apTomo.uploadZProjection(runname,imagelist[0],zprojectfile)
                                except:
                                        zimagedata = None
                                fullrundata = apTomo.insertFullTomoRun(sessiondata,processdir,runname,'imod-wbp')
                                fulltomodata = apTomo.insertFullTomogram(sessiondata,tiltdatalist[0],alignerdata,
                                                fullrundata,runname,description,zimagedata,thickness_pixel,reconbin)


                                # if raptor succeeded, upload data and parameters to database
                                session_time = sessiondata.timestamp
                                description = self.params['description']
                                raptordatabase = apRaptor.commitToJensenDatabase(session_time, fulltomodata, stackdir, processdir, stackname, description)
                                if raptordatabase == 0:
                                        apDisplay.printMsg("RAPTOR and uploading to Jensen database done.")
                                else:
                                        apDisplay.printWarning("Uploading to Jensen database failed.")
Пример #6
0
 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)