import statistics


def get_peak_region(pos, sc_list,
                    reverse=False,
                    set_mean=False):
    """
    For a list of scores get peak region around score position which
    lies above the mean score. Return 0-based start, 1-based end.

    reverse:
        Instead of region above, get region below the mean. Set this True
        if negative scores indicate stronger signal.
    set_mean:
        Instead of using mean of scores list, use provided mean to get
        the peak region.

    >>> sc_list = [1,2,3,2,0.5,1]
    >>> get_peak_region(2, sc_list, set_mean=1)
    (0, 4)
    >>> sc_list = [-1,-2,-3,-2,-2,-0.5, 0]
    >>> get_peak_region(2, sc_list, reverse=True, set_mean=-1)
    (0, 5)
    >>> sc_list = [-5,-2,-3,-2,-4,-0.5, 0]
    >>> get_peak_region(0, sc_list, reverse=True, set_mean=-4)
    (0, 1)
    >>> sc_list = [5]
    >>> get_peak_region(0, sc_list, set_mean=5)
    (0, 1)


    """
    assert sc_list, "sc_list empty"
    assert len(sc_list) > pos, "len(sc_list) <= pos, but needs to be at least pos+1"

    # Mean score.
    mean_sc = statistics.mean(sc_list)
    if set_mean:
        mean_sc = set_mean
    # Init start + end of > mean region.
    s = pos
    e = pos

    # Get start + end positions above (or below if reverse) mean.
    for i in reversed(range(pos)):
        if reverse:
            if sc_list[i] <= mean_sc:
                s = i
            else:
                break
        else:
            if sc_list[i] >= mean_sc:
                s = i
            else:
                break

    for i in range(pos+1, len(sc_list)):
        if reverse:
            if sc_list[i] <= mean_sc:
                e = i
            else:
                break
        else:
            if sc_list[i] >= mean_sc:
                e = i
            else:
                break

    # Make end 1-based.
    e = e + 1

    return s, e