code: def sorted_ranges(ranges, contigs=None):
      """Sorts ranges by reference_name, start, and end.
  
      Args:
        ranges: Iterable of nucleus.genomics.v1.Range protos that we want to sort.
        contigs: None or an iterable of ContigInfo protos. If not None, we will use
          the order of the contigs (as defined by their pos_in_fasta field values)
          to sort the Ranges on different contigs with respect to each other.
  
      Returns:
        A newly allocated list of nucleus.genomics.v1.Range protos.
      """
      if contigs:
          contig_map = contigs_dict(contigs)
  
          def to_key(range_):
              pos = contig_map[range_.reference_name].pos_in_fasta
              return pos, range_.start, range_.end
  
      else:
          to_key = as_tuple
  
      return sorted(ranges, key=to_key)
  
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 14 for calling a global function with example usage: sorted_ranges(ranges, contigs) and returns: sorted, pos,  range_,  range_