-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhello_indra.py
62 lines (51 loc) · 1.76 KB
/
hello_indra.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
import numpy as np
from pysb.integrate import Solver
from pysb.export import export
from matplotlib import pyplot as plt
from indra.sources import biopax
from indra.sources import bel, trips
from indra.util import plot_formatting as pf
from indra.assemblers.pysb import PysbAssembler
def plot_result(model, sol):
pf.set_fig_params()
plt.ion()
plt.figure(figsize=(1, 1), dpi=300)
species_names = [str(s) for s in model.species]
plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='u', Y187='u')")],
'b', label='MAPK1.uu')
plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='p', Y187='u')")] +
sol.y[:, species_names.index("MAPK1(T185='u', Y187='p')")],
'g', label='MAPK1.p')
plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='p', Y187='p')")],
'r', label='MAPK1.pp')
plt.xlabel('Time')
plt.ylabel('Amount')
plt.legend(loc='upper right', fontsize=4)
plt.xticks([])
plt.yticks([])
pf.format_axis(plt.gca())
def export_hello(model, formats):
for f in formats:
model_export = export(model, f)
extension = (f if f != 'pysb_flat' else 'py')
fname = 'hello_indra_model.%s' % extension
with open(fname, 'wb') as fh:
fh.write(model_export)
# User defines text
text = 'MEK1 phosphorylates ERK2 on threonine 185 and tyrosine 187.'
# Process text using TRIPS processor
tp = trips.process_text(text)
# Get the list of extracted Statements
stmts = tp.statements
# Assemble a PySB model
pa = PysbAssembler()
pa.add_statements(stmts)
pa.make_model()
# Run simulation
t = np.linspace(0, 300)
sol = Solver(pa.model, t)
sol.run()
# Plot the result
plot_result(pa.model, sol)
# Export model
export_hello(pa.model, ['sbml', 'bngl', 'kappa', 'pysb_flat'])