forked from st35/frustration-ODEs-modeling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkage_Methods.py
51 lines (46 loc) · 1.46 KB
/
Linkage_Methods.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
def Get_Clusters(inputnetworkid, updateindex, excludedids, numnodes):
import numpy as np
from scipy.spatial.distance import pdist
from scipy.cluster.hierarchy import linkage
newids = {}
newidsrev = {}
index = 0
for i in range(numnodes):
if i in excludedids:
continue
newids[i] = index
newidsrev[index] = i
index += 1
print(newidsrev)
D = []
index = 0
with open('steadystates/RUN_' + str(inputnetworkid) + '/network_' + str(updateindex) + '.log', 'r') as f:
for line in f:
l = line.strip().split(' ')
D.append([])
for i in range(1, len(l)):
if i - 1 not in excludedids:
D[index].append(float(l[i].strip()))
index += 1
if len(D) == 0 or len(D[0]) < 2:
return -1
M = np.transpose(np.array(D))
dist = pdist(M, metric = 'correlation')
L = linkage(dist)
with open('linkages/RUN_' + str(inputnetworkid) + '/linkage_' + str(updateindex) + '.log', 'w') as f:
for i in range(L.shape[0]):
if L[i][0] < M.shape[0] and L[i][1] < M.shape[0]:
f.write(str(newidsrev[int(L[i][0])] + 1) + '\t' + str(newidsrev[int(L[i][1])] + 1) + '\n')
return 1
if __name__ == "__main__":
exclnodes = []
with open('Excluded.log', 'r') as f:
for line in f:
exclnodes.append(line.strip())
excludedids = []
with open('RACIPE_Output/RUN_' + str(inputnetworkid) + '/linkage_' + str(updateindex) + '.log', 'r') as f:
for line in f:
l = line.strip().split('\t')
if l[0] in exclnodes:
excludedids.append(int(l[1].strip()))
Get_Clusters(0, 0, [], 26)