def directional(M, window=None, circ=False, extrapolate=True, log=True):
<EOL>if not type(M) is np.ndarray:<EOL><INDENT>M = np.array(M)<EOL><DEDENT>if M.shape[<NUM_LIT:0>] != M.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>n = min(M.shape)<EOL><DEDENT>except AttributeError:<EOL><INDENT>n = M.size<EOL><DEDENT>if window is None:<EOL><INDENT>window = max(n // <NUM_LIT:100>, <NUM_LIT:5>)<EOL><DEDENT>if window >= n:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>from scipy.stats import ttest_rel<EOL><DEDENT>except ImportError as e:<EOL><INDENT>print("<STR_LIT>")<EOL>print(str(e))<EOL>raise<EOL><DEDENT>if log:<EOL><INDENT>N = np.zeros((n, n))<EOL>N[M > <NUM_LIT:0>] = np.log(M[M > <NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>N = M<EOL><DEDENT>if circ:<EOL><INDENT>d = [ttest_rel(np.array(list(N[i, i - window:]) + list(N[i, :i])),<EOL>N[i, i:i + window])[<NUM_LIT:0>] for i in range(window)]<EOL><DEDENT>elif extrapolate:<EOL><INDENT>d = [ttest_rel(N[i, <NUM_LIT:0>:i], N[i, i:<NUM_LIT:2> * i])[<NUM_LIT:0>] for i in range(window)]<EOL><DEDENT>else:<EOL><INDENT>d = []<EOL><DEDENT>d += [ttest_rel(N[i, i - window:i], N[i, i:i + window])[<NUM_LIT:0>]<EOL>for i in range(window, n - window)]<EOL>if circ:<EOL><INDENT>d += [ttest_rel(N[i, i - window:i],<EOL>np.array((list(N[i, :i - n + window]) +<EOL>list(N[i, i:]))))[<NUM_LIT:0>]<EOL>for i in range(n - window, n)]<EOL><DEDENT>elif extrapolate:<EOL><INDENT>d += [ttest_rel(N[i, i - window:i],<EOL>(np.array(list(N[i, i:]) +<EOL>list(N[i, :window - (n - i)]))))[<NUM_LIT:0>]<EOL>for i in range(n - window, n)]<EOL><DEDENT>return d<EOL>
From a symmetrical matrix M of size n, return a vector d whose each
    component d[i] is a T-test of two samples represented by vectors of size
    window on either side of the i-th pixel on the diagonal. Edge elements may
    be extrapolated based on the vector size reduction, except in the case of
    circular genomes. If they aren't, d will be of size n - 2*(window-1)
    instead of n.