-
Notifications
You must be signed in to change notification settings - Fork 0
/
omg_interface.py
104 lines (92 loc) · 3.67 KB
/
omg_interface.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
from appscript import *
import networkx as nx
#by using omg edit->Copy as->Applescript menu item in omg, it is very easy to build up some template code
omg=app("OmniGraffle Professional 5")
canv=None
def setup_canvas():
global canv
if not omg.isrunning():
omg.activate()
if omg.documents()[0].path()!=None and omg.documents()[0].path().endswith("gstencil"):
d=app(u'OmniGraffle Professional 5').make(new=k.document)
canv=omg.windows()[0].canvas()
try:
canv=omg.windows()[0].canvas()
print "Drawing on ",canv.name(),omg.documents()[0].name()
except CommandError:
d=app(u'OmniGraffle Professional 5').make(new=k.document)
canv=d.canvas()[0]
def get_graphic(srcTerm):
try:
srcTerm.omg
except:
return srcTerm
if srcTerm.omg!=None:
try:
srcTerm.omg.canvas()
except CommandError:
srcTerm.omg=None
if srcTerm.omg==None:
srcTerm.omg=canv.make(at=app.windows[1].canvas.graphics.end, new=k.shape, with_properties={k.text: {k.text: srcTerm.name, k.alignment: k.center}, k.draws_shadow: False, k.url: "http://www.google.com/search?q=%s"%(srcTerm.name),})
srcTerm.omg.autosizing.set(k.full)
return srcTerm.omg
def add_activation(srcTerm,tgtTerm):
setup_canvas()
g1=get_graphic(srcTerm)
g2=get_graphic(tgtTerm)
lin=g1.connect(to=g2, with_properties={k.head_type: u'FilledArrow'})
lin.url.set("http://www.google.com/search?q=%s %s"%(srcTerm.name,tgtTerm.name))
def add_upregulation(srcTerm,tgtTerm):
setup_canvas()
g1=get_graphic(srcTerm)
g2=get_graphic(tgtTerm)
lin=g1.connect(to=g2, with_properties={k.head_type: u'FilledDoubleArrow'})
lin.url.set("http://www.google.com/search?q=%s %s"%(srcTerm.name,tgtTerm.name))
def add_binding(srcTerm,tgtTerm):
setup_canvas()
g1=get_graphic(srcTerm)
g2=get_graphic(tgtTerm)
lin=g1.connect(to=g2, with_properties={k.head_type: u'FilledCenterBall',k.head_scale:1.2})
lin.url.set("http://www.google.com/search?q=%s %s"%(srcTerm.name,tgtTerm.name))
def add_and_node(predecessors):
setup_canvas()
and_node=canv.make(at=app.windows[1].canvas.graphics.end, new=k.shape, with_properties={k.name:"Circle", k.draws_shadow: False,k.size:(14,14)})
for src in predecessors:
g=get_graphic(src)
g.connect(to=and_node)
return and_node
def add_inhibition(srcTerm,tgtTerm):
setup_canvas()
g1=get_graphic(srcTerm)
g2=get_graphic(tgtTerm)
g1.connect(to=g2, with_properties={k.head_type: u'NegativeControls'})
def layout():
setup_canvas()
canv.layout()
def draw_nx_graph(g):
omg_mappings={}
global canv
setup_canvas()
for e in g.edges_iter(data=True):
#I cannot get access to the data in predicates_with_uid
# pred=miner.predicates_with_uid(e[2]["uid"])[0]
# print "Adding",e
if e[0] not in omg_mappings:
omg_mappings[e[0]]=canv.make(at=canv.graphics.end, new=k.shape, with_properties={k.text: {k.text: e[0], k.alignment: k.center}, k.draws_shadow: False, k.url: "http://www.google.com/search?q=%s"%(e[0]),})
omg_mappings[e[0]].autosizing.set(k.full)
if e[1] not in omg_mappings:
omg_mappings[e[1]]=canv.make(at=canv.graphics.end, new=k.shape, with_properties={k.text: {k.text: e[1], k.alignment: k.center}, k.draws_shadow: False, k.url: "http://www.google.com/search?q=%s"%(e[1]),})
omg_mappings[e[1]].autosizing.set(k.full)
#relation type
# if type(pred) in [Activates, Binds, Complexes, Phosphorylates, RequiredToActivate, Upregulates]:
# head_type=u'FilledArrow'
# else:
# head_type=u'NegativeControls'
head_type="FilledArrow"
omg_mappings[e[0]].connect(to=omg_mappings[e[1]], with_properties={k.head_type: head_type})
if e[1].startswith("AND"):
omg_mappings[e[1]].text.set("")
omg_mappings[e[1]].name.set("Circle")
omg_mappings[e[1]].size.set((14,14))
omg_mappings[e[0]].autosizing.set(k.full)
layout()