def test_bad_get_variant_request(self): invalid_id = "Jijf30453hwbur-PWFvWIvwPRGrjnib" request = self.factory.get("/data/ga4gh/variants/"+invalid_id) response = views.get_variant(request, invalid_id) # Useful error message for an id which is not supported self.assertEqual(response.status_code, 404) self.assertJSONEqual(response.content, views.ErrorMessages['notFoundId']) invalid_id_2 = "hg37-999999999999" request = self.factory.get("/data/ga4gh/variants/" + invalid_id_2) response = views.get_variant(request, invalid_id_2) # Useful error for elements non existent in data base""" self.assertEqual(response.status_code, 404) self.assertJSONEqual(response.content, views.ErrorMessages['notFoundId'])
def test_get_variant_by_id(self): """Ensures the results found via search variants and get variant by ID are equal.""" search_request = self.factory.post("/data/ga4gh/variants/search", json.dumps({"referenceName": "chr17", "variantSetId": "brca-hg37", "start" : 4124692, "end" : 41247086, "pageSize": 1}), content_type="application/json" ) search_response = views.search_variants(search_request) json_search_response = json.loads(search_response.content)["variants"][0] self.assertIsNotNone(json_search_response["variantSetId"]) self.assertIsNotNone(json_search_response["referenceName"]) self.assertIsNotNone(json_search_response["id"]) search_based_id = str(json_search_response['id']) get_request = self.factory.get("/data/ga4gh/variants/"+search_based_id) response = views.get_variant(get_request, search_based_id) json_get_response = json.loads(response.content) """Note, because we made a get_request based on the search above, we should be able to confirm that the individual variant request is exactly the same one""" self.assertEqual(json_get_response["referenceName"], json_search_response["referenceName"]) self.assertEqual(json_get_response["start"], json_search_response["start"]) self.assertEqual(json_get_response["end"], json_search_response["end"])
def test_get_variant_by_id(self): """Ensures the results found via search variants and get variant by ID are equal.""" search_request = self.factory.post("/data/ga4gh/variants/search", json.dumps({ "referenceName": "chr17", "variantSetId": "brca-hg37", "start": 4124692, "end": 41247086, "pageSize": 1 }), content_type="application/json") search_response = views.search_variants(search_request) json_search_response = json.loads( search_response.content)["variants"][0] self.assertIsNotNone(json_search_response["variantSetId"]) self.assertIsNotNone(json_search_response["referenceName"]) self.assertIsNotNone(json_search_response["id"]) search_based_id = str(json_search_response['id']) get_request = self.factory.get("/data/ga4gh/variants/" + search_based_id) response = views.get_variant(get_request, search_based_id) json_get_response = json.loads(response.content) """Note, because we made a get_request based on the search above, we should be able to confirm that the individual variant request is exactly the same one""" self.assertEqual(json_get_response["referenceName"], json_search_response["referenceName"]) self.assertEqual(json_get_response["start"], json_search_response["start"]) self.assertEqual(json_get_response["end"], json_search_response["end"])
def test_origin(self): variant_id = "hg37-55" request = self.factory.get("/data/ga4gh/variants/"+variant_id) response = views.get_variant(request, variant_id) json_response = json.loads(response.content) hgvs_start = int( json_response['info']["Genomic_Coordinate_hg37"][0].split(':')[1].replace('g.','')) # Note that `Genomic Coordinate hg37` is 1 base offset from its determined 'start' position""" self.assertEqual(int(json_response['start']), hgvs_start, "`base_1_start`, obtained from 'Genomic Coordinate hg37' minus 1 should be equal to the `start` Variant parameter {} {}".format( int(json_response['start']), hgvs_start - 1)) variant_id = "hg38-945" request = self.factory.get("/data/ga4gh/variants/" + variant_id) response = views.get_variant(request, variant_id) json_response = json.loads(response.content) # Note that `start` is 0 base offset from its determined 'Genomic Coordinate' field""" hgvs_start = int(json_response['info']['Genomic_Coordinate_hg38'][0].split(':')[1].replace('g.','')) self.assertEqual(int(json_response['start']), hgvs_start - 1)
def test_origin(self): variant_id = "hg37-" + str(self.existing_variant_materialized_view.id) request = self.factory.get("/data/ga4gh/variants/"+variant_id) response = views.get_variant(request, variant_id) json_response = json.loads(response.content) hgvs_start = int( json_response['info']["Genomic_Coordinate_hg37"][0].split(':')[1].replace('g.', '')) # Note that `Genomic Coordinate hg37` is 1 base offset from its determined 'start' position""" self.assertEqual(int(json_response['start']), hgvs_start, "`base_1_start`, obtained from 'Genomic Coordinate hg37' minus 1 should be equal to the `start` Variant parameter {} {}".format( int(json_response['start']), hgvs_start - 1)) variant_id = "hg38-" + str(self.existing_variant_materialized_view.id) request = self.factory.get("/data/ga4gh/variants/" + variant_id) response = views.get_variant(request, variant_id) json_response = json.loads(response.content) # Note that `start` is 0 base offset from its determined 'Genomic Coordinate' field""" hgvs_start = int(json_response['info']['Genomic_Coordinate_hg38'][0].split(':')[1].replace('g.', '')) self.assertEqual(int(json_response['start']), hgvs_start)
def test_origin(self): variant_id = "hg37-55" request = self.factory.get("/data/ga4gh/variants/" + variant_id) response = views.get_variant(request, variant_id) json_response = json.loads(response.content) base_1_start = int(json_response['info']["Genomic_Coordinate_hg37"] [0].split(':')[1]) - 1 # Note that `Genomic Coordinate hg37` is 1 base offset from its determined 'start' position""" self.assertEqual( int(json_response['start']), base_1_start, "`base_1_start`, obtained from 'Genomic Coordinate hg37' minus 1 should be equal to the `start` Variant parameter" ) variant_id_2 = "hg36-945" request_2 = self.factory.get("/data/ga4gh/variants/" + variant_id_2) response_2 = views.get_variant(request_2, variant_id_2) json_response_2 = json.loads(response_2.content) base_0_start = int(json_response_2['start']) + 1 # Note that `start` is 0 base offset from its determined 'Genomic Coordinate' field""" genomic_coordinate_start = int( json_response_2['info']['Genomic_Coordinate_hg36'][0].split( ':')[1]) self.assertEqual(genomic_coordinate_start, base_0_start)