def matchby_comparison(iter1, iter2, matchfun1, matchfun2=None):

    if matchfun2 is None:
        matchfun2 = matchfun1
    groups1 = itertools.groupby(iter1, matchfun1)
    groups2 = itertools.groupby(iter2, matchfun2)
    key2, value2 = groups2.next()
    last_key1, last_key2 = key1, key2
    for key1, value1 in groups1:
        assert last_key1 < key1, "input needs to be sorted by keys in ascending order."
        last_key1 = key1
        while key1 > key2:
            last_key2 = key2
            key2, value2 = groups2.next()
            assert last_key2 < key2, "input needs to be sorted by keys in ascending order."
        if key1 < key2:
            continue
        yield(value1, value2)
return pairs of values from two streams that are matched by match 
dataset/ETHPy150Open CGATOxford/cgat/scripts/maq2psl.py/matchby_comparison