def FindMatch(matrix, seq1, x, seq2, y, options, max_advance=10, min_match=3):
    """advance on sequence2 from position y until you find a minimum match of
    min_match residues.

    returns the offset in y. If no match is found, an offset of 0 is returned.
    """

    # for z in range(0,10):
    # print seq1.asChar(x+z), seq2.asChar(y+z)

    min_match = min(seq1.getLength() - x, min_match)
    l2 = seq2.getLength()
    # get list of reference residues
    rr = []
    for xx in range(x, x + min_match):
        rr.append(seq1.asResidue(xx))

    max_advance = min(max_advance, l2 - y)
    for yy in range(y, y + max_advance):
        m = True
        for i in range(0, min_match):
            if matrix.getValue(rr[i], seq2.asResidue(yy + i)) < 0:
                m = False
                break
        if m:
            return yy - y

    return 0