code: def import_locus_intervals(
      path,
      reference_genome="default",
      skip_invalid_intervals=False,
      contig_recoding=None,
      **kwargs,
  ) -> Table:
      """Import a locus interval list as a :class:`.Table`.
  
      Examples
      --------
  
      Add the row field `capture_region` indicating inclusion in
      at least one locus interval from `capture_intervals.txt`:
  
      >>> intervals = hl.import_locus_intervals('data/capture_intervals.txt', reference_genome='GRCh37')
      >>> result = dataset.annotate_rows(capture_region = hl.is_defined(intervals[dataset.locus]))
  
      Notes
      -----
  
      Hail expects an interval file to contain either one, three or five fields
      per line in the following formats:
  
      - ``contig:start-end``
      - ``contig  start  end`` (tab-separated)
      - ``contig  start  end  direction  target`` (tab-separated)
  
      A file in either of the first two formats produces a table with one
      field:
  
      - **interval** (:class:`.tinterval`) - Row key. Genomic interval. If
        `reference_genome` is defined, the point type of the interval will be
        :class:`.tlocus` parameterized by the `reference_genome`. Otherwise,
        the point type is a :class:`.tstruct` with two fields: `contig` with
        type :obj:`.tstr` and `position` with type :py:data:`.tint32`.
  
      A file in the third format (with a "target" column) produces a table with two
      fields:
  
       - **interval** (:class:`.tinterval`) - Row key. Same schema as above.
       - **target** (:py:data:`.tstr`)
  
      If `reference_genome` is defined **AND** the file has one field, intervals
      are parsed with :func:`.parse_locus_interval`. See the documentation for
      valid inputs.
  
      If `reference_genome` is **NOT** defined and the file has one field,
      intervals are parsed with the regex ```"([^:]*):(\\d+)\\-(\\d+)"``
      where contig, start, and end match each of the three capture groups.
      ``start`` and ``end`` match positions inclusively, e.g.
      ``start <= position <= end``.
  
      For files with three or five fields, ``start`` and ``end`` match positions
      inclusively, e.g. ``start <= position <= end``.
  
      Parameters
      ----------
      path : :class:`str`
          Path to file.
      reference_genome : :class:`str` or :class:`.ReferenceGenome`, optional
          Reference genome to use.
      skip_invalid_intervals : :obj:`bool`
          If ``True`` and `reference_genome` is not ``None``, skip lines with
          intervals that are not consistent with the reference genome.
      contig_recoding: :obj:`dict` of (:class:`str`, :obj:`str`)
          Mapping from contig name in file to contig name in loaded dataset.
          All contigs must be present in the `reference_genome`, so this is
          useful for mapping differently-formatted data onto known references.
      **kwargs
          Additional optional arguments to :func:`import_table` are valid
          arguments here except: `no_header`, `comment`, `impute`, and
          `types`, as these are used by :func:`import_locus_intervals`.
  
      Returns
      -------
      :class:`.Table`
          Interval-keyed table.
      """
  
      if contig_recoding is not None:
          contig_recoding = hl.literal(contig_recoding)
  
      def recode_contig(x):
          if contig_recoding is None:
              return x
          return contig_recoding.get(x, x)
  
      t = import_table(
          path,
          comment="@",
          impute=False,
          no_header=True,
          types={
              "f0": tstr,
              "f1": tint32,
              "f2": tint32,
              "f3": tstr,
              "f4": tstr,
          },
          **kwargs,
      )
  
      if t.row.dtype == tstruct(f0=tstr):
          if reference_genome:
              t = t.select(
                  interval=hl.parse_locus_interval(
                      t["f0"], reference_genome
                  )
              )
          else:
              interval_regex = r"([^:]*):(\d+)\-(\d+)"
  
              def checked_match_interval_expr(match):
                  return hl.or_missing(
                      hl.len(match) == 3,
                      locus_interval_expr(
                          recode_contig(match[0]),
                          hl.int32(match[1]),
                          hl.int32(match[2]),
                          True,
                          True,
                          reference_genome,
                          skip_invalid_intervals,
                      ),
                  )
  
              expr = hl.bind(
                  t["f0"].first_match_in(interval_regex),
                  lambda match: hl.if_else(
                      hl.bool(skip_invalid_intervals),
                      checked_match_interval_expr(match),
                      locus_interval_expr(
                          recode_contig(match[0]),
                          hl.int32(match[1]),
                          hl.int32(match[2]),
                          True,
                          True,
                          reference_genome,
                          skip_invalid_intervals,
                      ),
                  ),
              )
  
              t = t.select(interval=expr)
  
      elif t.row.dtype == tstruct(f0=tstr, f1=tint32, f2=tint32):
          t = t.select(
              interval=locus_interval_expr(
                  recode_contig(t["f0"]),
                  t["f1"],
                  t["f2"],
                  True,
                  True,
                  reference_genome,
                  skip_invalid_intervals,
              )
          )
  
      elif t.row.dtype == tstruct(
          f0=tstr, f1=tint32, f2=tint32, f3=tstr, f4=tstr
      ):
          t = t.select(
              interval=locus_interval_expr(
                  recode_contig(t["f0"]),
                  t["f1"],
                  t["f2"],
                  True,
                  True,
                  reference_genome,
                  skip_invalid_intervals,
              ),
              target=t["f4"],
          )
  
      else:
          raise FatalError(
              """invalid interval format.  Acceptable formats:
                'chr:start-end'
                'chr  start  end' (tab-separated)
                'chr  start  end  strand  target' (tab-separated, strand is '+' or '-')"""
          )
  
      if skip_invalid_intervals and reference_genome:
          t = t.filter(hl.is_defined(t.interval))
  
      return t.key_by("interval")
  
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 7 for calling a global function with example usage: import_locus_intervals(path, reference_genome, skip_invalid_intervals, contig_recoding) and returns: t, contig_recoding, x, hl