code: def make_reference_matrix_table(
      mt: MatrixTable, entry_to_keep: Collection[str]
  ) -> MatrixTable:
      mt = mt.filter_rows(hl.is_defined(mt.info.END))
      entry_key = tuple(sorted(entry_to_keep))  # hashable stable value
  
      def make_entry_struct(e, row):
          handled_fields = dict()
          # we drop PL by default, but if `entry_to_keep` has it then PL needs to be
          # turned into LPL
          handled_names = {"AD", "PL"}
  
          if "AD" in entry_to_keep:
              handled_fields["LAD"] = e["AD"][:1]
          if "PL" in entry_to_keep:
              handled_fields["LPL"] = e["PL"][:1]
  
          reference_fields = {
              k: v
              for k, v in e.items()
              if k in entry_to_keep and k not in handled_names
          }
          return (
              hl.case()
              .when(
                  e.GT.is_hom_ref(),
                  hl.struct(
                      END=row.info.END,
                      **reference_fields,
                      **handled_fields,
                  ),
              )
              .or_error(
                  "found END with non reference-genotype at"
                  + hl.str(row.locus)
              )
          )
  
      mt = localize(mt).key_by("locus")
      transform_row = _transform_reference_fuction_map.get(
          (mt.row.dtype, entry_key)
      )
      if (
          transform_row is None
          or not hl.current_backend()._is_registered_ir_function_name(
              transform_row._name
          )
      ):
          transform_row = hl.experimental.define_function(
              lambda row: hl.struct(
                  locus=row.locus,
                  __entries=row.__entries.map(
                      lambda e: make_entry_struct(e, row)
                  ),
              ),
              mt.row.dtype,
          )
          _transform_reference_fuction_map[
              mt.row.dtype, entry_key
          ] = transform_row
  
      return unlocalize(
          Table(
              TableMapRows(
                  mt._tir,
                  Apply(
                      transform_row._name,
                      transform_row._ret_type,
                      mt.row._ir,
                  ),
              )
          )
      )
  
imports: import math
  from typing import Collection, Optional, Set, Union, List, Tuple, Dict
  import hail
  from hail import MatrixTable, Table
  from hail.experimental.function import Function
  from hail.expr import StructExpression, unify_all, construct_expr
  from hail.expr.expressions import expr_bool, expr_str
  from hail.genetics.reference_genome import reference_genome_type
  from hail.ir import Apply, TableMapRows
  from hail.typecheck import oneof, sequenceof, typecheck
  from ..variant_dataset import VariantDataset
label_desc: Use image node_id 5 for calling a global function with example usage: make_reference_matrix_table(mt, entry_to_keep) and returns: unlocalize, hl