forked from VoigtLab/dnaplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepressilator_animate.py
154 lines (134 loc) · 7.05 KB
/
repressilator_animate.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
153
154
#!/usr/bin/env python
"""
Repressilator gene circuit
"""
import numpy as np
from scipy.integrate import odeint
import dnaplotlib
import matplotlib.pyplot as plt
from matplotlib import gridspec
__author__ = 'Emerson Glassey <[email protected]>, Voigt Lab, MIT'
__license__ = 'MIT'
__version__ = '1.0'
# Initialize Simulation
# Initial concentration of mRNA and Protein for each repressor
mtet, mlac, mgamma, tet, lac, gamma = initial = [1, 1, 1, 2, 1, 1]
# Non-dimensionalized production rate
alpha = 15
# Degradation Rate
beta = 2000
# Repressor/Promoter Leak
leak = 1
# Hill Coefficient
n = 8
# Initialize Parts
# tetr is orange [1.00, 0.75, 0.17]
# lacI is green [0.38, 0.82, 0.32]
# gamma is blue [0.38, 0.65, 0.87]
plac = {'name':'P_lac', 'start':1, 'end':10, 'type':'Promoter', 'opts': {'color':[0.38, 0.82, 0.32]}}
rbs1 = {'name':'RBS', 'start':11, 'end':20, 'type':'RBS', 'opts':{'linewidth': 0, 'color':[0.0, 0.0, 0.0]}}
tetr = {'name':'tetR', 'start':21, 'end':40, 'type':'CDS', 'opts':{'label': '', 'fontsize': 8, 'label_y_offset': 0, 'label_x_offset': -2, 'label_style':'italic', 'color':[1.00, 0.75, 0.17]}}
term1 = {'name':'Term', 'start':41, 'end':55, 'type':'Terminator'}
pgamma = {'name':'P_gamma', 'start':56, 'end':65, 'type':'Promoter', 'opts': {'color':[0.38, 0.65, 0.87]}}
rbs2 = {'name':'RBS', 'start':66, 'end':75, 'type':'RBS', 'opts':{'linewidth': 0, 'color':[0.0, 0.0, 0.0]}}
laci = {'name':'lacI', 'start':76, 'end':95, 'type':'CDS', 'opts':{'label': '', 'fontsize': 8, 'label_y_offset': 0, 'label_x_offset': -2, 'label_style':'italic', 'color':[0.38, 0.82, 0.32]}}
term2 = {'name':'Term', 'start':96, 'end':110, 'type':'Terminator'}
ptet = {'name':'P_tet', 'start':111, 'end':120, 'type':'Promoter', 'opts': {'color':[1.00, 0.75, 0.17]}}
rbs3 = {'name':'RBS', 'start':121, 'end':130, 'type':'RBS', 'opts':{'linewidth': 0, 'color':[0.0, 0.0, 0.0]}}
gamma = {'name':'gamma', 'start':131, 'end':150, 'type':'CDS', 'opts':{'label': '', 'fontsize': 8, 'label_y_offset': 0, 'label_x_offset': -1, 'label_style':'italic', 'color':[0.38, 0.65, 0.87]}}
term3 = {'name':'Term', 'start':151, 'end':165, 'type':'Terminator'}
lac_repress = {'from_part':laci, 'to_part':plac, 'type':'Repression', 'opts':{'linewidth':1, 'color':[0.38, 0.82, 0.32]}}
gamma_repress = {'from_part':gamma, 'to_part':pgamma, 'type':'Repression', 'opts':{'linewidth':1, 'color':[0.38, 0.65, 0.87]}}
tet_repress = {'from_part':tetr, 'to_part':ptet, 'type':'Repression', 'opts':{'linewidth':1, 'color':[1.00, 0.75, 0.17]}}
def repressilator(y, t):
mtet, mlac, mgamma, tet, lac, gamma = y
dmtet = -mtet + (alpha / (1 + lac**n)) + leak
dtet = -beta * (tet - mtet)
dmlac = -mlac + (alpha / (1 + gamma**n)) + leak
dlac = -beta * (lac - mlac)
dmgamma = -mgamma + (alpha / (1 + tet**n)) + leak
dgamma = -beta * (gamma - mgamma)
return [dmtet, dmlac, dmgamma, dtet, dlac, dgamma]
def repression(val, Kd, power):
"""Function takes a value and Kd. Function fits the value to a hill function with n=power and Kd
and returns the fraction bound."""
new_val = val**power / (Kd**power + val** power)
return new_val
def expression(val, lims):
"""function takes a value between two limits (as a tuple) and returns the value normalized
by the limits to be between 0 and 1"""
new_val = (val - lims[0]) / (lims[1] - lims[0])
return new_val
def rescale(val, lims):
"""function takes a value between 0 and 1 and normalizes it between the limits in lims"""
new_val = (val*(lims[1]-lims[0])) + lims[0]
return new_val
def plot_construct(ax, t, ymtet, ymlac, ymgamma, ytet, ylac, ygamma):
tind = int(t*10)
exp_lims = (1.0, 4.0)
# Set color for each of the CDSs
tetr['opts']['color'] = [rescale(1 - expression(ymtet[tind], exp_lims), (1.0, 1.0)),
rescale(1 - expression(ymtet[tind], exp_lims), (0.75, 1.0)),
rescale(1 - expression(ymtet[tind], exp_lims), (0.17, 1.0))]
laci['opts']['color'] = [rescale(1 - expression(ymlac[tind], exp_lims), (0.38, 1.0)),
rescale(1 - expression(ymlac[tind], exp_lims), (0.82, 1.0)),
rescale(1 - expression(ymlac[tind], exp_lims), (0.32, 1.0))]
gamma['opts']['color'] = [rescale(1 - expression(ymgamma[tind], exp_lims), (0.38, 1.0)),
rescale(1 - expression(ymgamma[tind], exp_lims), (0.65, 1.0)),
rescale(1 - expression(ymgamma[tind], exp_lims), (0.87, 1.0))]
# Set transparency for each of the regulatory lines
lac_repress['opts']['color'] = [0.38, 0.82, 0.32,
rescale(repression(ylac[tind], 2.0, 8), (0.2, 1.0))]
gamma_repress['opts']['color'] = [0.38, 0.65, 0.87,
rescale(repression(ygamma[tind], 2.0, 8), (0.2, 1.0))]
tet_repress['opts']['color'] = [1.00, 0.75, 0.17,
rescale(repression(ytet[tind], 2.0, 8), (0.2, 1.0))]
# Set width for each of the regulatory lines
lac_repress['opts']['linewidth'] = rescale(repression(ylac[tind], 2.0, 8), (0.5, 2.0))
gamma_repress['opts']['linewidth'] = rescale(repression(ygamma[tind], 2.0, 8), (0.5, 2.0))
tet_repress['opts']['linewidth'] = rescale(repression(ytet[tind], 2.0, 8), (0.5, 2.0))
dnaplotlib.plot_sbol_designs([ax], [[plac, rbs1, tetr, term1, pgamma, rbs2, laci, term2, ptet, rbs3, gamma, term3]],
[[lac_repress, gamma_repress, tet_repress]])
ax.set_ylim([-11, 31])
def main():
t = np.arange(0, 30.1, 0.1)
ymtet, ymlac, ymgamma, ytet, ylac, ygamma = list(zip(*odeint(repressilator, initial, t)))
plt.close()
plt.figure(figsize=(3.7, 1.5))
gs = gridspec.GridSpec(3, 2, height_ratios=[1, 1, 1], width_ratios=[2.6, 3])
# Plot of repressilator circuit
#ax = plt.subplot(gs[0], rowspan=3)
#dnaplotlib.plot_sbol_designs([ax], [[plac, rbs1, tetr, term1, pgamma, rbs2, laci, term2, ptet, rbs3, gamma, term3]],
# [[lac_repress, gamma_repress, tet_repress]])
#ax.set_ylim([-10, 31])
# Plot of repressilator dynamics
ax = plt.subplot(gs[0:,0])
plt.plot(t, ytet, color=[1.00, 0.75, 0.17])
plt.plot(t, ylac, color=[0.38, 0.82, 0.32])
plt.plot(t, ygamma, color=[0.38, 0.65, 0.87])
plt.axvline(x=1, color='k', linewidth=0.7)
plt.axvline(x=12, color='k', linewidth=0.7)
plt.axvline(x=25.3, color='k', linewidth=0.7)
plt.axvline(x=27.3, color='k', linewidth=0.7)
plt.axvline(x=29.4, color='k', linewidth=0.7)
plt.ylim([1,4])
ax.tick_params(axis='both', labelsize=8, width=0.8, length=3)
ax.yaxis.tick_left()
ax.xaxis.tick_bottom()
ax.set_xlabel('Time', fontsize=8, labelpad=1)
ax.set_ylabel('Protein Concentration', fontsize=8, labelpad=2)
#plt.legend(['tetR', 'lacI', 'gamma'], frameon=False, fontsize=8, labelspacing=0.15, loc=(0.06,0.65))
# Plot of each timepoint
ax = plt.subplot(gs[1])
plot_construct(ax, 25.3, ymtet, ymlac, ymgamma, ytet, ylac, ygamma)
ax = plt.subplot(gs[3])
plot_construct(ax, 27.3, ymtet, ymlac, ymgamma, ytet, ylac, ygamma)
ax = plt.subplot(gs[5])
plot_construct(ax, 29.4, ymtet, ymlac, ymgamma, ytet, ylac, ygamma)
# Update subplot spacing
plt.subplots_adjust(hspace=0.1, wspace=0.05, left=0.01, right=0.99, top=0.99, bottom=0.01)
# Save the figure
plt.savefig('repressilator_fig.pdf', transparent=True)
plt.savefig('repressilator_fig.png', dpi=300)
if __name__ == '__main__':
main()