code: def locate_key(self, chrom, pos=None):
          
  
          if pos is None:
              # we just want the region for a chromosome
              if chrom in self.chrom_ranges:
                  # return previously cached result
                  return self.chrom_ranges[chrom]
              else:
                  loc_chrom = np.nonzero(self.chrom == chrom)[0]
                  if len(loc_chrom) == 0:
                      raise KeyError(chrom)
                  slice_chrom = slice(min(loc_chrom), max(loc_chrom) + 1)
                  # cache the result
                  self.chrom_ranges[chrom] = slice_chrom
                  return slice_chrom
  
          else:
              slice_chrom = self.locate_key(chrom)
              pos_chrom = SortedIndex(self.pos[slice_chrom])
              try:
                  idx_within_chrom = pos_chrom.locate_key(pos)
              except KeyError:
                  raise KeyError(chrom, pos)
              if isinstance(idx_within_chrom, slice):
                  return slice(slice_chrom.start + idx_within_chrom.start,
                               slice_chrom.start + idx_within_chrom.stop)
              else:
                  return slice_chrom.start + idx_within_chrom
docs: Get index location for the requested key.
  
          Parameters
          ----------
          chrom : object
              Chromosome or contig.
          pos : int, optional
              Position within chromosome or contig.
  
          Returns
          -------
          loc : int or slice
              Location of requested key (will be slice if there are duplicate
              entries).
  
          Examples
          --------
  
          >>> import allel
          >>> chrom = ['chr2', 'chr2', 'chr1', 'chr1', 'chr1', 'chr3']
          >>> pos = [1, 4, 2, 5, 5, 3]
          >>> idx = allel.ChromPosIndex(chrom, pos)
          >>> idx.locate_key('chr1')
          slice(2, 5, None)
          >>> idx.locate_key('chr2', 4)
          1
          >>> idx.locate_key('chr1', 5)
          slice(3, 5, None)
          >>> try:
          ...     idx.locate_key('chr3', 4)
          ... except KeyError as e:
          ...     print(e)
          ...
          ('chr3', 4)