def BEDIterator(filehandle, sortedby=None, verbose=False, scoreType=int,<EOL>dropAfter=None):
chromsSeen = set()<EOL>prev = None<EOL>if type(filehandle).__name__ == "<STR_LIT:str>":<EOL><INDENT>filehandle = open(filehandle)<EOL><DEDENT>if verbose:<EOL><INDENT>try:<EOL><INDENT>pind = ProgressIndicator(totalToDo=os.path.getsize(filehandle.name),<EOL>messagePrefix="<STR_LIT>",<EOL>messageSuffix="<STR_LIT>" +<EOL>filehandle.name)<EOL><DEDENT>except (AttributeError, OSError) as e:<EOL><INDENT>sys.stderr.write("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL>verbose = False<EOL><DEDENT><DEDENT>for line in filehandle:<EOL><INDENT>if verbose:<EOL><INDENT>pind.done = filehandle.tell()<EOL>pind.showProgress()<EOL><DEDENT>if line.strip() == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>e = parseBEDString(line, scoreType, dropAfter=dropAfter)<EOL><DEDENT>except GenomicIntervalError as e:<EOL><INDENT>raise BEDError(str(e) + "<STR_LIT>" + line)<EOL><DEDENT>if ((sortedby == ITERATOR_SORTED_NAME and prev is not None) and<EOL>(prev.name > e.name)):<EOL><INDENT>raise BEDError("<STR_LIT>" + filehandle.name +<EOL>"<STR_LIT>" +<EOL>"<STR_LIT>" + e.name + "<STR_LIT>" +<EOL>prev.name)<EOL><DEDENT>if prev is None:<EOL><INDENT>chromsSeen.add(e.chrom)<EOL><DEDENT>if prev is not None and sortedby is not None and e.chrom == prev.chrom:<EOL><INDENT>if sortedby == ITERATOR_SORTED_START and prev.start > e.start:<EOL><INDENT>raise BEDError("<STR_LIT>" + filehandle.name +<EOL>"<STR_LIT>" +<EOL>str(prev) + "<STR_LIT>" + str(e))<EOL><DEDENT>if sortedby == ITERATOR_SORTED_END and prev.end > e.end:<EOL><INDENT>raise BEDError("<STR_LIT>" + filehandle.name +<EOL>"<STR_LIT>" +<EOL>str(prev) + "<STR_LIT>" + str(e))<EOL><DEDENT><DEDENT>if prev is not None and prev.chrom != e.chrom:<EOL><INDENT>if (sortedby == ITERATOR_SORTED_START or<EOL>sortedby == ITERATOR_SORTED_END or<EOL>sortedby == ITERATOR_SORTED_CHROM) and(e.chrom in chromsSeen or prev.chrom > e.chrom):<EOL><INDENT>try:<EOL><INDENT>e_fn = filehandle.name<EOL><DEDENT>except AttributeError:<EOL><INDENT>e_fn = "<STR_LIT>"<EOL><DEDENT>raise BEDError("<STR_LIT>" + e_fn + "<STR_LIT>")<EOL><DEDENT>chromsSeen.add(e.chrom)<EOL><DEDENT>yield e<EOL>prev = e<EOL><DEDENT>
Get an iterator for a BED file

:param filehandle: 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 sortedby: if None, order is not checked.
                 if == ITERATOR_SORTED_START, elements in file must
                 be sorted by chrom and start index (an exception
                 is raised if they are not)
                 if == ITERATOR_SORTED_END, element must be sorted
                 by chrom and end index.
:param verbose: if True, output additional progress messages to stderr
:param scoreType: The data type for scores (the fifth column) in the BED
                  file.
:param dropAfter: an int indicating that any fields after and including this
                  field should be ignored as they don't conform to the BED
                  format. By default, None, meaning we use all fields. Index
                  from zero.
:return: iterator where subsequent calls to next() yield the next BED
         element in the stream as a GenomicInterval object.