def test_order_of_genotypes(self): run_id = self.no_chr_run['id'] query = { 'range': {}, 'filters': [{'columnName': 'sample_name', 'filterValue': 'normal', 'type': '='}], 'sortBy': [{'columnName': 'contig', 'order': 'asc'}, {'columnName': 'position', 'order': 'asc'}] } records = genotypes.get(run_id, query, with_stats=False)['records'] results = [pick(r, 'contig', 'position') for r in records] expected_results = [{'contig': '1', 'position': 1}, {'contig': '1', 'position': 2}, {'contig': '1', 'position': 10}, {'contig': '1', 'position': 11}, {'contig': '1', 'position': 21}, {'contig': '2', 'position': 1}, {'contig': '10', 'position': 17}, {'contig': '11', 'position': 163}, {'contig': '20', 'position': 123}, {'contig': '23', 'position': 1}, {'contig': 'X', 'position': 2}, {'contig': 'Y', 'position': 1}, {'contig': 'Y', 'position': 7}, {'contig': 'Y', 'position': 17}, {'contig': 'Y', 'position': 19}, {'contig': 'Y', 'position': 21}, {'contig': 'GTR01', 'position': 20}, {'contig': 'GT05182', 'position': 1}] asserts.eq_(results, expected_results)
def test_order_of_genotypes_by_dp_asc(self): run_id = self.no_chr_run['id'] query = { 'range': {}, 'filters': [{'columnName': 'sample_name', 'filterValue': 'normal', 'type': '='}], 'sortBy': [{'columnName': 'sample:DP', 'order': 'asc'}] } records = genotypes.get(run_id, query, with_stats=False)['records'] results = [pick(r, 'contig', 'position', 'sample:DP') for r in records] expected_results = [{'contig': 'Y', 'position': 21, 'sample:DP': '10'}, {'contig': 'Y', 'position': 1, 'sample:DP': '11'}, {'contig': 'Y', 'position': 7, 'sample:DP': '12'}, {'contig': 'Y', 'position': 19, 'sample:DP': '13'}, {'contig': 'Y', 'position': 17, 'sample:DP': '21'}, {'contig': '10', 'position': 17, 'sample:DP': '30'}, {'contig': '11', 'position': 163, 'sample:DP': '30'}, {'contig': '20', 'position': 123, 'sample:DP': '30'}, {'contig': 'X', 'position': 2, 'sample:DP': '32'}, {'contig': '2', 'position': 1, 'sample:DP': '45'}, {'contig': 'GTR01', 'position': 20, 'sample:DP': '45'}, {'contig': '1', 'position': 1, 'sample:DP': '67'}, {'contig': '1', 'position': 2, 'sample:DP': '67'}, {'contig': '1', 'position': 10, 'sample:DP': '67'}, {'contig': '1', 'position': 11, 'sample:DP': '67'}, {'contig': '1', 'position': 21, 'sample:DP': '67'}, {'contig': '23', 'position': 1, 'sample:DP': '99'}, {'contig': 'GT05182', 'position': 1, 'sample:DP': '99'}] asserts.eq_(results, expected_results)
def test_filtered_sample_gt(self): run_id = self.no_chr_run['id'] query = { 'range': {}, 'filters': [{'columnName': 'sample:RD', 'filterValue': '35', 'type': '>'}], 'sortBy': [] } records = genotypes.get(run_id, query, with_stats=False)['records'] results = [pick(r, 'contig', 'sample:RD', 'sample_name') for r in records] expected_results = [{'contig': '1', 'sample:RD': '38', 'sample_name': 'normal'}, {'contig': '1', 'sample:RD': '36', 'sample_name': 'normal'}, {'contig': '1', 'sample:RD': '45', 'sample_name': 'normal'}, {'contig': '10', 'sample:RD': '72', 'sample_name': 'tumor'}, {'contig': 'Y', 'sample:RD': '67', 'sample_name': 'normal'}, {'contig': 'GTR01', 'sample:RD': '51', 'sample_name': 'tumor'}, {'contig': 'GT05182', 'sample:RD': '91', 'sample_name': 'normal'}] asserts.eq_(len(results), 7) asserts.eq_(results, expected_results)
def test_filtered_info_lt(self): run_id = self.no_chr_run['id'] query = { 'range': {}, 'filters': [{'columnName': 'sample_name', 'filterValue': 'tumor', 'type': '='}, {'columnName': 'info:DP', 'filterValue': '50', 'type': '<'}], 'sortBy': [] } records = genotypes.get(run_id, query, with_stats=False)['records'] results = [pick(r, 'contig', 'position', 'info:DP') for r in records] expected_results = [{'contig': '1', 'info:DP': '43', 'position': 11}, {'contig': '10', 'info:DP': '18', 'position': 17}, {'contig': '11', 'info:DP': '12', 'position': 163}, {'contig': '20', 'info:DP': '12', 'position': 123}, {'contig': 'Y', 'info:DP': '49', 'position': 1}, {'contig': 'GTR01', 'info:DP': '45', 'position': 20}] asserts.eq_(len(results), 6) asserts.eq_(results, expected_results)
def test_pick(): asserts.eq_(pick({'a': 1, 'b': 2, 'c': 'abc'}, 'a', 'c'), {'a': 1, 'c': 'abc'}) asserts.eq_(pick({'a': 1, 'b': 2, 'c': 'abc'}), {}) pick({'a': 'oh no'}, 'b') # This raises a KeyError