code: def _parameterized_filter_intervals(
      vds: "VariantDataset", intervals, keep: bool, mode: str
  ) -> "VariantDataset":
      intervals_table = None
      if isinstance(intervals, Table):
          expected = hl.tinterval(hl.tlocus(vds.reference_genome))
          if len(intervals.key) != 1 or intervals.key[
              0
          ].dtype != hl.tinterval(hl.tlocus(vds.reference_genome)):
              raise ValueError(
                  f"'filter_intervals': expect a table with a single key of type {expected}; "
                  f"found {list(intervals.key.dtype.values())}"
              )
          intervals_table = intervals
          intervals = hl.literal(
              intervals.aggregate(
                  hl.agg.collect(intervals.key[0]), _localize=False
              )
          )
  
      if mode == "unchecked_filter_both":
          return VariantDataset(
              hl.filter_intervals(vds.reference_data, intervals, keep),
              hl.filter_intervals(vds.variant_data, intervals, keep),
          )
  
      reference_data = vds.reference_data
      if keep:
          rbml = hl.vds.VariantDataset.ref_block_max_length_field
          if rbml in vds.reference_data.globals:
              max_len = hl.eval(
                  vds.reference_data.index_globals()[rbml]
              )
              ref_intervals = intervals.map(
                  lambda interval: hl.interval(
                      interval.start - (max_len - 1),
                      interval.end,
                      interval.includes_start,
                      interval.includes_end,
                  )
              )
              reference_data = hl.filter_intervals(
                  reference_data, ref_intervals, keep
              )
          else:
              warning(
                  "'hl.vds.filter_intervals': filtering intervals without a known max reference block length"
                  "\n  (computed by `hl.vds.store_ref_block_max_length` or 'hl.vds.truncate_reference_blocks')"
                  "\n  requires a full pass over the reference data (expensive!)"
              )
  
      if mode == "variants_only":
          variant_data = hl.filter_intervals(
              vds.variant_data, intervals, keep
          )
          return VariantDataset(reference_data, variant_data)
      if mode == "split_at_boundaries":
          if not keep:
              raise ValueError(
                  "filter_intervals mode 'split_at_boundaries' not implemented for keep=False"
              )
          par_intervals = intervals_table or hl.Table.parallelize(
              intervals.map(lambda x: hl.struct(interval=x)),
              schema=hl.tstruct(interval=intervals.dtype.element_type),
              key="interval",
          )
          ref = segment_reference_blocks(
              reference_data, par_intervals
          ).drop("interval_end", list(par_intervals.key)[0])
          return VariantDataset(
              ref,
              hl.filter_intervals(vds.variant_data, intervals, keep),
          )
  
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 9 for calling a global function with example usage: _parameterized_filter_intervals(vds, intervals, keep, mode) and returns: VariantDataset, VariantDataset, VariantDataset