def causatives(institute_id): institute_obj = institute_and_case(store, institute_id) query = request.args.get('query', '') hgnc_id = None if '|' in query: # filter accepts an array of IDs. Provide an array with one ID element try: hgnc_id = [int(query.split(' | ', 1)[0])] except ValueError: flash('Provided gene info could not be parsed!', 'warning') variants = store.check_causatives(institute_obj=institute_obj, limit_genes=hgnc_id) if variants: variants.sort("hgnc_symbols", pymongo.ASCENDING) all_variants = {} all_cases = {} for variant_obj in variants: if variant_obj['case_id'] not in all_cases: case_obj = store.case(variant_obj['case_id']) all_cases[variant_obj['case_id']] = case_obj else: case_obj = all_cases[variant_obj['case_id']] if variant_obj['variant_id'] not in all_variants: # capture ACMG classification for this variant if isinstance(variant_obj.get('acmg_classification'), int): acmg_code = ACMG_MAP[variant_obj['acmg_classification']] variant_obj['acmg_classification'] = ACMG_COMPLETE_MAP[ acmg_code] all_variants[variant_obj['variant_id']] = [] all_variants[variant_obj['variant_id']].append((case_obj, variant_obj)) return dict(institute=institute_obj, variant_groups=all_variants)
def causatives(institute_obj, request): """Create content to be displayed on institute causatives page Args: institute_obj(dict) An institute object request(flask.request) request sent by user's browser Returns: data(dict) """ # Retrieve variants grouped by case query = request.args.get("query", "") hgnc_id = None if "|" in query: # filter accepts an array of IDs. Provide an array with one ID element try: hgnc_id = [int(query.split(" | ", 1)[0])] except ValueError: flash("Provided gene info could not be parsed!", "warning") variants = list( store.check_causatives(institute_obj=institute_obj, limit_genes=hgnc_id)) if variants: variants = sorted( variants, key=lambda k: k.get("hgnc_symbols", [None])[0] or k.get("str_repid" ) or "", ) all_variants = {} all_cases = {} for variant_obj in variants: if variant_obj["category"] in ["snv", "cancer"]: update_representative_gene(variant_obj, variant_obj.get( "genes", [])) # required to display cDNA and protein change if variant_obj["case_id"] not in all_cases: case_obj = store.case(variant_obj["case_id"]) all_cases[variant_obj["case_id"]] = case_obj else: case_obj = all_cases[variant_obj["case_id"]] if variant_obj["variant_id"] not in all_variants: all_variants[variant_obj["variant_id"]] = [] all_variants[variant_obj["variant_id"]].append((case_obj, variant_obj)) data = dict( institute=institute_obj, variant_groups=all_variants, acmg_map={ key: ACMG_COMPLETE_MAP[value] for key, value in ACMG_MAP.items() }, ) return data
def causatives(institute_id): institute_obj = institute_and_case(store, institute_id) variants = store.check_causatives(institute_obj=institute_obj) all_variants = {} all_cases = {} for variant_obj in variants: if variant_obj['case_id'] not in all_cases: case_obj = store.case(variant_obj['case_id']) all_cases[variant_obj['case_id']] = case_obj else: case_obj = all_cases[variant_obj['case_id']] if variant_obj['variant_id'] not in all_variants: all_variants[variant_obj['variant_id']] = [] all_variants[variant_obj['variant_id']].append((case_obj, variant_obj)) return dict(institute=institute_obj, variant_groups=all_variants)
def causatives(institute_id): institute_obj = institute_and_case(store, institute_id) query = request.args.get("query", "") hgnc_id = None if "|" in query: # filter accepts an array of IDs. Provide an array with one ID element try: hgnc_id = [int(query.split(" | ", 1)[0])] except ValueError: flash("Provided gene info could not be parsed!", "warning") variants = store.check_causatives(institute_obj=institute_obj, limit_genes=hgnc_id) if variants: variants.sort("hgnc_symbols", pymongo.ASCENDING) all_variants = {} all_cases = {} for variant_obj in variants: if variant_obj["case_id"] not in all_cases: case_obj = store.case(variant_obj["case_id"]) all_cases[variant_obj["case_id"]] = case_obj else: case_obj = all_cases[variant_obj["case_id"]] if variant_obj["variant_id"] not in all_variants: all_variants[variant_obj["variant_id"]] = [] all_variants[variant_obj["variant_id"]].append((case_obj, variant_obj)) acmg_map = { key: ACMG_COMPLETE_MAP[value] for key, value in ACMG_MAP.items() } return dict(institute=institute_obj, variant_groups=all_variants, acmg_map=acmg_map)
for term in store.case_omim_diagnoses(case_obj.get("diagnosis_phenotypes")) } if case_obj.get("custom_images"): # re-encode images as base64 if "case" in case_obj.get("custom_images"): case_obj["custom_images"] = case_obj["custom_images"]["case"] for img_section in case_obj["custom_images"].keys(): for img in case_obj["custom_images"][img_section]: img["data"] = b64encode(img["data"]).decode("utf-8") data = { "institute": institute_obj, "case": case_obj, "status_class": STATUS_MAP.get(case_obj["status"]), "other_causatives": [var for var in store.check_causatives(case_obj=case_obj)], "managed_variants": [var for var in store.check_managed(case_obj=case_obj)], "comments": store.events(institute_obj, case=case_obj, comments=True), "hpo_groups": pheno_groups, "case_groups": case_groups, "case_group_label": case_group_label, "events": events, "suspects": suspects, "causatives": causatives, "evaluated_variants": evaluated_variants, "partial_causatives": partial_causatives, "collaborators": collab_ids, "cohort_tags": institute_obj.get("cohorts", []), "omim_terms": omim_terms, "manual_rank_options": MANUAL_RANK_OPTIONS, "cancer_tier_options": CANCER_TIER_OPTIONS,