code: def make_variants_matrix_table(
      mt: MatrixTable, info_to_keep: Optional[Collection[str]] = None
  ) -> MatrixTable:
      if info_to_keep is None:
          info_to_keep = []
      if not info_to_keep:
          info_to_keep = [
              name for name in mt.info if name not in ["END", "DP"]
          ]
      info_key = tuple(sorted(info_to_keep))  # hashable stable value
      mt = localize(mt)
      mt = mt.filter(hl.is_missing(mt.info.END))
  
      transform_row = _transform_variant_function_map.get(
          (mt.row.dtype, info_key)
      )
      if (
          transform_row is None
          or not hl.current_backend()._is_registered_ir_function_name(
              transform_row._name
          )
      ):
  
          def get_lgt(gt, n_alleles, has_non_ref, row):
              index = gt.unphase().unphased_diploid_gt_index()
              n_no_nonref = n_alleles - hl.int(has_non_ref)
              triangle_without_nonref = hl.triangle(n_no_nonref)
              return (
                  hl.case()
                  .when(
                      gt.is_haploid(),
                      hl.or_missing(gt[0] < n_no_nonref, gt),
                  )
                  .when(index < triangle_without_nonref, gt)
                  .when(
                      index < hl.triangle(n_alleles), hl.missing("call")
                  )
                  .or_error(
                      "invalid call "
                      + hl.str(gt)
                      + " at site "
                      + hl.str(row.locus)
                  )
              )
  
          def make_entry_struct(e, alleles_len, has_non_ref, row):
              handled_fields = dict()
              handled_names = {
                  "LA",
                  "gvcf_info",
                  "LAD",
                  "AD",
                  "LGT",
                  "GT",
                  "LPL",
                  "PL",
                  "LPGT",
                  "PGT",
              }
  
              if "GT" not in e:
                  raise hl.utils.FatalError(
                      "the Hail VDS combiner expects input GVCFs to have a 'GT' field in FORMAT."
                  )
  
              handled_fields["LA"] = hl.range(
                  0, alleles_len - hl.if_else(has_non_ref, 1, 0)
              )
              handled_fields["LGT"] = get_lgt(
                  e.GT, alleles_len, has_non_ref, row
              )
              if "AD" in e:
                  handled_fields["LAD"] = hl.if_else(
                      has_non_ref, e.AD[:-1], e.AD
                  )
              if "PGT" in e:
                  handled_fields["LPGT"] = (
                      e.PGT
                      if e.PGT.dtype != hl.tcall
                      else get_lgt(e.PGT, alleles_len, has_non_ref, row)
                  )
              if "PL" in e:
                  handled_fields["LPL"] = hl.if_else(
                      has_non_ref,
                      hl.if_else(
                          alleles_len > 2,
                          e.PL[:-alleles_len],
                          hl.missing(e.PL.dtype),
                      ),
                      hl.if_else(
                          alleles_len > 1, e.PL, hl.missing(e.PL.dtype)
                      ),
                  )
                  handled_fields["RGQ"] = hl.if_else(
                      has_non_ref,
                      hl.if_else(
                          e.GT.is_haploid(),
                          e.PL[alleles_len - 1],
                          e.PL[
                              hl.call(
                                  0, alleles_len - 1
                              ).unphased_diploid_gt_index()
                          ],
                      ),
                      hl.missing(e.PL.dtype.element_type),
                  )
  
              handled_fields["gvcf_info"] = (
                  hl.case()
                  .when(
                      hl.is_missing(row.info.END),
                      parse_allele_specific_fields(
                          row.info.select(*info_to_keep), has_non_ref
                      ),
                  )
                  .or_missing()
              )
  
              pass_through_fields = {
                  k: v for k, v in e.items() if k not in handled_names
              }
              return hl.struct(**handled_fields, **pass_through_fields)
  
          transform_row = hl.experimental.define_function(
              lambda row: hl.rbind(
                  hl.len(row.alleles),
                  "<NON_REF>" == row.alleles[-1],
                  lambda alleles_len, has_non_ref: hl.struct(
                      locus=row.locus,
                      alleles=hl.if_else(
                          has_non_ref, row.alleles[:-1], row.alleles
                      ),
                      **({"rsid": row.rsid} if "rsid" in row else {}),
                      __entries=row.__entries.map(
                          lambda e: make_entry_struct(
                              e, alleles_len, has_non_ref, row
                          )
                      ),
                  ),
              ),
              mt.row.dtype,
          )
          _transform_variant_function_map[
              mt.row.dtype, info_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 1 for calling a global function with example usage: make_variants_matrix_table(mt, info_to_keep) and returns: unlocalize, hl, hl