-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfer.py
executable file
·152 lines (125 loc) · 3.43 KB
/
infer.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import networkx as nx
import importlib
import gprops
#import reduction
def create_node(G,node,node_list):
G.add_node(node)
G.node[node]['label']=node
node_list.append(node)
return None
fname = 'examples/inference_test.txt'
#outf = 'examples/inferred_ABA_network.graphml'
G = nx.DiGraph()
node_list = []
f = open(fname,'r+')
lines = f.readlines()
#l = len(lines)
#f.seek(0)
for line in lines:
#print line
words = line.split('\t')
if words[0][0] is '#':
continue
source = words[0]
target = words[1]
etype = words[2].strip()
if source not in node_list:
create_node(G,source,node_list)
if target not in node_list:
create_node(G,target,node_list)
G.add_edge(source,target,edge_attr = etype)
f.close()
gprops.set_edge_props(G)
gprops.lone_reg(G)
reduction.edge_red(G)
gprops.set_edge_props(G)
#nx.write_graphml(G,outf)
#print the Boolean rules that have no incompatibility
#create compatibility dictionary
comp = {'s':['s', 'ni'], 'si':['si', 'n'], 'n':['n', 'si'], 'ni':['ni', 's']}
gprops.set_edge_type(G)
for node in G.nodes():
regs = list(G.predecessors(node))
if len(regs)==0:
print str(G.node[node]['label']), 'is a source node'
continue
if len(regs)==1:
print str(G.node[node]['label'])+'* = '+str(G.node[regs[0]]['label'])
else:
dom = G[regs[0]][node]['edge_attr']
if dom[-1]=='i':
rule_so_far = 'not '+str(G.node[regs[0]]['label'])
else:
rule_so_far = str(G.node[regs[0]]['label'])
rule_opp = ''
compatible = True
for regulator in regs[1:]:
logic = G[regulator][node]['edge_attr']
#compatible = True
if logic not in comp[dom]:
compatible = False
if rule_opp:
if dom[0]=='s':
rule_opp+=' and '
else:
rule_opp+=' or '
if logic[-1]=='i':
rule_opp+='not '
rule_opp+=str(G.node[regulator]['label'])
#break
else:
if logic[-1]=='i':
if logic[0]=='s':
rule_so_far+=(' and not '+str(G.node[regulator]['label']))
else:
rule_so_far+=(' or not '+str(G.node[regulator]['label']))
else:
if logic[0]=='s':
rule_so_far+=(' or '+str(G.node[regulator]['label']))
else:
rule_so_far+=(' and '+str(G.node[regulator]['label']))
if compatible:
print str(G.node[node]['label'])+'* = '+rule_so_far
else:
print 'Regulators of', str(G.node[node]['label']), 'are incompatible.',
#print 'One set of regulators are:', rule_so_far
#print 'Second set of regulators are:', rule_opp
if dom=='s' or dom=='ni':
#rule_so_far is OR type
final_rule1 = '('+rule_opp+')'+' or '+rule_so_far
final_rule2 = rule_opp+' and '+'('+rule_so_far+')'
else:
final_rule1 = '('+rule_opp+')'+' and '+rule_so_far
final_rule2 = rule_opp+' or '+'('+rule_so_far+')'
print 'Rules as per the two templates are: \n1.',final_rule1, '\n2.', final_rule2
print 'Done creating all Boolean rules'
'''
critical = ['Ca2+', 'ROS', 'OST1', 'PA', 'ABI1']
sigs = []
for node in G.nodes():
parents = G.predecessors(node)
if len(parents)<1:
sigs.append(node)
print 'Signals are:', sigs
critical = critical + sigs
critical = G.nodes()
s = 'M'
for i in range(10):
critical.remove(s+str(i+1))
print 'Critical is:', critical
gprops.lone_reg(G)
reduction.node_red(G, critical)
gprops.set_edge_props(G)
gprops.lone_reg(G)
reduction.edge_red(G)
gprops.set_edge_props(G)
'''
#nx.write_graphml(G,outf)
'''
gprops.update_graph(G, 'MRP5','ON')
gprops.set_edge_props(G)
gprops.lone_reg(G)
reduction.edge_red(G)
gprops.set_edge_props(G)
nx.write_graphml(G,outf)
'''