def _get_variant_stats(variant, vaf_available=False, vcf_reader=None): """Returns a VariantStats object corresponding to the input variant.""" vtype = _get_variant_type(variant) is_transition, is_transversion = _tstv(variant, vtype) vaf = None if vaf_available: vaf = _get_vaf(variant, vcf_reader) return VariantStats( reference_name=variant.reference_name, position=(variant.start + 1), reference_bases=variant.reference_bases, alternate_bases=list(variant.alternate_bases), variant_type=vtype, is_transition=is_transition, is_transversion=is_transversion, is_variant=variant_utils.is_variant_call(variant), depth=variantcall_utils.get_format( variant_utils.only_call(variant), 'DP'), genotype_quality=variantcall_utils.get_gq( variant_utils.only_call(variant)), genotype=str( sorted(variantcall_utils.get_gt(variant_utils.only_call(variant)))), vaf=vaf, qual=variant.quality)
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)
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)
def _get_vaf(variant, vcf_reader): """Gets the VAF (variant allele frequency).""" vafs = variantcall_utils.get_format( variant_utils.only_call(variant), 'VAF', vcf_reader) return sum(vafs)