Esempio n. 1
0
def start(context, ccp, config, executable, gene_list, email, priority, dryrun,
          customer, family):
    """Start a new analysis."""
    ccp_abs = (Path(ccp).abspath() if ccp else
               Path(context.obj['analysis_root']).joinpath(customer))
    # parse pedigree yaml
    pedigree_path = ccp_abs.joinpath("{0}/{0}_pedigree.yaml".format(family))
    if not pedigree_path.exists():
        log.error("pedigree YAML doesn't exist")
        context.abort()

    # check if case is already running
    case_id = "{}-{}".format(customer, family)
    if api.is_running(case_id):
        log.error("case already running!")
        context.abort()

    global_config = config or context.obj['mip_config']
    executable = executable or context.obj['mip_exe']
    gene_list = gene_list or context.obj.get('mip_genelist')
    email = email or environ_email()

    process = start_mip(
        config=global_config,
        family_id=family,
        ccp=ccp_abs,
        executable=executable,
        gene_list=gene_list,
        dryrun=dryrun,
        email=email,
        priority=priority,
    )
    process.wait()
    if process.returncode != 0:
        log.error("error starting analysis, check the output")
        context.abort()

    # add pending entry to database
    new_entry = build_pending(case_id, ccp_abs)
    if email:
        user = api.user(email)
        new_entry.user = user
    commit_analysis(context.obj['manager'], new_entry)
    context.obj['manager'].commit()
Esempio n. 2
0
def commit_analysis(manager, new_entry, email=None):
    """Store new analysis in the database."""
    # look up previous runs for the same case
    old_runs = api.case(case_id=new_entry.case_id)
    latest_run = old_runs.first()
    if latest_run is None or not same_entry(latest_run, new_entry):
        if new_entry.status == 'completed':
            # set failed runs to not be visible in dashboard
            for old_run in old_runs:
                old_runs.is_visible = False
            manager.commit()

        # save the new entry to the database
        if latest_run and latest_run.status in ('running', 'pending'):
            # replace old temporary entries
            log.debug("deleting existing entry: %s", new_entry.case_id)
            latest_run.delete()
            manager.commit()

        if email:
            new_entry.user = api.user(email)
        manager.add_commit(new_entry)
        log.info("added new entry: {entry.case_id} - {entry.status}"
                 .format(entry=new_entry))