def intervalTrees(reffh, scoreType=int, verbose=False):
if type(reffh).__name__ == "<STR_LIT:str>":<EOL><INDENT>fh = open(reffh)<EOL><DEDENT>else:<EOL><INDENT>fh = reffh<EOL><DEDENT>elements = {}<EOL>if verbose and fh != sys.stdin:<EOL><INDENT>totalLines = linesInFile(fh.name)<EOL>pind = ProgressIndicator(totalToDo=totalLines,<EOL>messagePrefix="<STR_LIT>",<EOL>messageSuffix="<STR_LIT>" + fh.name)<EOL><DEDENT>for element in BEDIterator(fh, scoreType=scoreType, verbose=verbose):<EOL><INDENT>if element.chrom not in elements:<EOL><INDENT>elements[element.chrom] = []<EOL><DEDENT>elements[element.chrom].append(element)<EOL>if verbose and fh != sys.stdin:<EOL><INDENT>pind.done += <NUM_LIT:1><EOL>pind.showProgress()<EOL><DEDENT><DEDENT>trees = {}<EOL>if verbose:<EOL><INDENT>totalLines = len(elements)<EOL>pind = ProgressIndicator(totalToDo=totalLines,<EOL>messagePrefix="<STR_LIT>",<EOL>messageSuffix="<STR_LIT>")<EOL><DEDENT>for chrom in elements:<EOL><INDENT>trees[chrom] = IntervalTree(elements[chrom], openEnded=True)<EOL>if verbose:<EOL><INDENT>pind.done += <NUM_LIT:1><EOL>pind.showProgress()<EOL><DEDENT><DEDENT>return trees<EOL>
Build a dictionary of interval trees indexed by chrom from a BED stream or
file

:param reffh: This can be either a string, or a stream-like object. In the
              former case, it is treated as a filename. The format of the
              file/stream must be BED.
:param scoreType: The data type for scores (the fifth column) in the BED
                  file.
:param verbose: output progress messages to sys.stderr if True