code: def import_plink(
      bed,
      bim,
      fam,
      min_partitions=None,
      delimiter="\\\\s+",
      missing="NA",
      quant_pheno=False,
      a2_reference=True,
      reference_genome="default",
      contig_recoding=None,
      skip_invalid_loci=False,
      n_partitions=None,
      block_size=None,
  ) -> MatrixTable:
      """Import a PLINK dataset (BED, BIM, FAM) as a :class:`.MatrixTable`.
  
      Examples
      --------
  
      >>> ds = hl.import_plink(bed='data/test.bed',
      ...                      bim='data/test.bim',
      ...                      fam='data/test.fam',
      ...                      reference_genome='GRCh37')
  
      Notes
      -----
  
      Only binary SNP-major mode files can be read into Hail. To convert your
      file from individual-major mode to SNP-major mode, use PLINK to read in
      your fileset and use the ``--make-bed`` option.
  
      Hail uses the individual ID (column 2 in FAM file) as the sample id (`s`).
      The individual IDs must be unique.
  
      The resulting :class:`.MatrixTable` has the following fields:
  
      * Row fields:
  
          * `locus` (:class:`.tlocus` or :class:`.tstruct`) -- Row key. The
            chromosome and position. If `reference_genome` is defined, the type
            will be :class:`.tlocus` parameterized by `reference_genome`.
            Otherwise, the type will be a :class:`.tstruct` with two fields:
            `contig` with type :py:data:`.tstr` and `position` with type
            :py:data:`.tint32`.
          * `alleles` (:class:`.tarray` of :py:data:`.tstr`) -- Row key. An
            array containing the alleles of the variant. The reference allele (A2
            if `a2_reference` is ``True``) is the first element in the array.
          * `rsid` (:py:data:`.tstr`) -- Column 2 in the BIM file.
          * `cm_position` (:py:data:`.tfloat64`) -- Column 3 in the BIM file,
            the position in centimorgans.
  
      * Column fields:
  
          * `s` (:py:data:`.tstr`) -- Column 2 in the Fam file (key field).
          * `fam_id` (:py:data:`.tstr`) -- Column 1 in the FAM file. Set to
            missing if ID equals "0".
          * `pat_id` (:py:data:`.tstr`) -- Column 3 in the FAM file. Set to
            missing if ID equals "0".
          * `mat_id` (:py:data:`.tstr`) -- Column 4 in the FAM file. Set to
            missing if ID equals "0".
          * `is_female` (:py:data:`.tstr`) -- Column 5 in the FAM file. Set to
            missing if value equals "-9", "0", or "N/A". Set to true if value
            equals "2". Set to false if value equals "1".
          * `is_case` (:py:data:`.tbool`) -- Column 6 in the FAM file. Only
            present if `quant_pheno` equals False. Set to missing if value equals
            "-9", "0", "N/A", or the value specified by `missing`. Set to true if
            value equals "2". Set to false if value equals "1".
          * `quant_pheno` (:py:data:`.tfloat`) -- Column 6 in the FAM file. Only
            present if `quant_pheno` equals True. Set to missing if value equals
            `missing`.
  
      * Entry fields:
  
          * `GT` (:py:data:`.tcall`) -- Genotype call (diploid, unphased).
  
      Warning
      -------
      Hail will interpret the value "-9" as a valid quantitative phenotype, which
      differs from default PLINK behavior. Use ``missing='-9'`` to interpret this
      value as missing.
  
      Parameters
      ----------
      bed : :class:`str`
          PLINK BED file.
  
      bim : :class:`str`
          PLINK BIM file.
  
      fam : :class:`str`
          PLINK FAM file.
  
      min_partitions : :obj:`int`, optional
          Minimum number of partitions.  Useful in conjunction with `block_size`.
  
      missing : :class:`str`
          String used to denote missing values **only** for the phenotype field.
          This is in addition to "-9", "0", and "N/A" for case-control
          phenotypes.
  
      delimiter : :class:`str`
          FAM file field delimiter regex.
  
      quant_pheno : :obj:`bool`
          If ``True``, FAM phenotype is interpreted as quantitative.
  
      a2_reference : :obj:`bool`
          If ``True``, A2 is treated as the reference allele. If False, A1 is treated
          as the reference allele.
  
      reference_genome : :class:`str` or :class:`.ReferenceGenome`, optional
          Reference genome to use.
  
      contig_recoding : :obj:`dict` of :class:`str` to :obj:`str`, optional
          Dict of old contig name to new contig name. The new contig name must be
          in the reference genome given by ``reference_genome``. If ``None``, the
          default is dependent on the ``reference_genome``. For "GRCh37", the default
          is ``{'23': 'X', '24': 'Y', '25': 'X', '26': 'MT'}``. For "GRCh38", the
          default is ``{'1': 'chr1', ..., '22': 'chr22', '23': 'chrX', '24': 'chrY', '25': 'chrX', '26': 'chrM'}``.
  
      skip_invalid_loci : :obj:`bool`
          If ``True``, skip loci that are not consistent with `reference_genome`.
  
      n_partitions : :obj:`int`, optional
          Number of partitions.  If both `n_partitions` and `block_size`
          are specified, `n_partitions` will be used.
  
      block_size : :obj:`int`, optional
          Block size, in MB.  Default: 128MB blocks.
  
      Returns
      -------
      :class:`.MatrixTable`
  
      """
  
      if contig_recoding is None:
          if reference_genome is None:
              contig_recoding = {}
          elif reference_genome.name == "GRCh37":
              contig_recoding = {
                  "23": "X",
                  "24": "Y",
                  "25": "X",
                  "26": "MT",
              }
          elif reference_genome.name == "GRCh38":
              contig_recoding = {
                  **{str(i): f"chr{i}" for i in range(1, 23)},
                  **{
                      "23": "chrX",
                      "24": "chrY",
                      "25": "chrX",
                      "26": "chrM",
                  },
              }
          else:
              contig_recoding = {}
  
      reader = ir.MatrixPLINKReader(
          bed,
          bim,
          fam,
          n_partitions,
          block_size,
          min_partitions,
          missing,
          delimiter,
          quant_pheno,
          a2_reference,
          reference_genome,
          contig_recoding,
          skip_invalid_loci,
      )
      return MatrixTable(
          ir.MatrixRead(reader, drop_cols=False, drop_rows=False)
      )
  
imports: import os
  import re
  from collections import defaultdict
  import avro.schema
  from avro.datafile import DataFileReader
  from avro.io import DatumReader
  import hail
  from hail import ir
  from hail.expr import StructExpression, LocusExpression, expr_array, expr_float64, expr_str, expr_numeric, expr_call, expr_bool, expr_int32, to_expr, analyze
  from hail.expr.types import hail_type, tarray, tfloat64, tstr, tint32, tstruct, tcall, tbool, tint64, tfloat32
  from hail.genetics.reference_genome import reference_genome_type
  from hail.ir.utils import parse_type
  from hail.matrixtable import MatrixTable
  from hail.methods.misc import require_biallelic, require_row_key_variant, require_col_key_str
  from hail.table import Table
  from hail.typecheck import typecheck, nullable, oneof, dictof, anytype, sequenceof, enumeration, sized_tupleof, numeric, table_key_type, char
  from hail.utils import new_temp_file
  from hail.utils.deduplicate import deduplicate
  from hail.utils.java import Env, FatalError, jindexed_seq_args, warning
  from hail.utils.java import info
  from hail.utils.misc import wrap_to_list, plural
  from .import_lines_helpers import split_lines, should_remove_line
label_desc: Use image node_id 16 for calling a global function with example usage: import_plink(bed, bim, fam, min_partitions, delimiter, missing, quant_pheno, a2_reference, reference_genome, contig_recoding, skip_invalid_loci, n_partitions, block_size) and returns: MatrixTable