code: def expand(region, n_bp, contig_map=None):
      """Expands region by n_bp in both directions.
  
      Takes a Range(chrom, start, stop) and returns a new
      Range(chrom, new_start, new_stop), where:
  
      -- new_start is max(start - n_bp, 0)
      -- new_stop is stop + n_bp if contig_map is None, or min(stop + n_bp, max_bp)
         where max_bp is contig_map[chrom].n_bp.
  
      Args:
        region: A nucleus.genomics.v1.Range proto.
        n_bp: int >= 0. how many basepairs to increase region by.
        contig_map: dict[string, ContigInfo] or None. If not None, used to get the
          maximum extent to increase stop by. Must have region.reference_name as a
          key.
  
      Returns:
        nucleus.genomics.v1.Range proto.
  
      Raises:
        ValueError: if n_bp is invalid.
        KeyError: contig_map is not None and region.reference_name isn't a key.
      """
      if n_bp < 0:
          raise ValueError("n_bp must be >= 0 but got {}".format(n_bp))
  
      new_start = max(region.start - n_bp, 0)
      new_end = region.end + n_bp
      if contig_map is not None:
          new_end = min(
              new_end, contig_map[region.reference_name].n_bases
          )
      return make_range(region.reference_name, new_start, new_end)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import re
  from typing import Dict, Iterable, Optional, Sequence
  from absl import logging
  from etils import epath
  import intervaltree
  import six
  from third_party.nucleus.io import bed
  from third_party.nucleus.protos import position_pb2
  from third_party.nucleus.protos import range_pb2
  from third_party.nucleus.protos import reference_pb2
  from third_party.nucleus.protos import variants_pb2
label_desc: Use image node_id 18 for calling a global function with example usage: expand(region, n_bp, contig_map) and returns: make_range