-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhic_oe.py
53 lines (41 loc) · 909 Bytes
/
hic_oe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
def oe(mat):
n = len(mat)
tots = np.zeros(n-1)
counts = np.zeros(n-1)
for i in range(n):
for j in range(i):
observed = mat[i,j]
if observed != 0:
s = i - j
tots[s - 1] += observed
counts[s - 1] += 1
avgs = np.zeros(n-1)
for i, count in enumerate(counts):
if count != 0:
avgs[i] = tots[i]/count
oe_mat = np.zeros_like(mat)
for i in range(n):
for j in range(i):
observed = mat[i,j]
s = i - j
expected = avgs[s - 1]
if expected != 0:
oe_mat[i,j] = observed/expected
return oe_mat
def get_expected(mat):
n = len(mat)
tots = np.zeros(n-1)
counts = np.zeros(n-1)
for i in range(n):
for j in range(i):
observed = mat[i,j]
if observed != 0:
s = i - j
tots[s - 1] += observed
counts[s - 1] += 1
avgs = np.zeros(n-1)
for i, count in enumerate(counts):
if count != 0:
avgs[i] = tots[i]/count
return avgs