def _build_trees_by_chrom(blocks, verbose=False):
  """
  Construct set of interval trees from an iterable of genome alignment blocks.

  :return: a dictionary indexed by chromosome name where each entry is an
           interval tree for that chromosome.
  """
  if verbose:
    sys.stderr.write("separating blocks by chromosome... ")
  by_chrom = {}
  for b in blocks:
    if b.chrom not in by_chrom:
      by_chrom[b.chrom] = []
    by_chrom[b.chrom].append(b)
  if verbose:
    sys.stderr.write("done\n")

  if verbose:
    sys.stderr.write("building interval trees by chromosome... ")
  res = {}
  for c in by_chrom:
    res[c] = IntervalTree(by_chrom[c], openEnded=True)
  if verbose:
    sys.stderr.write("done\n")

  return res
Construct set of interval trees from an iterable of genome alignment blocks.

  :return: a dictionary indexed by chromosome name where each entry is an
           interval tree for that chromosome.