code: def variant_qc(mt, name="variant_qc") -> MatrixTable:
      """Compute common variant statistics (quality control metrics).
  
      .. include:: ../_templates/req_tvariant.rst
  
      Examples
      --------
  
      >>> dataset_result = hl.variant_qc(dataset)
  
      Notes
      -----
      This method computes variant statistics from the genotype data, returning
      a new struct field `name` with the following metrics based on the fields
      present in the entry schema.
  
      If `mt` contains an entry field `DP` of type :py:data:`.tint32`, then the
      field `dp_stats` is computed. If `mt` contains an entry field `GQ` of type
      :py:data:`.tint32`, then the field `gq_stats` is computed. Both `dp_stats`
      and `gq_stats` are structs with with four fields:
  
      - `mean` (``float64``) -- Mean value.
      - `stdev` (``float64``) -- Standard deviation (zero degrees of freedom).
      - `min` (``int32``) -- Minimum value.
      - `max` (``int32``) -- Maximum value.
  
      If the dataset does not contain an entry field `GT` of type
      :py:data:`.tcall`, then an error is raised. The following fields are always
      computed from `GT`:
  
      - `AF` (``array<float64>``) -- Calculated allele frequency, one element
        per allele, including the reference. Sums to one. Equivalent to
        `AC` / `AN`.
      - `AC` (``array<int32>``) -- Calculated allele count, one element per
        allele, including the reference. Sums to `AN`.
      - `AN` (``int32``) -- Total number of called alleles.
      - `homozygote_count` (``array<int32>``) -- Number of homozygotes per
        allele. One element per allele, including the reference.
      - `call_rate` (``float64``) -- Fraction of calls neither missing nor filtered.
        Equivalent to `n_called` / :meth:`.count_cols`.
      - `n_called` (``int64``) -- Number of samples with a defined `GT`.
      - `n_not_called` (``int64``) -- Number of samples with a missing `GT`.
      - `n_filtered` (``int64``) -- Number of filtered entries.
      - `n_het` (``int64``) -- Number of heterozygous samples.
      - `n_non_ref` (``int64``) -- Number of samples with at least one called
        non-reference allele.
      - `het_freq_hwe` (``float64``) -- Expected frequency of heterozygous
        samples under Hardy-Weinberg equilibrium. See
        :func:`.functions.hardy_weinberg_test` for details.
      - `p_value_hwe` (``float64``) -- p-value from two-sided test of Hardy-Weinberg
        equilibrium. See :func:`.functions.hardy_weinberg_test` for details.
      - `p_value_excess_het` (``float64``) -- p-value from one-sided test of
        Hardy-Weinberg equilibrium for excess heterozygosity.
        See :func:`.functions.hardy_weinberg_test` for details.
  
      Warning
      -------
      `het_freq_hwe` and `p_value_hwe` are calculated as in
      :func:`.functions.hardy_weinberg_test`, with non-diploid calls
      (``ploidy != 2``) ignored in the counts. As this test is only
      statistically rigorous in the biallelic setting, :func:`.variant_qc`
      sets both fields to missing for multiallelic variants. Consider using
      :func:`~hail.methods.split_multi` to split multi-allelic variants beforehand.
  
      Parameters
      ----------
      mt : :class:`.MatrixTable`
          Dataset.
      name : :class:`str`
          Name for resulting field.
  
      Returns
      -------
      :class:`.MatrixTable`
      """
      require_alleles_field(mt, "variant_qc")
  
      bound_exprs = {}
      gq_dp_exprs = {}
  
      def has_field_of_type(name, dtype):
          return name in mt.entry and mt[name].dtype == dtype
  
      if has_field_of_type("DP", hl.tint32):
          gq_dp_exprs["dp_stats"] = hl.agg.stats(mt.DP).select(
              "mean", "stdev", "min", "max"
          )
  
      if has_field_of_type("GQ", hl.tint32):
          gq_dp_exprs["gq_stats"] = hl.agg.stats(mt.GQ).select(
              "mean", "stdev", "min", "max"
          )
  
      if not has_field_of_type("GT", hl.tcall):
          raise ValueError(
              "'variant_qc': expect an entry field 'GT' of type 'call'"
          )
  
      bound_exprs["n_called"] = hl.agg.count_where(
          hl.is_defined(mt["GT"])
      )
      bound_exprs["n_not_called"] = hl.agg.count_where(
          hl.is_missing(mt["GT"])
      )
      n_cols_ref = hl.expr.construct_expr(
          hl.ir.Ref("n_cols", hl.tint32),
          hl.tint32,
          mt._row_indices,
          hl.utils.LinkedList(hl.expr.expressions.Aggregation),
      )
      bound_exprs["n_filtered"] = hl.int64(n_cols_ref) - hl.agg.count()
      bound_exprs["call_stats"] = hl.agg.call_stats(mt.GT, mt.alleles)
  
      result = hl.rbind(
          hl.struct(**bound_exprs),
          lambda e1: hl.rbind(
              hl.case()
              .when(
                  hl.len(mt.alleles) == 2,
                  (
                      hl.hardy_weinberg_test(
                          e1.call_stats.homozygote_count[0],
                          e1.call_stats.AC[1]
                          - 2 * e1.call_stats.homozygote_count[1],
                          e1.call_stats.homozygote_count[1],
                      ),
                      hl.hardy_weinberg_test(
                          e1.call_stats.homozygote_count[0],
                          e1.call_stats.AC[1]
                          - 2 * e1.call_stats.homozygote_count[1],
                          e1.call_stats.homozygote_count[1],
                          one_sided=True,
                      ),
                  ),
              )
              .or_missing(),
              lambda hwe: hl.struct(
                  **{
                      **gq_dp_exprs,
                      **e1.call_stats,
                      "call_rate": hl.float(e1.n_called)
                      / (e1.n_called + e1.n_not_called + e1.n_filtered),
                      "n_called": e1.n_called,
                      "n_not_called": e1.n_not_called,
                      "n_filtered": e1.n_filtered,
                      "n_het": e1.n_called
                      - hl.sum(e1.call_stats.homozygote_count),
                      "n_non_ref": e1.n_called
                      - e1.call_stats.homozygote_count[0],
                      "het_freq_hwe": hwe[0].het_freq_hwe,
                      "p_value_hwe": hwe[0].p_value,
                      "p_value_excess_het": hwe[1].p_value,
                  }
              ),
          ),
      )
  
      return mt.annotate_rows(**{name: result})
  
imports: import abc
  import logging
  import hail
  from collections import Counter
  import os
  from shlex import quote
  from typing import Dict, Tuple, List, Optional, Union
  from hailtop import pip_version
  from hailtop.utils import async_to_blocking
  import hailtop.batch_client
  from hailtop.config import get_deploy_config
  from hailtop import yamlx
  from hail.backend.service_backend import ServiceBackend
  from hail.typecheck import typecheck, oneof, anytype, nullable, numeric
  from hail.expr.expressions.expression_typecheck import expr_float64
  from hail.utils import FatalError
  from hail.utils.java import Env, info, warning
  from hail.utils.misc import divide_null, guess_cloud_spark_provider, new_temp_file
  from hail.matrixtable import MatrixTable
  from hail.table import Table
  from hail.ir import TableToTableApply
  from .misc import require_biallelic, require_row_key_variant, require_col_key_str, require_table_key_variant, require_alleles_field
label_desc: Use image node_id 2 for calling a global function with example usage: variant_qc(mt, name) and returns: mt, unknown