def get_allele_frequency(variant, index):
  """Gets allele frequency of the index-th alt_base of a Variant proto.

  Args:
    variant: A Variant proto.
    index: The index where we want to query allele frequency.

  Returns:
    A float. The queried allele frequency.

  Raises:
    ValueError: If the Variant proto does not include 'AF' field or the 'AF'
      field encounters an out-of-bound error when querying at position `index`
  """
  if variant.info.get('AF'):
    if index < len(variant.info['AF'].values):
      return variant.info['AF'].values[index].number_value
    else:
      raise ValueError('Invalid index', index, 'for the info[AF] field',
                       variant.info['AF'].values)
  raise ValueError('Variant does not have an AF field')