def get_intervals(positions, window):
    """ find windows of genomic regions for getting variants within.

    This merges overlapping intervals
    """
    intervals = []
    for pos in sorted(positions):
        if intervals and pos - window < intervals[-1][1]:
            intervals[-1][1] = pos + window
        else:
            intervals.append([pos - window, pos + window])
    return intervals
