def get_variant_ad(variant): """Returns the allele depth for the Variant, calculated across its calls.""" num_alleles = len(variant.alternate_bases) + 1 call_ads = [variantcall_utils.get_format(vc, 'AD') for vc in variant.calls] assert(len(call_ad) == num_alleles for call_ad in call_ads) return [sum(call_ad[i] for call_ad in call_ads) for i in xrange(num_alleles)]
def test_get_format(self, field_name, reader, expected): if reader is not None: reader = mock.Mock() reader.field_access_cache.format_field_get_fn.return_value = ( functools.partial(struct_utils.get_string_field, is_single_field=True)) call = variants_pb2.VariantCall() variantcall_utils.set_format(call, 'GP', [.1, .2, .7]) variantcall_utils.set_format(call, 'AD', [55, 3]) variantcall_utils.set_format(call, 'DP', 58) variantcall_utils.set_format(call, 'GL', [-1, -3, -5.5]) variantcall_utils.set_format(call, 'GT', [0, 1]) variantcall_utils.set_format(call, 'FT', ['LowQual']) actual = variantcall_utils.get_format(call, field_name, vcf_object=reader) self.assertEqual(actual, expected)