def domainogram(M, window=None, circ=False, extrapolate=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>if circ:<EOL><INDENT>d = [(np.sum(M[-i + window:, -i + window:]) +<EOL>np.sum(M[:i - window + <NUM_LIT:1>, :i - window + <NUM_LIT:1>])<EOL>for i in range(window))]<EOL><DEDENT>elif extrapolate:<EOL><INDENT>d = [(np.sum(M[<NUM_LIT:0>:<NUM_LIT:2> * i + <NUM_LIT:1>, <NUM_LIT:0>:<NUM_LIT:2> * i + <NUM_LIT:1>]) *<EOL>((<NUM_LIT:2> * window + <NUM_LIT:1>) ** <NUM_LIT>) / ((<NUM_LIT:2> * i + <NUM_LIT:1>)**<NUM_LIT>))<EOL>for i in range(window)]<EOL><DEDENT>else:<EOL><INDENT>d = []<EOL><DEDENT>d += [np.sum(M[i - window:i + window + <NUM_LIT:1>, i - window:i + window + <NUM_LIT:1>])<EOL>for i in range(window, n - window)]<EOL>if circ:<EOL><INDENT>d += [M[i:, i:].sum() + M[:n - i, n - i].sum()<EOL>for i in range(n - window, n)]<EOL><DEDENT>elif extrapolate:<EOL><INDENT>d += [M[i - window:, i - window:].sum() * ((<NUM_LIT:2> * window + <NUM_LIT:1>)**<NUM_LIT>) /<EOL>((<NUM_LIT:2> * (n - i) + <NUM_LIT:1>)**<NUM_LIT>) for i in range(n - window, n)]<EOL><DEDENT>return np.array(d)<EOL>
From a symmetrical matrix M of size n, return a vector d whose each
    component d[i] is the total sum of a square of 2*window+1 size centered on
    the i-th main diagonal element. Edge elements may be extrapolated based on
    the square size reduction (i.e. for window = 4, the first component will be
    equal to the first diagonal pixel multiplied by 81, the second one will be
    equal to the first 2x2 square on the diagonal multiplied by 81/4, etc.),
    except in the case of circular genomes. If they aren't, d will be of size
    n - 2*(window-1) instead of n.