Skip to content

Commit 1c04a48

Browse files
committed
Added more models. The previous commit did not work
1 parent 9c18cf6 commit 1c04a48

16 files changed

+613
-2
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ text_script.py
1515
minority_consensus_event_figures
1616
linkedin_model.py
1717
isolate_test.py
18-
docs
1918
mobspy_jounal_models
2019
parameter_problem.py
2120
plot_config_donor.json
@@ -26,4 +25,5 @@ testing_tight_layout.png
2625
__pycache__/
2726
test_plot_images/*
2827
!test_plot_images/read_me.txt
29-
!docs/example_models/jounal_models/*
28+
docs/*
29+
!docs/example_models/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from mobspy import *
2+
3+
A, B, C, D = BaseSpecies()
4+
5+
A >> 2*B [3]
6+
B >> C + D [1.4]
7+
8+
S = Simulation(A | B | C | D)
9+
print(S.compile())
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from mobspy import *
2+
3+
Promoter, Start_Positions, Tet, Mortal = BaseSpecies()
4+
Promoter.inactive, Promoter.active
5+
Ribo, RNA_Poly = New(Start_Positions)
6+
P2, Ptet = New(Promoter)
7+
Mrna_P2, Mrna_Ptet, GFP, RFP, CFP, GFP_F_RFP = New(Mortal)
8+
9+
# Death here does not consider a compound for degradation.
10+
Mortal >> Zero [1]
11+
12+
# Promoter activation - only Ptet is activated. P2 is always active
13+
Rev[Ptet.inactive + Tet >> Ptet.active][1, 1]
14+
15+
# Read expresses the reading of RNA and DNA - both transcription and translation
16+
# For translation the RNA Polymerase is the reader, for protein it is the Ribossome
17+
def Read(Pro, R, strand):
18+
sp = 'started_' + strand[0][0] # sp stands for start position
19+
Start_Positions.c(sp)
20+
rate = [lambda r1, r2: 2 if r1.active else 1, 1]
21+
# From free position to bounded to a site
22+
Rev[Pro + R.c('free_' + str(R)) >> Pro + R.c(sp).c('at_' + strand[0][0])][rate]
23+
next_location = strand[1:]
24+
# Movement of the reader
25+
for (location, Product), (next_l, _) in zip(strand, next_location):
26+
R.c(sp).c('at_' + location) >> R.c(sp).c('at_' + next_l) + Product [1]
27+
# Remove reader from final location
28+
R.c(sp).c('at_' + next_location[-1][0]) >> R.c(sp).c('free_' + str(R)) [1]
29+
30+
# Zero produces nothing
31+
Read(Ptet, RNA_Poly, [('ptet_dna', Mrna_Ptet), ('ptet_end', Zero)])
32+
Read(P2, RNA_Poly, [('p2_dna', Mrna_P2), ('p2_end', Zero)])
33+
Read(Mrna_Ptet, Ribo, [('gfp', GFP), ('rfp', GFP_F_RFP), ('rfp_end', Zero)])
34+
Read(Mrna_P2, Ribo, [('cfp', CFP), ('cfp_end', Zero)])
35+
Read(Mrna_Ptet, Ribo, [('rfp', RFP), ('rfp_end', Zero)])
36+
37+
# P2 is set to active as it is a constitutive promoter
38+
model = set_counts({RNA_Poly: 100, Ribo: 100, GFP: 0, RFP: 0, CFP: 0, Ptet: 1, P2.active: 1,
39+
Tet: 100, Mrna_Ptet: 0, Mrna_P2: 0, GFP_F_RFP: 0})
40+
S = Simulation(model)
41+
print(S.compile())
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from mobspy import *
2+
3+
R0, L0, A0, kon, koff, kAon, kAoff, kAp, kAdp = ModelParameters(100, 500, 100, 0.01,
4+
0.1, 0.01, 0.1, 0.01, 0.1)
5+
6+
r_link = BaseSpecies()
7+
r_link.r_0, r_link.r_1
8+
R, L, A = New(r_link)
9+
10+
R.r_0 + L.r_0 >> R.r_1 + L.r_1 [kon, koff]
11+
12+
R.a_0 + A.r_0 >> R.a_1 + A.r_1 [kAon, kAoff]
13+
14+
(R.a_1+ L + A.n_p).r_1 >> (R.a_1 + L + A.y_p).r_1 [lambda R: kAp*R**3]
15+
16+
A.y_p >> A.n_p [kAdp]
17+
18+
R(R0), L(L0), A(A0)
19+
S = Simulation(R, L, A)
20+
print(S.compile())
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
begin parameters
2+
R0 100
3+
L0 500
4+
A0 100
5+
kon 0.01
6+
koff 0.1
7+
kAon 0.01
8+
kAoff 0.1
9+
kAp 0.01
10+
kAdp 0.1
11+
end parameters
12+
13+
begin molecule types
14+
R(l,a)
15+
L(r)
16+
A(r,Y~U~P)
17+
end molecule types
18+
19+
begin seed species
20+
R(l,a) R0
21+
L(r) L0
22+
A(r,Y~U) A0
23+
end seed species
24+
25+
begin reaction rules
26+
R(l) + L(r) <-> R(l!1).L(r!1) kon,koff
27+
R(a) + A(r) <-> R(a!1).A(r!1) kAon,kAoff
28+
L().R().A(Y~U) -> L().R().A(Y~P) kAp
29+
A(Y~P) -> A(Y~U) kAdp
30+
end reaction rules
31+
32+
begin observables
33+
Molecules A_P A(Y~P)
34+
Molecules A_unbound_P A(r,Y~P)
35+
Molecules A_bound_P A(r!+,Y~P)
36+
Molecules RLA_P R().L().A(Y~P)
37+
end observables
38+
39+
generate_network();
40+
writeSBML();
41+
simulate_ode({t_end=>50,n_steps=>20});
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from mobspy import *
2+
import os
3+
4+
# Conversion taking to much time - why?
5+
6+
Dummy, Dilutable, Promoter, TTR, Phosphorable = BaseSpecies()
7+
TF, Reporter = New(Dilutable)
8+
TtrR, TtrS = New(Phosphorable)
9+
Cro, CI = New(TF)
10+
Pcro, PcI = New(Promoter)
11+
Promoter.bound, Promoter.unbound, Phosphorable.dephospho, Phosphorable.phospho
12+
13+
# TtrS triggers the state transition, TTR indicates the presence of gut inflammation
14+
TtrS.dephospho + TTR >> TtrS.phospho + TTR [1/u.min]
15+
TtrS.phospho + TtrR.dephospho >> TtrR.phospho + TtrS.dephospho [1/u.min]
16+
TtrR.phospho >> TtrR.dephospho [5*1e-3*1/u.second]
17+
TtrR.phospho >> Cro + TtrR.phospho [50*0.02*1/u.min]
18+
19+
# Dummy represents the introduction of a constant flow of CI in the system
20+
Dummy >> CI + Dummy [30*0.02*1/u.min]
21+
22+
# Dilution and degradation
23+
Dilutable >> Zero [0.02/u.min]
24+
TF >> Zero [lambda r1: 0 if r1.is_a(CI) else 1.6e-2*1/u.min]
25+
26+
def Expression(P, Pdt, rate_expression, rate_leaky):
27+
P >> P + Pdt [lambda r1: rate_expression if r1.unbound else rate_leaky]
28+
29+
def Repression (Prom, Rep, rate_binding, rate_unbinding):
30+
Prom.unbound + 2*Rep >> Prom.bound [rate_binding]
31+
Prom.bound >> Prom.unbound + 2*Rep [rate_unbinding]
32+
33+
# Pcro produces Cro, and PcI produces CI
34+
Expression(Pcro, Cro, 5/u.min, 0.05/u.min), Expression(PcI, CI, 4.25/u.min, 0.05/u.min)
35+
# Cro represses Pcro, and cI represses PcI
36+
Repression(Pcro, CI, 1, 50**2), Repression(PcI, Cro, 1, 40**2)
37+
38+
model = set_counts({Pcro: 1, PcI: 1, Cro: 0, CI: 10,
39+
Reporter: 0, TtrR: 1, TtrS: 1, TTR: 0, Dummy: 0})
40+
S = Simulation(model)
41+
S.duration = 160*u.hour
42+
43+
# Event implementation
44+
with S.event_time(25*u.hour):
45+
TTR(1)
46+
with S.event_time(60*u.hour):
47+
TTR(0)
48+
with S.event_time(90*u.hour):
49+
Dummy(1)
50+
with S.event_time(130*u.hour):
51+
Dummy(0)
52+
53+
S.plot_data = False
54+
S.unit_x, S.unit_y = u.hour, 1/u.ml
55+
S.step_size, S.a_tol = 0.01*u.hour, 1e-16
56+
S.plot_config.title, S.plot_config.title_fontsize = 'Toggle Switch', 16
57+
S.plot_config.figsize = (6.5, 4)
58+
S.plot_config.vertical_lines = [25, 60, 90, 130]
59+
S.plot_config.ylabel = r"Conc. (mL$^{-1}$)"
60+
S.plot_config.save_to = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + \
61+
'/images/Toggle_Switch/Toggle_Switch.pdf'
62+
S.run()
63+
S.plot(CI, Cro)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from mobspy import *
2+
3+
if __name__ == '__main__':
4+
5+
"""
6+
This is the Tree model from the paper
7+
We have a population of Trees
8+
The Trees can die, age, have different colors and be in two different forests
9+
The colors can change randomly from time to time
10+
All old Trees can reproduce, but the Three is born green and young
11+
"""
12+
Age, Mortal, Colored, Location = BaseSpecies()
13+
Colored.green, Colored.yellow, Colored.brown
14+
Location.dense, Location.sparse
15+
Age.young >> Age.old[1 / 10 / u.year]
16+
Mortal >> Zero[lambda r1: 0.1 / u.year if r1.old else 0]
17+
Tree = Age * Colored * Mortal * Location
18+
19+
# replication
20+
Tree.old >> Tree + Tree.young[0.1 / u.year]
21+
22+
# competition
23+
Tree.dense.old + Tree.dense.young >> Tree.dense.old[1e-10 * u.decimeter ** 2 / u.year]
24+
25+
# reproduction
26+
bf = 1e-10 * u.decimeter ** 2 / u.year
27+
rep_r = lambda t1, t2: 5 * bf if (Location(t1) == Location(t2) and Colored(t1) == Colored(t2)) else bf
28+
2 * Tree >> 2 * Tree + Tree.yound[rep_r]
29+
30+
# color cycling
31+
colors = ['green', 'yellow', 'brown']
32+
for color, next_color in zip(colors, colors[1:] + colors[:1]):
33+
Tree.c(color) >> Tree.c(next_color)[10 / u.year]
34+
35+
# initial conditions
36+
Tree.dense(50), Tree.dense.old(50), Tree.sparse(50), Tree.sparse.old(50)
37+
MySim = Simulation(Tree)
38+
MySim.run(volume=1 * u.meter ** 2, unit_x='year',
39+
duration=100 * u.years, repetitions=3, output_concentration=False,
40+
simulation_method='stochastic', save_data=False, plot_data=False)
41+
MySim.plot_stochastic(Tree.dense, Tree.sparse, Tree.brown)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from mobspy import *
2+
3+
# We start with all base species
4+
Link1, Link2, Phos_2 = BaseSpecies()
5+
Link1.nl_1, Link1.l_1, Link2.nl_2, Link2.l_2
6+
Phos_2.not_phos, Phos_2.phos_1, Phos_2.phos_2
7+
8+
# A and B can be linked
9+
A = Link1*Link2
10+
B = New(Link1)
11+
# C can be phosporolized twice
12+
C = Phos_2*Link2
13+
14+
# Rev stands for reversible reaction
15+
Rev[A.nl_1 + B.nl_1 >> A.l_1 + B.l_1][1e-4, 0.1]
16+
17+
# A binds to C
18+
A.nl_2.l_1 + C.nl_2.not_phos >> A.l_2.l_1 + C.l_2.not_phos [1e-4]
19+
20+
# C is phosphoralized releases A
21+
C.l_2.not_phos + A.l_2.l_1 >> C.nl_2.phos_1 + A.nl_2.l_1 [1]
22+
23+
# C phosporalized binds to unbound A
24+
A.l_2.nl_1 + C.nl_2.phos_1 >> A.l_2.nl_1 + C.l_2.phos_1 [1e-4]
25+
26+
# Final C site is modified
27+
A.l_2.nl_1 + C.l_2.phos_1 >> A.nl_2.nl_1 + C.nl_2.phos_2 [1]
28+
29+
# initial conditions
30+
A(1000), B(1000), C(10000)
31+
S = Simulation(A | B | C)
32+
S.compile()
33+
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from mobspy import *
2+
import seaborn
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
6+
7+
max_plas, max_pbad, max_ptet = (1, 1, 1)
8+
9+
Mortal, Location = BaseSpecies()
10+
Location.c1, Location.c2, Location.c3, Location.c4
11+
PBad, PTet, Pcl, PLas, Movable = New(Location)
12+
Ara, aTc, Cl, YFP, AHL, OC12 = New(Mortal*Movable)
13+
n = 50
14+
# n = 10 - for testing
15+
# Parametric sweeps for XOR gate analysis
16+
ara_entrace_rate, atc_entrace_rate = ModelParameters([float(x) for x in np.linspace(0, 35, n)],
17+
[float(x) for x in np.linspace(0, 2000, n)])
18+
19+
# Death and movement reactions
20+
Mortal >> Zero[1]
21+
for x, y in zip(['c1', 'c1', 'c2', 'c3'], ['c2', 'c3', 'c4', 'c4']):
22+
Movable.c(x) >> Movable.c(y) [0.1]
23+
24+
# Represents the entrance of aTc and Ara in the system
25+
def diffusion_in_cell(Molecule, rate, locations):
26+
for l in locations:
27+
Zero >> Molecule.c(l) [rate]
28+
diffusion_in_cell(Ara, ara_entrace_rate, ['c1', 'c2'])
29+
diffusion_in_cell(aTc, atc_entrace_rate, ['c1', 'c3'])
30+
31+
# Promoter activation function
32+
def promoter_activation(P, Ligand, Protein, tf_max, n,
33+
K_d, protein_production_rate, locations):
34+
tf_linked = lambda lig: tf_max * lig ** n / (lig ** n + K_d ** n)
35+
tf_free = lambda lig: tf_max - tf_max * lig ** n / (lig ** n + K_d ** n)
36+
pr = lambda r1, r2: protein_production_rate(r1, tf_linked(r2), tf_free(r2))
37+
for l in locations:
38+
with Location.c(l):
39+
P + Ligand >> P + Ligand + Protein [pr]
40+
41+
# Inverter for each nor gate
42+
def inverter_wire(P, R, Signal, locations):
43+
rate_f = lambda r1, r2: 181*r1*350/(1 + 350 + 15*r2 + 50*r2 + 15*50*0.18*r2**2)
44+
for l in locations:
45+
with Location.c(l):
46+
P + R >> P + R + Signal[rate_f]
47+
48+
# Custom buffer for clear visibility
49+
def buffer(L, Signal, l, n, K):
50+
with Location.c(l):
51+
L >> L + Signal [lambda r: 30*r**n/(r**n + K**n)]
52+
53+
# Each promoter expression is written here and assign to the promoter function
54+
pbad_p_rate = lambda r1, r2, r3: 765*r1*(0.009 + 37.5*r2)/(1 + 0.009 + 37.5*r2 + 3.4*r3)
55+
promoter_activation(PBad, Ara, Cl, max_pbad, 2.8, 90, pbad_p_rate, ['c1', 'c2'])
56+
ptet_p_rate = lambda r1, r2, r3: 300*r1*350/(1 + 350 + 2*160*r3 + 160**2*r3**2)
57+
promoter_activation(PTet, aTc, Cl, max_ptet, 1.0, 250, ptet_p_rate, ['c1', 'c3'])
58+
plas_p_rate = lambda r1, r2, r3: 69*r1*(0.002 + 100*r2)/(1 + 0.002 + 100*r2)
59+
promoter_activation(PLas, AHL, Cl, max_plas, 1.4, 0.2, plas_p_rate, ['c2', 'c3'])
60+
# Inverter wires in all the gates
61+
inverter_wire(Pcl, Cl, AHL, ['c1']), inverter_wire(Pcl, Cl, OC12, ['c2', 'c3'])
62+
# Buffer for YFP
63+
buffer(OC12, YFP, 'c4', 4, 0.04)
64+
65+
# Count assignment and Sim
66+
model = set_counts({Ara: 0, aTc: 0, Cl: 0, YFP: 0, PBad.c1: 1, PBad.c2: 1, PTet.c1: 1, PTet.c3: 1,
67+
Pcl.c1: 1, Pcl.c2: 1, Pcl.c3: 1, PLas.c2: 1, PLas.c3: 1, AHL: 0, OC12: 0})
68+
S = Simulation(model)
69+
S.duration = 100
70+
S.plot_data = False
71+
S.run()
72+
73+
matrix = []
74+
line = []
75+
for i, r in enumerate(S.results[YFP]):
76+
line.append(r[-1])
77+
if (i + 1) % n == 0:
78+
matrix.append(line)
79+
line = []
80+
81+
ax = seaborn.heatmap(matrix)
82+
83+
# Invert the y-axis
84+
ax.invert_yaxis()
85+
86+
plt.title('XOR Gate Heatmap', fontsize=18)
87+
plt.xlabel('Ara (a.u.)', fontsize=14)
88+
plt.ylabel('aTc (a.u.)', fontsize=14)
89+
plt.show()

0 commit comments

Comments
 (0)