def set_info(variant, field_name, value, vcf_object=None): """Sets a field of the info map of the `Variant` to the given value(s). `variant.info` is analogous to the INFO field of a VCF record. Args: variant: Variant proto. The Variant to modify. field_name: str. The name of the field to set. value: A single value or list of values to update the Variant with. The type of the value is determined by the `vcf_object` if one is given, otherwise is looked up based on the reserved INFO fields in the VCF specification. vcf_object: (Optional) nucleus.io.vcf.Vcf{Reader,Writer}. 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 vcf_object is None: set_field_fn = vcf_constants.reserved_info_field_set_fn(field_name) else: set_field_fn = vcf_object.field_access_cache.info_field_set_fn(field_name) set_field_fn(variant.info, field_name, value)
def test_invalid_reserved_info_field_set_fn(self, field): with self.assertRaisesRegexp(ValueError, 'Unknown reserved INFO field:'): vcf_constants.reserved_info_field_set_fn(field)
def test_reserved_info_field_set_fn(self, field, expected): actual = vcf_constants.reserved_info_field_set_fn(field) self.assertIs(actual, expected)
def test_invalid_reserved_info_field_set_fn(self, field): with self.assertRaisesRegexp(ValueError, 'Unknown reserved INFO field:'): vcf_constants.reserved_info_field_set_fn(field)
def test_reserved_info_field_set_fn(self, field, expected): actual = vcf_constants.reserved_info_field_set_fn(field) self.assertIs(actual, expected)