def extract_measurement_statistic(experiment_proto, statistic):
  """Extract measurement statistics from a selection_pb2.Experiment.

  Args:
    experiment_proto: selection_pb2.Experiment proto with saved measurement
      statistics.
    statistic: string giving the name of the statistic to pull out of the proto.

  Returns:
    Dict[str, Number] giving statistics for each read.

  Raises:
    ValueError: if measurement statistics are missing.
  """
  output = {}
  for round_proto in experiment_proto.rounds.values():
    for reads in [round_proto.positive_reads, round_proto.negative_reads]:
      if reads.name:
        if not reads.HasField('statistics'):
          raise ValueError('missing statistics for reads: %r' % reads)
        output[reads.name] = getattr(reads.statistics, statistic)

  for feature in experiment_proto.additional_output:
    if feature.name:
      if not feature.HasField('statistics'):
        raise ValueError(
            'missing statistics for additional_output: %r' % feature)
      output[feature.name] = getattr(feature.statistics, statistic)
  return output