def update_haplotype(variant, reference_haplotype, reference_offset):
  """Updates haplotypes for a variant.

  A list of variant haplotypes are updated given a variant and a reference
  haplotype (this consists of a sequence and an offset wrt to the reference).
  All ALT alleles are updated as independent updated haplotypes.

  Args:
    variant: A Variant proto.
    reference_haplotype: A string extracted from the reference genome.
    reference_offset: An integer. The offset of the starting position of
      reference_haplotype on reference.

  Raises:
    ValueError: Variant.start is smaller than reference_offset.

  Returns:
    A list of haplotype objects. Haplotype objects are stored as dicts:
      {'haplotype': a haplotype (string),
       'alt': an alt allele (string),
       'variant': an Variant proto}
  """
  if variant.start < reference_offset:
    raise ValueError('The starting position of a variant is smaller than its ',
                     'corresponding reference offset', variant.start,
                     reference_offset)
  offset_start = variant.start - reference_offset
  offset_suffix = \
      variant.start + len(variant.reference_bases) - reference_offset
  list_updated_haplotype = []
  for biallelic_variant in variant.alternate_bases:
    updated_haplotype = reference_haplotype[: offset_start] + \
        biallelic_variant + reference_haplotype[offset_suffix: ]
    dict_haplotype = {
        'haplotype': updated_haplotype,
        'alt': biallelic_variant,
        'variant': variant
    }
    list_updated_haplotype.append(dict_haplotype)

  return list_updated_haplotype