def start(context: click.Context, dry_run: bool = False): """Start all cases that are ready for analysis""" exit_code = 0 cases = [case_obj.internal_id for case_obj in context.obj["db"].cases_to_mip_analyze()] for case_id in cases: case_obj = context.obj["db"].family(case_id) if AnalysisAPI.is_dna_only_case(case_obj): LOG.info("%s: start analysis", case_obj.internal_id) else: LOG.warning("%s: contains non-dna samples, skipping", case_obj.internal_id) continue priority = ( "high" if case_obj.high_priority else ("low" if case_obj.low_priority else "normal") ) if dry_run: continue try: context.invoke(mip_dna, priority=priority, case_id=case_obj.internal_id) except tb.MipStartError as error: LOG.error(error.message) exit_code = 1 except CgError as error: LOG.error(error.message) exit_code = 11 sys.exit(exit_code)
def test_get_latest_data_rank_model_version(analysis_api: AnalysisAPI): # GIVEN family_id = "dummy_family_id" # WHEN trending_data = analysis_api.get_latest_metadata("dummy_family_id") # THEN contains rankmodelversion assert trending_data["rank_model_version"]
def test_get_latest_data_genome_build(analysis_api: AnalysisAPI): # GIVEN family_id = "dummy_family_id" # WHEN trending_data = analysis_api.get_latest_metadata("dummy_family_id") # THEN contains genome_build assert trending_data["genome_build"]
def test_config(analysis_store: Store, analysis_api: AnalysisAPI): # GIVEN a status db with a family family_obj = analysis_store.families().first() assert family_obj is not None # WHEN generating the MIP config for the family mip_config = analysis_api.config(family_obj) # THEN it should fill in values accordingly assert len(mip_config["samples"]) == len(family_obj.links)
def test_get_latest_metadata_logging(analysis_api: AnalysisAPI): # GIVEN an initialised report_api and the deliver_api does not have what we want analysis_api.tb._get_trending_raises_keyerror = True # WHEN failing to get latest trending data for a family latest_data = analysis_api.get_latest_metadata(family_id="bluebull") # THEN there should be a log entry about this found = False for warn in analysis_api.log.get_warnings(): if "bluebull" in warn: found = True assert found assert not latest_data
def analysis_api(analysis_store, housekeeper_api, scout_store): """Setup an analysis API.""" Path_mock = MockPath("") tb_mock = MockTB() deliver_mock = MockDeliver() deliver_mock.housekeeper = housekeeper_api _analysis_api = AnalysisAPI( db=analysis_store, hk_api=housekeeper_api, scout_api=scout_store, tb_api=tb_mock, lims_api=None, deliver_api=deliver_mock, yaml_loader=safe_loader, path_api=Path_mock, logger=MockLogger(), ) yield _analysis_api
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, )
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"))