code: def examples_to_variants(examples_path, max_records=None):
      """Yields Variant protos from the examples in examples_path.
  
      This function reads in tf.Examples produced by DeepVariant from examples_path,
      which may contain a sharded spec, sorts them, selects a representive example
      when there are multiple versions representing different alt_alleles, and
      yields the example_variant field from those examples.
  
      Args:
        examples_path: str. Path, or sharded spec, to labeled tf.Examples produced
          by DeepVariant in training mode.
        max_records: int or None. Maximum number of records to read, or None, to
          read all of the records.
  
      Yields:
        nucleus.protos.Variant protos in coordinate-sorted order.
  
      Raises:
        ValueError: if we find a Variant in any example that doesn't have genotypes.
      """
      examples = tfrecord.read_tfrecords(
          examples_path, max_records=max_records
      )
      variants_and_labels = sorted(
          (
              (
                  dv_utils.example_variant(example),
                  dv_utils.example_label(example),
              )
              for example in examples
          ),
          key=lambda x: variant_utils.variant_range_tuple(x[0]),
      )
      for _, group in itertools.groupby(
          variants_and_labels,
          lambda x: variant_utils.variant_range_tuple(x[0]),
      ):
          (variant, label) = next(group)
          if not variantcall_utils.has_genotypes(
              variant_utils.only_call(variant)
          ):
              if label is not None:
                  logging.log_every_n(
                      logging.INFO,
                      "Variant in the example does not have GT. Use label to fill GT.",
                      _LOG_EVERY.value,
                  )
                  if label == 0:
                      gt = (0, 0)
                  if label == 1:
                      gt = (0, 1)
                  if label == 2:
                      gt = (1, 1)
                  call = (
                      variant.calls[0]
                      if variant.calls
                      else variant.calls.add()
                  )
                  variantcall_utils.set_gt(call, gt)
              elif _ALLOW_UNLABELED_EXAMPLES.value:
                  call = (
                      variant.calls[0]
                      if variant.calls
                      else variant.calls.add()
                  )
                  variantcall_utils.set_gt(call, (-1, -1))
              else:
                  raise ValueError(
                      (
                          "Variant {} does not have any genotypes. This tool only works "
                          "with variants that have been labeled."
                      ).format(variant_utils.variant_key(variant))
                  )
          yield variant
  
file_path: deepvariant/deepvariant/labeler/labeled_examples_to_vcf.py
imports: import itertools
  from absl import app
  from absl import flags
  from absl import logging
  from deepvariant import dv_utils
  from deepvariant import dv_vcf_constants
  from third_party.nucleus.io import fasta
  from third_party.nucleus.io import tfrecord
  from third_party.nucleus.io import vcf
  from third_party.nucleus.util import variant_utils
  from third_party.nucleus.util import variantcall_utils
label_desc: Use image node_id 2 for calling a global function with example usage: examples_to_variants(examples_path, max_records) without return types