def collapseRegions(s, stranded=False, names=False, verbose=False):
  """
  Get the union of a set of genomic intervals.

  given a list of genomic intervals with chromosome, start and end field,
  collapse into a set of non-overlapping intervals. Intervals must be sorted by
  chromosome and then start coordinate.

  :note: O(n) time, O(n) space
  :return:  list of intervals that define the collapsed regions. Note that
            these are all new objects, no existing object from s is returned
            or altered. Returned regions will all have name "X" and score 0
  :param s:        list of genomic regions to collapse
  :param stranded: if True, regions on positive and negative strands are
                   collapsed separately. Otherwise, strand is ignored and all
                   output regions are on positive strand.
  :raise GenomicIntervalError: if the input regions are not correctly sorted
                               (chromosome then start)
  """
  if stranded:
    return (__collapse_stranded(s, set("+"), names, verbose) +
            __collapse_stranded(s, set("-"), names, verbose))
  else:
    return __collapse_stranded(s, set(["+", "-"]), names, verbose)
Get the union of a set of genomic intervals.

  given a list of genomic intervals with chromosome, start and end field,
  collapse into a set of non-overlapping intervals. Intervals must be sorted by
  chromosome and then start coordinate.

  :note: O(n) time, O(n) space
  :return:  list of intervals that define the collapsed regions. Note that
            these are all new objects, no existing object from s is returned
            or altered. Returned regions will all have name "X" and score 0
  :param s:        list of genomic regions to collapse
  :param stranded: if True, regions on positive and negative strands are
                   collapsed separately. Otherwise, strand is ignored and all
                   output regions are on positive strand.
  :raise GenomicIntervalError: if the input regions are not correctly sorted
                               (chromosome then start)