ode2tn 1.0.5__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ode2tn/transform.py +30 -28
- {ode2tn-1.0.5.dist-info → ode2tn-1.1.0.dist-info}/METADATA +6 -4
- ode2tn-1.1.0.dist-info/RECORD +7 -0
- {ode2tn-1.0.5.dist-info → ode2tn-1.1.0.dist-info}/WHEEL +1 -1
- ode2tn-1.0.5.dist-info/RECORD +0 -7
- {ode2tn-1.0.5.dist-info → ode2tn-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {ode2tn-1.0.5.dist-info → ode2tn-1.1.0.dist-info}/top_level.txt +0 -0
ode2tn/transform.py
CHANGED
@@ -9,23 +9,23 @@ from scipy.integrate._ivp.ivp import OdeResult # noqa
|
|
9
9
|
|
10
10
|
|
11
11
|
def plot_tn(
|
12
|
-
odes: dict[sp.Symbol
|
13
|
-
|
12
|
+
odes: dict[sp.Symbol, sp.Expr | str | float],
|
13
|
+
inits: dict[sp.Symbol | gp.Specie, float],
|
14
14
|
t_eval: Iterable[float] | None = None,
|
15
15
|
*,
|
16
16
|
gamma: float,
|
17
17
|
beta: float,
|
18
18
|
scale: float = 1.0,
|
19
|
-
existing_factors: Iterable[sp.Symbol
|
19
|
+
existing_factors: Iterable[sp.Symbol] = (),
|
20
20
|
verify_negative_term: bool = True,
|
21
21
|
t_span: tuple[float, float] | None = None,
|
22
22
|
show_factors: bool = False,
|
23
23
|
latex_legend: bool = True,
|
24
|
-
resets: dict[float, dict[sp.Symbol
|
25
|
-
dependent_symbols: dict[sp.Symbol
|
26
|
-
|
27
|
-
symbols_to_plot: Iterable[sp.Symbol
|
28
|
-
Iterable[Iterable[sp.Symbol
|
24
|
+
resets: dict[float, dict[sp.Symbol, float]] | None = None,
|
25
|
+
dependent_symbols: dict[sp.Symbol, sp.Expr] | None = None,
|
26
|
+
figsize: tuple[float, float] = (10, 3),
|
27
|
+
symbols_to_plot: Iterable[sp.Symbol] |
|
28
|
+
Iterable[Iterable[sp.Symbol]] |
|
29
29
|
str |
|
30
30
|
re.Pattern |
|
31
31
|
Iterable[re.Pattern] |
|
@@ -43,7 +43,7 @@ def plot_tn(
|
|
43
43
|
"""
|
44
44
|
Plot transcription network (TN) ODEs and initial values.
|
45
45
|
|
46
|
-
For arguments other than odes,
|
46
|
+
For arguments other than odes, inits, gamma, and beta, see the documentation for
|
47
47
|
`plot` in the gpac library.
|
48
48
|
|
49
49
|
Args:
|
@@ -52,7 +52,7 @@ def plot_tn(
|
|
52
52
|
(representing RHS of ODEs)
|
53
53
|
Raises ValueError if any of the ODEs RHS is not a polynomial
|
54
54
|
|
55
|
-
|
55
|
+
inits: initial values,
|
56
56
|
dict of sympy symbols or strings (representing symbols) to floats
|
57
57
|
|
58
58
|
gamma: coefficient of the negative linear term in the transcription network
|
@@ -123,13 +123,15 @@ def plot_tn(
|
|
123
123
|
if show_factors and symbols_to_plot is not None:
|
124
124
|
raise ValueError("Cannot use both show_factors and symbols_to_plot at the same time.")
|
125
125
|
|
126
|
-
tn_odes, tn_inits, tn_syms = ode2tn(odes,
|
126
|
+
tn_odes, tn_inits, tn_syms = ode2tn(odes, inits, gamma=gamma, beta=beta, scale=scale,
|
127
127
|
existing_factors=existing_factors,
|
128
128
|
verify_negative_term=verify_negative_term)
|
129
129
|
dependent_symbols_tn = dict(dependent_symbols) if dependent_symbols is not None else {}
|
130
130
|
tn_ratios = {sym: sym_t/sym_b for sym, (sym_t, sym_b) in tn_syms.items()}
|
131
131
|
dependent_symbols_tn.update(tn_ratios)
|
132
|
-
|
132
|
+
|
133
|
+
assert symbols_to_plot is None or not show_factors
|
134
|
+
symbols_to_plot = list(dependent_symbols_tn.keys()) if symbols_to_plot is None else symbols_to_plot
|
133
135
|
|
134
136
|
if show_factors:
|
135
137
|
symbols_to_plot = [symbols_to_plot, [factor for pair in tn_syms.values() for factor in pair]]
|
@@ -144,12 +146,12 @@ def plot_tn(
|
|
144
146
|
|
145
147
|
return gp.plot(
|
146
148
|
odes=tn_odes,
|
147
|
-
|
149
|
+
inits=tn_inits,
|
148
150
|
t_eval=t_eval,
|
149
151
|
t_span=t_span,
|
150
152
|
dependent_symbols=dependent_symbols_tn,
|
151
153
|
resets=resets,
|
152
|
-
|
154
|
+
figsize=figsize,
|
153
155
|
latex_legend=latex_legend,
|
154
156
|
symbols_to_plot=symbols_to_plot,
|
155
157
|
legend=legend,
|
@@ -204,7 +206,7 @@ def update_resets_with_ratios(odes, resets, tn_odes, tn_syms, scale: float = 1.0
|
|
204
206
|
|
205
207
|
def ode2tn(
|
206
208
|
odes: dict[sp.Symbol | str, sp.Expr | str | float],
|
207
|
-
|
209
|
+
inits: dict[sp.Symbol | str | gp.Specie, float],
|
208
210
|
*,
|
209
211
|
gamma: float,
|
210
212
|
beta: float,
|
@@ -223,7 +225,7 @@ def ode2tn(
|
|
223
225
|
(representing RHS of ODEs)
|
224
226
|
Raises ValueError if any of the ODEs RHS is not a polynomial
|
225
227
|
|
226
|
-
|
228
|
+
inits: initial values,
|
227
229
|
dict of sympy symbols or strings (representing symbols) or gpac.Specie (representing chemical
|
228
230
|
species, if the ODEs were derived from `gpac.crn_to_odes`) to floats
|
229
231
|
|
@@ -264,14 +266,14 @@ def ode2tn(
|
|
264
266
|
in the original ODEs to the pair ``(x_top, x_bot)``.
|
265
267
|
"""
|
266
268
|
# normalize initial values dict to use symbols as keys
|
267
|
-
|
268
|
-
for symbol, value in
|
269
|
+
inits_norm = {}
|
270
|
+
for symbol, value in inits.items():
|
269
271
|
if isinstance(symbol, str):
|
270
272
|
symbol = sp.symbols(symbol)
|
271
273
|
if isinstance(symbol, gp.Specie):
|
272
274
|
symbol = sp.symbols(symbol.name)
|
273
|
-
|
274
|
-
|
275
|
+
inits_norm[symbol] = value
|
276
|
+
inits = inits_norm
|
275
277
|
|
276
278
|
# normalize existing_factors to be symbols
|
277
279
|
existing_factors: list[sp.Symbol] = [sp.Symbol(factor) if isinstance(factor, str) else factor
|
@@ -289,12 +291,12 @@ def ode2tn(
|
|
289
291
|
odes_normalized[symbol] = expr
|
290
292
|
odes = odes_normalized
|
291
293
|
|
292
|
-
# ensure that all symbols that are keys in `
|
293
|
-
|
294
|
+
# ensure that all symbols that are keys in `inits` are also keys in `odes`
|
295
|
+
inits_keys = set(inits.keys())
|
294
296
|
odes_keys = set(odes.keys())
|
295
|
-
diff =
|
297
|
+
diff = inits_keys - odes_keys
|
296
298
|
if len(diff) > 0:
|
297
|
-
raise ValueError(f"\
|
299
|
+
raise ValueError(f"\ninits contains symbols that are not in odes: "
|
298
300
|
f"{comma_separated(diff)}"
|
299
301
|
f"\nHere are the symbols of the ODES: "
|
300
302
|
f"{comma_separated(odes_keys)}")
|
@@ -311,7 +313,7 @@ def ode2tn(
|
|
311
313
|
if not expr.is_polynomial():
|
312
314
|
raise ValueError(f"ODE for {symbol}' is not a polynomial: {expr}")
|
313
315
|
|
314
|
-
return normalized_ode2tn(odes,
|
316
|
+
return normalized_ode2tn(odes, inits, gamma=gamma, beta=beta, scale=scale, ignore=list(ignore),
|
315
317
|
existing_factors=existing_factors, verify_negative_term=verify_negative_term)
|
316
318
|
|
317
319
|
|
@@ -464,7 +466,7 @@ def is_approximately_equal(a: float, b: float, rtol: float = 1e-5, atol: float =
|
|
464
466
|
|
465
467
|
def normalized_ode2tn(
|
466
468
|
odes: dict[sp.Symbol, sp.Expr],
|
467
|
-
|
469
|
+
inits: dict[sp.Symbol, float],
|
468
470
|
*,
|
469
471
|
gamma: float,
|
470
472
|
beta: float,
|
@@ -494,7 +496,7 @@ def normalized_ode2tn(
|
|
494
496
|
ratio = y_t / y_b
|
495
497
|
ode = ode.subs(y, ratio)
|
496
498
|
tn_odes[x] = ode
|
497
|
-
tn_inits[x] =
|
499
|
+
tn_inits[x] = inits.get(x, 0) * scale
|
498
500
|
continue
|
499
501
|
p_pos, p_neg = split_polynomial(ode)
|
500
502
|
|
@@ -510,7 +512,7 @@ def normalized_ode2tn(
|
|
510
512
|
x_t, x_b = tn_syms[x]
|
511
513
|
tn_odes[x_t] = beta * x_t / x_b + p_pos * x_b - gamma * x_t
|
512
514
|
tn_odes[x_b] = beta + p_neg * x_b ** 2 / x_t - gamma * x_b
|
513
|
-
tn_inits[x_t] =
|
515
|
+
tn_inits[x_t] = inits.get(x, 0) * scale
|
514
516
|
tn_inits[x_b] = scale
|
515
517
|
check_x_is_transcription_factor(x_t, tn_odes[x_t], gamma=gamma, verify_negative_term=False)
|
516
518
|
check_x_is_transcription_factor(x_b, tn_odes[x_b], gamma=gamma, verify_negative_term=False)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ode2tn
|
3
|
-
Version: 1.0
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: A Python package to turn arbitrary polynomial ODEs into a transcriptional network simulating it.
|
5
5
|
Author-email: Dave Doty <doty@ucdavis.edu>
|
6
6
|
License-Expression: MIT
|
7
|
-
Project-URL: Homepage, https://github.com/UC-Davis-molecular-computing/
|
8
|
-
Project-URL: Issues, https://github.com/UC-Davis-molecular-computing/
|
7
|
+
Project-URL: Homepage, https://github.com/UC-Davis-molecular-computing/ode2tn
|
8
|
+
Project-URL: Issues, https://github.com/UC-Davis-molecular-computing/ode2tn/issues
|
9
9
|
Requires-Python: >=3.10
|
10
10
|
Description-Content-Type: text/markdown
|
11
11
|
License-File: LICENSE
|
@@ -39,6 +39,7 @@ Here is a typical way to call each function:
|
|
39
39
|
from math import pi
|
40
40
|
import numpy as np
|
41
41
|
import sympy as sp
|
42
|
+
import gpac as gp
|
42
43
|
from transform import plot_tn, ode2tn
|
43
44
|
|
44
45
|
x,y = sp.symbols('x y')
|
@@ -118,4 +119,5 @@ y_t = [1. 1.87324904 2.14156469 2.10338162 2.74383426]
|
|
118
119
|
y_b = [1. 0.93637933 0.71348949 1.05261915 2.78279691]
|
119
120
|
```
|
120
121
|
|
121
|
-
|
122
|
+
## Usage
|
123
|
+
Funding for this work was provided by the US Department of Energy, under [award DE-SC0024467](https://pamspublic.science.energy.gov/WebPAMSExternal/Interface/Common/ViewPublicAbstract.aspx?rv=951d8de9-eec9-43a5-b112-357143330f8c&rtc=24).
|
@@ -0,0 +1,7 @@
|
|
1
|
+
ode2tn/__init__.py,sha256=CEHlHkTMSItKXBPVGGxTNa9FO-ywsIQ5-v6xk7Oy91A,177
|
2
|
+
ode2tn/transform.py,sha256=HJEeobByn_YGzAW6rok4Q0Nnl-JxIi7eBG624u1y8aw,28017
|
3
|
+
ode2tn-1.1.0.dist-info/licenses/LICENSE,sha256=VV9UH0kkG-2edZvwJOqgtN12bZIzs2vn9_cq1SjoUJc,1091
|
4
|
+
ode2tn-1.1.0.dist-info/METADATA,sha256=LebD66OlAOlQz-YcqEZp9N0BzqxRlkWbYBUetJpJlQM,5427
|
5
|
+
ode2tn-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
ode2tn-1.1.0.dist-info/top_level.txt,sha256=fPQ9s5yLIYfazJS7wBBfU9EsWa9RGALq8VL-wUYRlao,7
|
7
|
+
ode2tn-1.1.0.dist-info/RECORD,,
|
ode2tn-1.0.5.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
ode2tn/__init__.py,sha256=CEHlHkTMSItKXBPVGGxTNa9FO-ywsIQ5-v6xk7Oy91A,177
|
2
|
-
ode2tn/transform.py,sha256=rM-VB22RzXkJBFB3FQXRNbW9o8Im2uB2BDZmd-IqKQo,28197
|
3
|
-
ode2tn-1.0.5.dist-info/licenses/LICENSE,sha256=VV9UH0kkG-2edZvwJOqgtN12bZIzs2vn9_cq1SjoUJc,1091
|
4
|
-
ode2tn-1.0.5.dist-info/METADATA,sha256=OgGtD7rM0QPMdizRbb9VahAcF8pktpteiYxYstyxFLc,5207
|
5
|
-
ode2tn-1.0.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
6
|
-
ode2tn-1.0.5.dist-info/top_level.txt,sha256=fPQ9s5yLIYfazJS7wBBfU9EsWa9RGALq8VL-wUYRlao,7
|
7
|
-
ode2tn-1.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|