Example #1
0
def balsamic(context, case_id, priority, email, target_bed):
    """Cancer workflow """
    context.obj["store_api"] = Store(context.obj["database"])
    context.obj["hk_api"] = hk.HousekeeperAPI(context.obj)
    context.obj["fastq_handler"] = FastqHandler
    context.obj["gzipper"] = gzip
    context.obj["lims_api"] = lims.LimsAPI(context.obj)
    context.obj["fastq_api"] = FastqAPI

    context.obj["analysis_api"] = AnalysisAPI(
        hk_api=context.obj["hk_api"], fastq_api=context.obj["fastq_api"])

    if context.invoked_subcommand is None:
        if case_id is None:
            LOG.error("provide a case")
            context.abort()

        # execute the analysis!
        context.invoke(link, case_id=case_id)
        context.invoke(config_case, case_id=case_id, target_bed=target_bed)
        context.invoke(run,
                       run_analysis=True,
                       case_id=case_id,
                       priority=priority,
                       email=email)
Example #2
0
def microsalt(context: click.Context, order_id):
    """Microbial workflow"""
    context.obj["db"] = Store(context.obj["database"])
    hk_api = hk.HousekeeperAPI(context.obj)
    lims_api = lims.LimsAPI(context.obj)
    deliver = DeliverAPI(
        context.obj,
        hk_api=hk_api,
        lims_api=lims_api,
        case_tags=PROJECT_TAGS,
        sample_tags=SAMPLE_TAGS,
    )
    context.obj["api"] = AnalysisAPI(db=context.obj["db"],
                                     hk_api=hk_api,
                                     lims_api=lims_api)
    context.obj["lims_microsalt_api"] = LimsMicrosaltAPI(lims=lims_api)

    if context.invoked_subcommand is None:
        if order_id is None:
            LOG.error("Please provide an order")
            context.abort()
        else:
            # execute the analysis!
            context.invoke(config_case, order_id=order_id)
            context.invoke(link, order_id=order_id)
            context.invoke(run, order_id=order_id)
Example #3
0
def clean(context):
    """Clean up processes"""
    context.obj["db"] = Store(context.obj["database"])
    context.obj["tb"] = tb.TrailblazerAPI(context.obj)
    context.obj["hk"] = hk.HousekeeperAPI(context.obj)
    context.obj["scout"] = scoutapi.ScoutAPI(context.obj)
    context.obj["beacon"] = beacon_app.BeaconApi(context.obj)
    context.obj["crunchy"] = crunchy.CrunchyAPI(context.obj)
Example #4
0
def flowcell(context, flowcell_name):
    """Populate results from a flowcell."""
    stats_api = stats.StatsAPI(context.obj)
    hk_api = hk.HousekeeperAPI(context.obj)
    transfer_api = transfer_app.TransferFlowcell(context.obj['db'], stats_api,
                                                 hk_api)
    new_record = transfer_api.transfer(flowcell_name)
    context.obj['db'].add_commit(new_record)
    click.echo(click.style(f"flowcell added: {new_record}", fg='green'))
Example #5
0
def deliver(context):
    """Deliver stuff."""
    context.obj["db"] = Store(context.obj["database"])
    context.obj["deliver_api"] = DeliverAPI(
        db=context.obj["db"],
        hk_api=hk.HousekeeperAPI(context.obj),
        lims_api=lims.LimsAPI(context.obj),
        case_tags=CASE_TAGS,
        sample_tags=SAMPLE_TAGS,
    )
Example #6
0
def store(context):
    """Store results from Balsamic in housekeeper."""
    context.obj["store_api"] = context.obj.get("store_api") or Store(
        context.obj["database"])
    context.obj["hk_api"] = context.obj.get("hk_api") or hk.HousekeeperAPI(
        context.obj)
    context.obj["analysis_api"] = context.obj.get(
        "analysis_api") or AnalysisAPI(
            hk_api=context.obj["hk_api"],
            fastq_api=fastq.FastqAPI,
        )
Example #7
0
def mip_dna(context: click.Context, case_id: str, email: str, priority: str, start_with: str):
    """Rare disease DNA workflow"""
    context.obj["db"] = Store(context.obj["database"])
    hk_api = hk.HousekeeperAPI(context.obj)
    scout_api = scoutapi.ScoutAPI(context.obj)
    lims_api = lims.LimsAPI(context.obj)
    context.obj["tb"] = tb.TrailblazerAPI(context.obj)
    deliver = DeliverAPI(
        context.obj, hk_api=hk_api, lims_api=lims_api, case_tags=CASE_TAGS, sample_tags=SAMPLE_TAGS,
    )
    context.obj["api"] = AnalysisAPI(
        db=context.obj["db"],
        hk_api=hk_api,
        tb_api=context.obj["tb"],
        scout_api=scout_api,
        lims_api=lims_api,
        deliver_api=deliver,
    )

    if context.invoked_subcommand is None:
        if case_id is None:
            _suggest_cases_to_analyze(context, show_as_error=True)
            context.abort()

        # check everything is ok
        case_obj = context.obj["db"].family(case_id)
        if case_obj is None:
            LOG.error("%s: not found", case_id)
            context.abort()
        is_ok = context.obj["api"].check(case_obj)
        if not is_ok:
            LOG.warning("%s: not ready to run", case_obj.internal_id)
            # commit the updates to request flowcells
            context.obj["db"].commit()
        else:
            # execute the analysis!
            context.invoke(config_case, case_id=case_id)
            context.invoke(link, case_id=case_id)
            context.invoke(panel, case_id=case_id)
            context.invoke(
                run, case_id=case_id, priority=priority, email=email, start_with=start_with,
            )
Example #8
0
def upload(context, family_id):
    """Upload results from analyses."""
    context.obj['status'] = Store(context.obj['database'])
    context.obj['housekeeper_api'] = hk.HousekeeperAPI(context.obj)
    if family_id:
        family_obj = context.obj['status'].family(family_id)
        analysis_obj = family_obj.analyses[0]
        if analysis_obj.uploaded_at is not None:
            message = f"analysis already uploaded: {analysis_obj.uploaded_at.date()}"
            click.echo(click.style(message, fg='yellow'))
            context.abort()

        context.invoke(coverage, family_id=family_id)
        context.invoke(validate, family_id=family_id)
        context.invoke(genotypes, family_id=family_id)
        context.invoke(observations, family_id=family_id)
        context.invoke(scout, family_id=family_id)

        analysis_obj.uploaded_at = dt.datetime.now()
        context.obj['status'].commit()
        click.echo(click.style(f"{family_id}: analysis uploaded!", fg='green'))
Example #9
0
def analysis(context, priority, email, family_id):
    """Prepare and start a MIP analysis for a FAMILY_ID."""
    context.obj['db'] = Store(context.obj['database'])
    hk_api = hk.HousekeeperAPI(context.obj)
    scout_api = scoutapi.ScoutAPI(context.obj)
    lims_api = lims.LimsAPI(context.obj)
    context.obj['tb'] = tb.TrailblazerAPI(context.obj)
    context.obj['api'] = AnalysisAPI(
        db=context.obj['db'],
        hk_api=hk_api,
        tb_api=context.obj['tb'],
        scout_api=scout_api,
        lims_api=lims_api,
    )

    if context.invoked_subcommand is None:
        if family_id is None:
            LOG.error('provide a family')
            context.abort()

        # check everything is okey
        family_obj = context.obj['db'].family(family_id)
        if family_obj is None:
            LOG.error(f"{family_id} not found")
            context.abort()
        is_ok = context.obj['api'].check(family_obj)
        if not is_ok:
            LOG.warning(f"{family_obj.internal_id}: not ready to start")
            # commit the updates to request flowcells
            context.obj['db'].commit()
        else:
            # execute the analysis!
            context.invoke(config, family_id=family_id)
            context.invoke(link, family_id=family_id)
            context.invoke(panel, family_id=family_id)
            context.invoke(start,
                           family_id=family_id,
                           priority=priority,
                           email=email)
Example #10
0
def mip_rna(context: click.Context):
    """Rare disease RNA workflow"""
    context.obj["db"] = Store(context.obj["database"])
    hk_api = hk.HousekeeperAPI(context.obj)
    lims_api = lims.LimsAPI(context.obj)
    context.obj["tb"] = tb.TrailblazerAPI(context.obj)
    deliver = DeliverAPI(
        context.obj,
        hk_api=hk_api,
        lims_api=lims_api,
        case_tags=CASE_TAGS,
        sample_tags=SAMPLE_TAGS,
    )
    context.obj["api"] = AnalysisAPI(
        db=context.obj["db"],
        hk_api=hk_api,
        tb_api=context.obj["tb"],
        lims_api=lims_api,
        deliver_api=deliver,
    )
    context.obj["rna_api"] = MipAPI(context.obj["mip-rd-rna"]["script"],
                                    context.obj["mip-rd-rna"]["pipeline"])
Example #11
0
def store(context):
    """Store results from MIP in housekeeper."""
    context.obj["db"] = Store(context.obj["database"])
    context.obj["tb_api"] = tb.TrailblazerAPI(context.obj)
    context.obj["hk_api"] = hk.HousekeeperAPI(context.obj)
Example #12
0
def store(context):
    """Store results from MIP in housekeeper."""
    context.obj['db'] = Store(context.obj['database'])
    context.obj['tb_api'] = tb.TrailblazerAPI(context.obj)
    context.obj['hk_api'] = hk.HousekeeperAPI(context.obj)
Example #13
0
def inbox(context, dry, family, version, tag, inbox):
    """Link files from HK to cust inbox."""

    db = Store(context.obj['database'])
    deliver_api = DeliverAPI(db=db,
                             hk_api=hk.HousekeeperAPI(context.obj),
                             lims_api=lims.LimsAPI(context.obj))

    family_obj = db.family(family)
    if family_obj is None:
        LOG.error(f"Family '{family}' not found.")
        context.abort()

    family_files = deliver_api.get_post_analysis_family_files(family=family,
                                                              version=version,
                                                              tag=tag)
    if not family_files:
        LOG.warning(f"No family files found.")

    for file_obj in family_files:
        out_dir = Path(
            inbox.format(family=family_obj.name,
                         customer=family_obj.customer.internal_id))
        out_dir.mkdir(parents=True, exist_ok=True)

        # might be fun to name exit files according to tags instead of MIP's long name
        #file_name = Path('_'.join([ tag.name for tag in file_obj.tags ]))
        #file_ext = ''.join(Path(file_obj.path).suffixes)
        out_file_name = Path(file_obj.path).name.replace(
            family, family_obj.name)
        out_path = Path(f"{out_dir/ out_file_name}")
        in_path = Path(file_obj.full_path)

        if not out_path.exists():
            os.link(in_path, out_path)
            LOG.info(f"linked file: {in_path} -> {out_path}")
        else:
            LOG.info(f"Target file exists: {out_path}")

    link_obj = db.family_samples(family)
    if not link_obj:
        LOG.warning(f"No sample files found.")

    for family_sample in link_obj:
        sample_obj = family_sample.sample
        sample_files = deliver_api.get_post_analysis_sample_files(
            family=family,
            sample=sample_obj.internal_id,
            version=version,
            tag=tag)

        if not sample_files:
            LOG.warning(
                f"No sample files found for '{sample_obj.internal_id}'.")

        for file_obj in sample_files:
            out_dir = Path(
                inbox.format(family=family_obj.name,
                             customer=family_obj.customer.internal_id))
            out_dir = out_dir.joinpath(sample_obj.name)
            out_dir.mkdir(parents=True, exist_ok=True)

            out_file_name = Path(file_obj.path).name.replace(
                sample_obj.internal_id, sample_obj.name)
            out_path = Path(f"{out_dir / out_file_name}")
            in_path = Path(file_obj.full_path)

            if not out_path.exists():
                os.link(in_path, out_path)
                LOG.info(f"linked file: {in_path} -> {out_path}")
            else:
                LOG.info(f"Target file exists: {out_path}")
Example #14
0
def compress(context):
    """Compress files"""
    context.obj["db"] = Store(context.obj["database"])
    context.obj["hk"] = hk.HousekeeperAPI(context.obj)
    context.obj["scout"] = scoutapi.ScoutAPI(context.obj)
    context.obj["crunchy"] = crunchy.CrunchyAPI(context.obj)
Example #15
0
def upload(context, family_id, force_restart):
    """Upload results from analyses."""

    click.echo(click.style("----------------- UPLOAD ----------------------"))

    context.obj["status"] = Store(context.obj["database"])

    if family_id:
        family_obj = context.obj["status"].family(family_id)
        if not family_obj:
            message = f"family not found: {family_id}"
            click.echo(click.style(message, fg="red"))
            context.abort()

        if not family_obj.analyses:
            message = f"no analysis exists for family: {family_id}"
            click.echo(click.style(message, fg="red"))
            context.abort()

        analysis_obj = family_obj.analyses[0]

        if analysis_obj.uploaded_at is not None:
            message = f"analysis already uploaded: {analysis_obj.uploaded_at.date()}"
            click.echo(click.style(message, fg="red"))
            context.abort()

        if not force_restart and analysis_obj.upload_started_at is not None:
            if dt.datetime.now(
            ) - analysis_obj.upload_started_at > dt.timedelta(hours=24):
                raise AnalysisUploadError(
                    f"The upload started at {analysis_obj.upload_started_at} "
                    f"something went wrong, restart it with the --restart flag"
                )

            message = f"analysis upload already started: {analysis_obj.upload_started_at.date()}"
            click.echo(click.style(message, fg="yellow"))
            return

    context.obj["housekeeper_api"] = hk.HousekeeperAPI(context.obj)

    context.obj["madeline_api"] = madeline.api.MadelineAPI(context.obj)
    context.obj["genotype_api"] = gt.GenotypeAPI(context.obj)
    context.obj["lims_api"] = lims.LimsAPI(context.obj)
    context.obj["tb_api"] = tb.TrailblazerAPI(context.obj)
    context.obj["chanjo_api"] = coverage_app.ChanjoAPI(context.obj)
    context.obj["deliver_api"] = DeliverAPI(
        context.obj,
        hk_api=context.obj["housekeeper_api"],
        lims_api=context.obj["lims_api"],
        case_tags=CASE_TAGS,
        sample_tags=SAMPLE_TAGS,
    )
    context.obj["scout_api"] = scoutapi.ScoutAPI(context.obj)
    context.obj["analysis_api"] = AnalysisAPI(
        context.obj,
        hk_api=context.obj["housekeeper_api"],
        scout_api=context.obj["scout_api"],
        tb_api=context.obj["tb_api"],
        lims_api=context.obj["lims_api"],
        deliver_api=context.obj["deliver_api"],
    )
    context.obj["report_api"] = ReportAPI(
        store=context.obj["status"],
        lims_api=context.obj["lims_api"],
        chanjo_api=context.obj["chanjo_api"],
        analysis_api=context.obj["analysis_api"],
        scout_api=context.obj["scout_api"],
    )

    context.obj["scout_upload_api"] = UploadScoutAPI(
        hk_api=context.obj["housekeeper_api"],
        scout_api=context.obj["scout_api"],
        madeline_api=context.obj["madeline_api"],
        analysis_api=context.obj["analysis_api"],
        lims_api=context.obj["lims_api"],
    )

    if context.invoked_subcommand is not None:
        return

    if not family_id:
        _suggest_cases_to_upload(context)
        context.abort()

    family_obj = context.obj["status"].family(family_id)
    analysis_obj = family_obj.analyses[0]
    if analysis_obj.uploaded_at is not None:
        message = f"analysis already uploaded: {analysis_obj.uploaded_at.date()}"
        click.echo(click.style(message, fg="yellow"))
    else:
        analysis_obj.upload_started_at = dt.datetime.now()
        context.obj["status"].commit()
        context.invoke(coverage, re_upload=True, family_id=family_id)
        context.invoke(validate, family_id=family_id)
        context.invoke(genotypes, re_upload=False, family_id=family_id)
        context.invoke(observations, case_id=family_id)
        context.invoke(scout, case_id=family_id)
        analysis_obj.uploaded_at = dt.datetime.now()
        context.obj["status"].commit()
        click.echo(click.style(f"{family_id}: analysis uploaded!", fg="green"))