def get_variantid(variant_obj, family_id): """Create a new variant id.""" new_id = parse_document_id( chrom=variant_obj['chromosome'], pos=str(variant_obj['position']), ref=variant_obj['reference'], alt=variant_obj['alternative'], variant_type=variant_obj['variant_type'], case_id=family_id, ) return new_id
def test_parse_document_id(): # GIVEN some variant information chrom = '1' pos = '10' ref = 'A' alt = 'G' case_id = 'cust000_1' variant_type = 'clinical' # WHEN parsing the document id variant_id = parse_document_id(chrom, pos, ref, alt, variant_type, case_id) # THEN we should get a correct md5 string back assert variant_id == generate_md5_key([chrom, pos, ref, alt, variant_type, case_id])
def test_parse_document_id(): # GIVEN some variant information chrom = "1" pos = "10" ref = "A" alt = "G" case_id = "cust000_1" variant_type = "clinical" # WHEN parsing the document id variant_id = parse_document_id(chrom, pos, ref, alt, variant_type, case_id) # THEN we should get a correct md5 string back assert variant_id == generate_md5_key( [chrom, pos, ref, alt, variant_type, case_id])
def test_parse_document_id(): # GIVEN some variant information chrom = '1' pos = '10' ref = 'A' alt = 'G' case_id = 'cust000_1' variant_type = 'clinical' # WHEN parsing the document id variant_id = parse_document_id(chrom, pos, ref, alt, variant_type, case_id) # THEN we should get a correct md5 string back assert variant_id == generate_md5_key( [chrom, pos, ref, alt, variant_type] + case_id.split('_'))
def get_variantid(variant_obj, family_id): """Create a new variant id. Args: variant_obj(dict) family_id(str) Returns: new_id(str): The new variant id """ new_id = parse_document_id( chrom=variant_obj["chromosome"], pos=str(variant_obj["position"]), ref=variant_obj["reference"], alt=variant_obj["alternative"], variant_type=variant_obj["variant_type"], case_id=family_id, ) return new_id
def observations(store, loqusdb, case_obj, variant_obj): """Query observations for a variant. Check if variant_obj have been observed before ni the loqusdb instance. If not return empty dictionary. We need to add links to the variant in other cases where the variant has been observed. First we need to make sure that the user has access to these cases. The user_institute_ids holds information about what institutes the user has access to. Loop over the case ids from loqusdb and check if they exist in the scout instance. Also make sure that we do not link to the observation that is the current variant. Args: store (scout.adapter.MongoAdapter) loqusdb (scout.server.extensions.LoqusDB) case_obj (scout.models.Case) variant_obj (scout.models.Variant) Returns: obs_data(dict) """ chrom = variant_obj["chromosome"] pos = variant_obj["position"] ref = variant_obj["reference"] alt = variant_obj["alternative"] var_case_id = variant_obj["case_id"] var_type = variant_obj.get("variant_type", "clinical") composite_id = "{0}_{1}_{2}_{3}".format(chrom, pos, ref, alt) variant_query = { "_id": composite_id, "chrom": chrom, "end_chrom": variant_obj.get("end_chrom", chrom), "pos": pos, "end": variant_obj["end"], "length": variant_obj.get("length", 0), "variant_type": variant_obj.get("sub_category", "").upper(), "category": variant_obj["category"], } institute_id = variant_obj["institute"] institute_obj = store.institute(institute_id) obs_data = loqusdb.get_variant( variant_query, loqusdb_id=institute_obj.get("loqusdb_id")) or {} if not obs_data: LOG.debug("Could not find any observations for %s", composite_id) obs_data["total"] = loqusdb.case_count() return obs_data user_institutes_ids = set( [inst["_id"] for inst in user_institutes(store, current_user)]) obs_data["cases"] = [] for i, case_id in enumerate(obs_data.get("families", [])): if i > 10: break if case_id == var_case_id: continue # other case might belong to same institute, collaborators or other institutes other_case = store.case(case_id) if not other_case: # Case could have been removed LOG.debug("Case %s could not be found in database", case_id) continue other_institutes = set([other_case.get("owner")]) other_institutes.update(set(other_case.get("collaborators", []))) if user_institutes_ids.isdisjoint(other_institutes): # If the user does not have access to the information we skip it continue document_id = parse_document_id(chrom, str(pos), ref, alt, var_type, case_id) other_variant = store.variant(document_id=document_id) # If the other variant is not loaded we skip it if not other_variant: continue obs_data["cases"].append(dict(case=other_case, variant=other_variant)) return obs_data