build a dictionary, indexed by chrom name, of interval trees for each chrom.

  :param inElements: list of genomic intervals. Members of the list must have
                     chrom, start and end fields; no other restrictions.
  :param verbose: output progress messages to sys.stderr if True

def intervalTreesFromList(inElements, verbose=False, openEnded=False):
  """
  build a dictionary, indexed by chrom name, of interval trees for each chrom.

  :param inElements: list of genomic intervals. Members of the list must have
                     chrom, start and end fields; no other restrictions.
  :param verbose: output progress messages to sys.stderr if True
  """
  elements = {}
  if verbose:
    totalLines = len(inElements)
    pind = ProgressIndicator(totalToDo=totalLines,
                             messagePrefix="completed",
                             messageSuffix="of parsing")

  for element in inElements:
    if element.chrom not in elements:
      elements[element.chrom] = []
    elements[element.chrom].append(element)
    if verbose:
      pind.done += 1
      pind.showProgress()

  # create an interval tree for each list
  trees = {}
  if verbose:
    totalLines = len(elements)
    pind = ProgressIndicator(totalToDo=totalLines,
                             messagePrefix="completed",
                             messageSuffix="of making interval trees")
  for chrom in elements:
    trees[chrom] = IntervalTree(elements[chrom], openEnded)
    if verbose:
      pind.done += 1
      pind.showProgress()

  return trees