def test_multi_insertion(): """Find a variantTypes INS at a position where there are two different variants.""" query = dict(QUERY) query['start'] = 16879600 query['end'] = 16879601 query['referenceBases'] = 'T' del query['alternateBases'] query['variantType'] = 'INS' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 116, "sampleCount": 2504, "exists": True, "referenceBases": "T", "alternateBases": "TAA", "variantType": "INS", "frequency": 0.023162939, } gold2 = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 314, "sampleCount": 2504, "exists": True, "referenceBases": "T", "alternateBases": "TA", "variantType": "INS", "frequency": 0.062699683, } assert_partly_in(gold, resp, 'datasetAlleleResponses') assert_partly_in(gold2, resp, 'datasetAlleleResponses')
def test_deletion_2(): """Test variantTypes DEL with startMin/startMax.""" query = dict(QUERY) del query['start'] del query['end'] query['startMin'] = 17301520 query['startMax'] = 17301530 query['endMin'] = 17301535 query['endMax'] = 17301536 query['referenceBases'] = 'ATACATAGTC' del query['alternateBases'] query['variantType'] = 'DEL' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 2932, "sampleCount": 2504, "exists": True, "referenceBases": "ATACATAGTC", "alternateBases": "A", "variantType": "DEL", "frequency": 0.585463 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_bad_end(): """Test querying with a bad end position.""" query = dict(QUERY) query['start'] = 17300407 query['end'] = 17300409 query['referenceBases'] = 'A' query['alternateBases'] = 'G' resp = call_beacon(query=query) assert 'exists' in resp and not resp['exists'], 'Beacon did not report "exist: False" for a bad query'
def test_info(): """Test the beacon's info (/) call.""" resp = call_beacon(path='/') # takes care of calling, validating to schemas, status code counts = {"id": "GRCh38:beacon_test:2030-01-01", "assemblyId": "GRCh38", "variantCount": 17, "callCount": 12, "sampleCount": 2504 } assert_partly_in(counts, resp, 'datasets')
def run_test(test): """Call the beacon as specified in the test and check the result.""" logging.info(f"Running test {test['name']}") logging.debug(f"{test.get('descr', '')}") logging.debug( f"Assuming that this data is present in your beacon: {test.get('data', [])}" ) settings = utils.setup.Settings() if test.get('skip', False): return try: status_code, ignore_schemas = prepare_call(test) if 'query' not in test: resp = call_beacon(path='/', code=status_code, ignore_schemas=ignore_schemas) else: query = prepare_query(test['query']) resp = call_beacon(query=query, code=status_code, ignore_schemas=ignore_schemas) if settings.check_result: for check in test['results']: assert_test(check, resp) except err.ResponseError as r_error: # errors from the comparisons of a response, contains a list of errors to report logging.error('Test "%s" did not pass: """%s"""', test['name'], test['descr']) for err_msg in r_error.messages: settings.errors += 1 logging.error(err_msg) except AssertionError as a_error: # other errors logging.error('Test "%s" did not pass: """%s"""', test['name'], test['descr']) logging.error(str(a_error)) settings.errors += 1
def test_multi(): """Test alternateBases=N and multiple variations from one vcf line (indel).""" query = dict(QUERY) query['start'] = 19617926 query['referenceBases'] = 'N' query['alternateBases'] = 'N' del query['end'] resp = call_beacon(query=query) golds = [ {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 17, "sampleCount": 2504, "exists": True, "referenceBases": "GTCT", "alternateBases": "GTCTTCTTCT", "variantType": "INS", "frequency": 0.00339457 }, {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 118, "sampleCount": 2504, "exists": True, "referenceBases": "GTCT", "alternateBases": "GTCTTCT", "variantType": "INS", "frequency": 0.0235623 }, {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "variantCount": 182, "callCount": 5008, "sampleCount": 2504, "exists": True, "referenceBases": "GTCT", "alternateBases": "G", "variantType": "DEL", "frequency": 0.036341853 }] for gold in golds: assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_end(): """Test the same query as `test_bad_end()` but with the correct end position.""" query = dict(QUERY) query['start'] = 17300407 query['end'] = 17300408 query['referenceBases'] = 'A' query['alternateBases'] = 'G' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 4723, "sampleCount": 2504, "exists": True, "referenceBases": "A", "alternateBases": "G", "variantType": "SNP", "frequency": 0.943091 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_search_1(): """Test a standard query with alternateBases, start and end.""" query = dict(QUERY) query['start'] = 16050074 query['end'] = 16050075 query['referenceBases'] = 'A' query['alternateBases'] = 'G' gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 1, "sampleCount": 2504, "exists": True, "referenceBases": "A", "alternateBases": "G", "variantType": "SNP", "frequency": 0.000199681 } resp = call_beacon(query=query) assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_deletion_altbase(): """Test a deletion by searching for ref and alt.""" query = dict(QUERY) query['start'] = 16497140 query['end'] = 16497143 query['referenceBases'] = 'CTT' query['alternateBases'] = 'C' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 4, "sampleCount": 2504, "exists": True, "referenceBases": "CTT", "alternateBases": "C", "variantType": "DEL", "frequency": 0.000798722 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_insertion_altbase(): """Test variantTypes by searching for ref and alt.""" query = dict(QUERY) query['start'] = 16539540 query['end'] = 16539541 query['referenceBases'] = 'A' query['alternateBases'] = 'AC' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 7, "sampleCount": 2504, "exists": True, "referenceBases": "A", "alternateBases": "AC", "variantType": "INS", "frequency": 0.00139776 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_snp(): """Test variantType SNP.""" query = dict(QUERY) query['start'] = 17302971 query['end'] = 17302972 query['variantType'] = 'SNP' query['referenceBases'] = 'C' del query['alternateBases'] resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 2931, "sampleCount": 2504, "exists": True, "referenceBases": "C", "alternateBases": "A", "variantType": "SNP", "frequency": 0.585264 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_deletion(): """Test variantTypes DEL.""" query = dict(QUERY) query['start'] = 16517679 query['end'] = 16517684 query['referenceBases'] = 'GACAA' del query['alternateBases'] query['variantType'] = 'DEL' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 3, "sampleCount": 2504, "exists": True, "referenceBases": "GACAA", "alternateBases": "G", "variantType": "DEL", "frequency": 0.000599042 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_snp_mnp(): """Test representation of TG->AG and multiple variations from one vcf line.""" query = dict(QUERY) query['start'] = 16577043 query['end'] = 16577045 query['referenceBases'] = 'TG' del query['alternateBases'] query['variantType'] = 'SNP' resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 17, "sampleCount": 2504, "exists": True, "referenceBases": "TG", "alternateBases": "AG", "variantType": "SNP", "frequency": 0.003394569 } assert_partly_in(gold, resp, 'datasetAlleleResponses')
def test_insertion(): """Test variantTypes INS.""" query = dict(QUERY) query['start'] = 16064512 query['end'] = 16064513 query['variantType'] = 'INS' query['referenceBases'] = 'A' del query['alternateBases'] resp = call_beacon(query=query) gold = {"datasetId": "GRCh38:beacon_test:2030-01-01", "referenceName": "22", "callCount": 5008, "variantCount": 21, "sampleCount": 2504, "exists": True, "referenceBases": "A", "alternateBases": "AAGAATGGCCTAATAC", "variantType": "INS", "frequency": 0.00419329 } assert_partly_in(gold, resp, 'datasetAlleleResponses')