def BEDUniqueIterator(fh1, fh2, verbose=False, best=False, dropAfter=None):
def next_item(iterator):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return next(iterator)<EOL><DEDENT>except StopIteration:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>bit1 = BEDIterator(fh1, sortedby=ITERATOR_SORTED_NAME, verbose=verbose,<EOL>dropAfter=dropAfter)<EOL>bit2 = BEDIterator(fh2, sortedby=ITERATOR_SORTED_NAME, verbose=verbose,<EOL>dropAfter=dropAfter)<EOL>bf1, bf2 = None, None<EOL>bf1_Q, bf2_Q = Queue(), Queue()<EOL>while True:<EOL><INDENT>if bf1 is None:<EOL><INDENT>bf1 = next_item(bit1)<EOL><DEDENT>if bf2 is None:<EOL><INDENT>bf2 = next_item(bit2)<EOL><DEDENT>if bf1 is not None and (bf2 is None or bf1.name < bf2.name):<EOL><INDENT>bf1_Q.put(bf1)<EOL>bf1 = next_item(bit1)<EOL><DEDENT>if bf2 is not None and (bf1 is None or bf2.name < bf1.name):<EOL><INDENT>bf2_Q.put(bf2)<EOL>bf2 = next_item(bit2)<EOL><DEDENT>if bf1 is not None and bf2 is not None and bf1.name == bf2.name:<EOL><INDENT>if best and bf1.score < bf2.score:<EOL><INDENT>bf1_Q.put(bf1)<EOL><DEDENT>if best and bf2.score < bf1.score:<EOL><INDENT>bf2_Q.put(bf2)<EOL><DEDENT>bf1 = next_item(bit1)<EOL>bf2 = next_item(bit2)<EOL><DEDENT>y1, y2 = None, None<EOL>if not bf1_Q.empty():<EOL><INDENT>y1 = bf1_Q.get()<EOL><DEDENT>if not bf2_Q.empty():<EOL><INDENT>y2 = bf2_Q.get()<EOL><DEDENT>yield (y1, y2)<EOL>if bf1_Q.empty() and bf2_Q.empty() and bf1 is None and bf2 is None:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
@summary: returns an iterator which will yield pairs of reads (r1, r2)
          for which r1 does not appear in fh2 and r2 does not appear in
          fh1. Either r1 or r2 may be None (but not both) if one of
          file1 or file2 has fewer unique entries than the other.
          reads are compared by name, other attributes are ignored
@param fh1: BED formated stream, must be sorted by name
@param fh2: BED formated stream, must be sorted by name
@param verbose: output additional progress messages to stderr if this
                is True
@param best: If True, when encountering two reads with the same name,
             we'll output the one with the better (smaller) score, unless
             they both get the same score, then we'll skip them
@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.