def insertTomoAlignmentRun(sessiondata,
                           leginontomosettingsdata,
                           imodxcorrparamsdata,
                           protomorunparamsdata,
                           raptorparamsdata,
                           bin,
                           name,
                           path,
                           description=None,
                           bad_alignment=False):
    pathq = appiondata.ApPathData(path=os.path.abspath(path))
    qalign = appiondata.ApTomoAlignmentRunData(session=sessiondata,
                                               bin=bin,
                                               name=name,
                                               path=pathq)
    if leginontomosettingsdata:
        qalign['coarseLeginonParams'] = leginontomosettingsdata
    if imodxcorrparamsdata:
        qalign['coarseImodParams'] = imodxcorrparamsdata
    if protomorunparamsdata:
        qalign['fineProtomoParams'] = protomorunparamsdata
    if raptorparamsdata:
        qalign['raptorParams'] = raptorparamsdata
    results = qalign.query()
    if not results:
        qalign['badAlign'] = bad_alignment
        qalign['description'] = description
        qalign.insert()
        return qalign
    return results[0]
def getTomoAlignmentRuns():
    alignrunids = []
    alignrunq = appiondata.ApTomoAlignmentRunData()
    alignrundatas = alignrunq.query()

    if not alignrundatas:
        return []
    return alignrundatas
def getAlignersFromTiltSeries(tiltseriesdata, alignrunname=''):
    q = appiondata.ApTiltsInAlignRunData(tiltseries=tiltseriesdata)
    if alignrunname:
        runq = appiondata.ApTomoAlignmentRunData(name=alignrunname)
        q['alignrun'] = runq
    results = q.query()
    if results:
        allaligners = []
        allalignerids = []
        for tilt_in_run in results:
            alignerq = appiondata.ApTomoAlignerParamsData(
                alignrun=tilt_in_run['alignrun'])
            aligners = alignerq.query()
            for aligner in aligners:
                if aligner.dbid not in allalignerids:
                    allaligners.append(aligner)
                    allalignerids.append(aligner.dbid)
        return allaligners
    return []