示例#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)
示例#3
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.")