code: def impute_sex_chr_ploidy_from_interval_coverage(
      mt: "MatrixTable",
      normalization_contig: str,
  ) -> "Table":
      """Impute sex chromosome ploidy from a precomputed interval coverage MatrixTable.
  
      The input MatrixTable must have the following row fields:
  
       - ``interval`` (*interval*): Genomic interval of interest.
       - ``interval_size`` (*int32*): Size of interval, in bases.
  
      And the following entry fields:
  
       -  ``sum_dp`` (*int64*): Sum of depth values by base across the interval.
  
      Returns a :class:`.Table` with sample ID keys, with the following fields:
  
       -  ``autosomal_mean_dp`` (*float64*): Mean depth on calling intervals on normalization contig.
       -  ``x_mean_dp`` (*float64*): Mean depth on calling intervals on X chromosome.
       -  ``x_ploidy`` (*float64*): Estimated ploidy on X chromosome. Equal to ``2 * x_mean_dp / autosomal_mean_dp``.
       -  ``y_mean_dp`` (*float64*): Mean depth on calling intervals on  chromosome.
       -  ``y_ploidy`` (*float64*): Estimated ploidy on Y chromosome. Equal to ``2 * y_mean_db / autosomal_mean_dp``.
  
      Parameters
      ----------
      mt : :class:`.MatrixTable`
          Interval-by-sample MatrixTable with sum of depth values across the interval.
      normalization_contig : str
          Autosomal contig for depth comparison.
  
      Returns
      -------
      :class:`.Table`
      """
  
      rg = mt.interval.start.dtype.reference_genome
  
      if len(rg.x_contigs) != 1:
          raise NotImplementedError(
              f"reference genome {rg.name!r} has multiple X contigs, this is not supported in 'impute_sex_chr_ploidy_from_interval_coverage'"
          )
      chr_x = rg.x_contigs[0]
      if len(rg.y_contigs) != 1:
          raise NotImplementedError(
              f"reference genome {rg.name!r} has multiple Y contigs, this is not supported in 'impute_sex_chr_ploidy_from_interval_coverage'"
          )
      chr_y = rg.y_contigs[0]
  
      mt = mt.annotate_rows(contig=mt.interval.start.contig)
      mt = mt.annotate_cols(
          __mean_dp=hl.agg.group_by(
              mt.contig,
              hl.agg.sum(mt.sum_dp) / hl.agg.sum(mt.interval_size),
          )
      )
  
      mean_dp_dict = mt.__mean_dp
      auto_dp = mean_dp_dict.get(normalization_contig, 0.0)
      x_dp = mean_dp_dict.get(chr_x, 0.0)
      y_dp = mean_dp_dict.get(chr_y, 0.0)
      per_sample = mt.transmute_cols(
          autosomal_mean_dp=auto_dp,
          x_mean_dp=x_dp,
          x_ploidy=2 * x_dp / auto_dp,
          y_mean_dp=y_dp,
          y_ploidy=2 * y_dp / auto_dp,
      )
      info(
          "'impute_sex_chromosome_ploidy': computing and checkpointing coverage and karyotype metrics"
      )
      return per_sample.cols().checkpoint(
          new_temp_file("impute_sex_karyotype", extension="ht")
      )
  
imports: from typing import Sequence
  import hail
  from hail import ir
  from hail.expr import expr_any, expr_array, expr_interval, expr_locus, expr_str, expr_bool
  from hail.matrixtable import MatrixTable
  from hail.methods.misc import require_first_key_field_locus
  from hail.table import Table
  from hail.typecheck import sequenceof, typecheck, nullable, oneof, enumeration, func_spec, dictof
  from hail.utils.java import Env, info, warning
  from hail.utils.misc import divide_null, new_temp_file, wrap_to_list
  from hail.vds.variant_dataset import VariantDataset
label_desc: Use image node_id 6 for calling a global function with example usage: impute_sex_chr_ploidy_from_interval_coverage(mt, normalization_contig) and returns: per_sample