def test_variants_research_no_shadow_clinical_assessments( real_variant_database, institute_obj, case_obj ): # GIVEN a db with variants, adapter = real_variant_database case_id = case_obj["_id"] # GIVEN a clinical variant from one case variant_clinical = adapter.variant_collection.find_one( {"case_id": case_id, "variant_type": "clinical"} ) # GIVEN a copy of that variant marked research variant_research = copy.deepcopy(variant_clinical) variant_research["_id"] = "research_version" variant_research["variant_type"] = "research" adapter.variant_collection.insert_one(variant_research) # WHEN filtering for that variant in research variants_query = {"variant_type": "research"} variants_query_res = adapter.variants( case_obj["_id"], query=variants_query, category=variant_clinical["category"] ) res = variants(adapter, institute_obj, case_obj, variants_query_res) res_variants = res["variants"] LOG.debug("Variants: {}".format(res_variants)) # THEN it is returned assert any([variant["_id"] == variant_research["_id"] for variant in res_variants]) # THEN no previous annotations are reported back for the reseach case.. assert not any([variant.get("clinical_assessments") for variant in res_variants])
def test_variants_assessment_shared_with_group(mocker, real_variant_database, institute_obj, case_obj): mocker.patch( "scout.server.blueprints.variants.controllers.user_institutes", return_value=[{ "_id": "cust000" }], ) # GIVEN a db with variants, adapter = real_variant_database case_id = case_obj["_id"] other_case_id = "other_" + case_id other_case_obj = copy.deepcopy(case_obj) other_case_obj["_id"] = other_case_id ## WHEN inserting an object with a group id group_id = ObjectId("101010101010101010101010") other_case_obj["group"] = [group_id] adapter.case_collection.insert_one(other_case_obj) # WHEN setting the same group id for the original case adapter.case_collection.find_one_and_update( {"_id": case_id}, {"$set": { "group": [group_id] }}) # GIVEN a clinical variant from one case variant = adapter.variant_collection.find_one({ "case_id": case_id, "variant_type": "clinical" }) # GIVEN a copy of the variant for the other case other_variant_obj = copy.deepcopy(variant) other_variant_obj["case_id"] = other_case_id other_variant_obj["_id"] = "another_variant" adapter.variant_collection.insert_one(other_variant_obj) # WHEN updating an assessment on the same first case variant adapter.variant_collection.find_one_and_update( {"_id": variant["_id"]}, {"$set": { "acmg_classification": 4 }}) # WHEN retrieving assessments for the variant from the other case variants_query = {"variant_type": "clinical"} variants_query_res = adapter.variants(other_case_id, query=variants_query, category=variant["category"]) res = variants(adapter, institute_obj, other_case_obj, variants_query_res, 1000) res_variants = res["variants"] # THEN a group assessment is recalled on the other case, # since the variant in the first case had an annotation assert any(variant.get("group_assessments") for variant in res_variants)
def test_variants_research_shadow_clinical_assessments(real_variant_database, institute_obj, case_obj): # GIVEN a db with variants, adapter = real_variant_database case_id = case_obj["_id"] # GIVEN a clinical variant from one case variant_clinical = adapter.variant_collection.find_one({ "case_id": case_id, "variant_type": "clinical" }) # GIVEN a copy of that variant marked research variant_research = copy.deepcopy(variant_clinical) variant_research["_id"] = "research_version" variant_research["variant_type"] = "research" adapter.variant_collection.insert_one(variant_research) # WHEN updating the manual assessments of the clinical variant adapter.variant_collection.update_one( {"_id": variant_clinical["_id"]}, { "$set": { "manual_rank": 2, "mosaic_tags": ["1"], "dismiss_variant": ["2", "3"], "acmg_classification": 0, } }, ) # WHEN filtering for that variant in research variants_query = {"variant_type": "research"} variants_query_res = adapter.variants( case_obj["_id"], query=variants_query, category=variant_clinical["category"]) res = variants(adapter, institute_obj, case_obj, variants_query_res) res_variants = res["variants"] # THEN it is returned assert any([ variant["_id"] == variant_research["_id"] for variant in res_variants ]) # THEN previous annotations are reported back for the reseach case. assert any( [variant.get("clinical_assessments") for variant in res_variants])
def test_variants_research_no_shadow_clinical_assessments( mocker, real_variant_database, institute_obj, case_obj): mocker.patch( "scout.server.blueprints.variants.controllers.user_institutes", return_value=[{ "_id": "cust000" }], ) # GIVEN a db with variants, adapter = real_variant_database case_id = case_obj["_id"] # GIVEN a clinical variant from one case variant_clinical = adapter.variant_collection.find_one({ "case_id": case_id, "variant_type": "clinical" }) # GIVEN a copy of that variant marked research variant_research = copy.deepcopy(variant_clinical) variant_research["_id"] = "research_version" variant_research["variant_type"] = "research" adapter.variant_collection.insert_one(variant_research) # WHEN filtering for that variant in research variants_query = {"variant_type": "research"} variants_query_res = adapter.variants( case_obj["_id"], query=variants_query, category=variant_clinical["category"]) # NOTE in tests list length will be used, in live code count_documents{query} is # called. number_variants = len(list(variants_query_res.clone())) res = variants(adapter, institute_obj, case_obj, variants_query_res, number_variants) res_variants = res["variants"] LOG.debug("Variants: {}".format(res_variants)) # THEN it is returned assert any([ variant["_id"] == variant_research["_id"] for variant in res_variants ]) # THEN no previous annotations are reported back for the reseach case.. assert not any( [variant.get("clinical_assessments") for variant in res_variants])
def test_variants_research_shadow_clinical_assessments(mocker, real_variant_database, institute_obj, case_obj): mocker.patch( "scout.server.blueprints.variants.controllers.user_institutes", return_value=[{ "_id": "cust000" }], ) # GIVEN a db with variants, adapter = real_variant_database case_id = case_obj["_id"] # GIVEN a clinical variant from one case variant_clinical = adapter.variant_collection.find_one({ "case_id": case_id, "variant_type": "clinical" }) # GIVEN a copy of that variant marked research variant_research = copy.deepcopy(variant_clinical) variant_research["_id"] = "research_version" variant_research["variant_type"] = "research" adapter.variant_collection.insert_one(variant_research) # WHEN updating the manual assessments of the clinical variant adapter.variant_collection.update_one( {"_id": variant_clinical["_id"]}, { "$set": { "manual_rank": 2, "mosaic_tags": ["1"], "dismiss_variant": ["2", "3"], "acmg_classification": 0, } }, ) # WHEN filtering for that variant in research variants_query = {"variant_type": "research"} variants_query_res = adapter.variants( case_obj["_id"], query=variants_query, category=variant_clinical["category"]) # NOTE in tests list length will be used, in live code count_documents{query} is # called. number_variants = len(list(variants_query_res.clone())) res = variants(adapter, institute_obj, case_obj, variants_query_res, number_variants) res_variants = res["variants"] # THEN it is returned assert any([ variant["_id"] == variant_research["_id"] for variant in res_variants ]) # THEN previous annotations are reported back for the reseach case. assert any( [variant.get("clinical_assessments") for variant in res_variants])