def test_reserved_format_field_get_fn(self): info = variants_pb2.VariantCall().info expected = [0.2, 0.5, 0.3] struct_utils.set_number_field(info, 'GP', expected[:]) get_fn = vcf_constants.reserved_format_field_get_fn('GP') actual = get_fn(info, 'GP') self.assertEqual(actual, expected)
def get_format(variant_call, field_name, vcf_object=None): """Returns the value of the `field_name` FORMAT field. The `vcf_object` is used to determine the type of the resulting value. If it is a single value or a Flag, that single value will be returned. Otherwise, the list of values is returned. Args: variant_call: VariantCall proto. The VariantCall of interest. field_name: str. The name of the field to retrieve values from. vcf_object: (Optional) A VcfReader or VcfWriter object. If not None, the type of the field is inferred from the associated VcfReader or VcfWriter based on its name. Otherwise, the type is inferred if it is a reserved field. """ if field_name == _GL: return get_gl(variant_call) if field_name == _GT: return get_gt(variant_call) if vcf_object is None: get_field_fn = vcf_constants.reserved_format_field_get_fn(field_name) else: get_field_fn = vcf_object.field_access_cache.format_field_get_fn(field_name) return get_field_fn(variant_call.info, field_name)
def test_invalid_reserved_format_field_get_fn(self, field): with self.assertRaisesRegexp(ValueError, 'Unknown reserved FORMAT field to get:'): vcf_constants.reserved_format_field_get_fn(field)