ode2tn 1.0.1__py3-none-any.whl → 1.0.2__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 CHANGED
@@ -17,6 +17,7 @@ def plot_tn(
17
17
  beta: float,
18
18
  scale: float = 1.0,
19
19
  t_span: tuple[float, float] | None = None,
20
+ show_factors: bool = False,
20
21
  resets: dict[float, dict[sp.Symbol | str, float]] | None = None,
21
22
  dependent_symbols: dict[sp.Symbol | str, sp.Expr | str] | None = None,
22
23
  figure_size: tuple[float, float] = (10, 3),
@@ -54,6 +55,12 @@ def plot_tn(
54
55
  scale: "scaling factor" for the transcription network ODEs. Each variable `x` is replaced by a pair
55
56
  (`x_top`, `x_bot`). The initial `x_bot` value is `scale`, and the initial `x_top` value is
56
57
  `x*scale`.
58
+ show_factors: if True, then in addition to plotting the ratios x_top/x_bot,
59
+ also plot the factors x_top and x_bot separately in a second plot.
60
+ Mutually exlusive with `symbols_to_plot`, since it is equivalent to setting
61
+ `symbols_to_plot` to ``[ratios, factors]``, where ratios is a list of dependent symbols
62
+ `x=x_top/x_bot`, and factors is a list of symbols with the transcription factors `x_top`, `x_bot`,
63
+ for each original variable `x`.
57
64
  resets:
58
65
  If specified, this is a dict mapping times to "configurations"
59
66
  (i.e., dict mapping symbols/str to values).
@@ -77,12 +84,18 @@ def plot_tn(
77
84
  Typically None, but if return_ode_result is True, returns the result of the ODE integration.
78
85
  See documentation of `gpac.plot` for details.
79
86
  """
87
+ if show_factors and symbols_to_plot is not None:
88
+ raise ValueError("Cannot use both show_factors and symbols_to_plot at the same time.")
89
+
80
90
  tn_odes, tn_inits, tn_syms = ode2tn(odes, initial_values, gamma=gamma, beta=beta, scale=scale)
81
91
  dependent_symbols_tn = dict(dependent_symbols) if dependent_symbols is not None else {}
82
92
  tn_ratios = {sym: sym_t/sym_b for sym, (sym_t, sym_b) in tn_syms.items()}
83
93
  dependent_symbols_tn.update(tn_ratios)
84
94
  symbols_to_plot = dependent_symbols_tn if symbols_to_plot is None else symbols_to_plot
85
95
 
96
+ if show_factors:
97
+ symbols_to_plot = [symbols_to_plot, [factor for pair in tn_syms.values() for factor in pair]]
98
+
86
99
  legend = {}
87
100
  for sym, (sym_t, sym_b) in tn_syms.items():
88
101
  legend[sym_t] = f'${sym}^\\top$'
@@ -317,7 +330,7 @@ def split_polynomial(expr: sp.Expr) -> tuple[sp.Expr, sp.Expr]:
317
330
  else:
318
331
  # For negative coefficients, add the negated term to p2
319
332
  p_neg += -term
320
- elif expanded.is_Mul:
333
+ elif expanded.is_Mul or expanded.is_Pow:
321
334
  # If it's a single term, just check the sign; is_Mul for things like x*y or -x (represented as -1*x)
322
335
  coeff = next((arg for arg in expanded.args if arg.is_number), 1)
323
336
  if coeff > 0:
@@ -347,43 +360,19 @@ def main():
347
360
  import gpac as gp
348
361
  import numpy as np
349
362
  import sympy as sp
350
- from ode2tn import plot_tn, ode2tn
351
-
352
- P = 1
353
- I = 1
354
- D = 1
355
- val, setpoint, bias, integral, derivative_p, derivative_m, delayed_val = \
356
- sp.symbols('val setpoint bias integral derivative_p derivative_m delayed_val')
357
- proportional_term = P * (setpoint - val)
358
- integral_term = I * (integral - 10)
359
- # derivative_term = D * (temperature - delayed_temperature)
360
- c = 1
361
- odes = {
362
- val: proportional_term + integral_term, # + derivative_term,
363
- integral: setpoint - val,
364
- delayed_val: c * (val - delayed_val),
365
- setpoint: 0,
366
- }
367
- inits = {
368
- val: 5,
369
- setpoint: 7,
370
- integral: 10,
371
- }
372
- t_eval = np.linspace(0, 40, 500)
373
- figsize = (16, 4)
374
- resets = {
375
- 10: {val: 9},
376
- 20: {val: 3},
377
- 30: {bias: 2},
378
- }
363
+ from ode2tn import plot_tn
364
+
365
+ x = gp.species('X')
366
+ rxns = [2 * x >> 3 * x]
367
+ odes = gp.crn_to_odes(rxns)
368
+ inits = {x: 1}
369
+ t_eval = np.linspace(0, 1, 100)
379
370
  gamma = 1
380
371
  beta = 1
381
- # plot_tn(odes, inits, t_eval, gamma=gamma, beta=beta, resets=resets, figure_size=figsize)
382
- tn_odes, tn_inits, tn_syms = ode2tn(odes, inits, gamma=gamma, beta=beta)
383
- val_top = tn_syms[val][0]
384
- tn_odes[val_top] += bias
385
- tn_odes[bias] = 0
386
- gp.plot(tn_odes, tn_inits, t_eval, resets=resets, figure_size=figsize)
372
+ # figsize = (16,4)
373
+
374
+ # gp.plot_crn(rxns, inits, t_eval, figure_size=figsize)
375
+ plot_tn(odes, inits, t_eval, gamma=gamma, beta=beta)
387
376
 
388
377
 
389
378
  if __name__ == '__main__':
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ode2tn
3
- Version: 1.0.1
3
+ Version: 1.0.2
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
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/UC-Davis-molecular-computing/ode-to-transcription-network
8
8
  Project-URL: Issues, https://github.com/UC-Davis-molecular-computing/ode-to-transcription-network/issues
9
9
  Requires-Python: >=3.10
@@ -53,12 +53,7 @@ inits = { # inits maps each symbol to its initial value
53
53
  gamma = 2 # uniform decay constant; should be set sufficiently large that ???
54
54
  beta = 1 # constant introduced to keep values from going to infinity or 0
55
55
  t_eval = np.linspace(0, 6*pi, 1000)
56
- # tn_odes, tn_inits, tn_syms = ode2tn(odes, inits, gamma, beta)
57
- # for sym, expr in tn_odes.items():
58
- # print(f"{sym}' = {expr}")
59
- # print(f'{tn_inits=}')
60
- # print(f'{tn_syms=}')
61
- plot_tn(odes, inits, gamma=gamma, beta=beta, t_eval=t_eval)
56
+ plot_tn(odes, inits, gamma=gamma, beta=beta, t_eval=t_eval, show_factors=True)
62
57
  ```
63
58
 
64
59
  This will print
@@ -76,7 +71,7 @@ showing that the variables `x` and `y` have been replace by pairs `x_t,x_b` and
76
71
  The function `plot_tn` above does this conversion and then plots the ratios.
77
72
  Running the code above in a Jupyter notebook will print the above text and show this figure:
78
73
 
79
- ![](sine-cosine-plot.png)
74
+ ![](sine-cosine-plot.svg)
80
75
 
81
76
  One could also hand the transcriptional network ODEs to gpac to integrate, if you want to directly access the data being plotted above.
82
77
  The `OdeResult` object returned by `gpac.integrate_odes` is the same returned by [`scipy.integrate.solve_ivp`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html), where the return value `sol` has a field `sol.y` that has the values of the variables in the order they were inserted into `tn_odes`, which will be the same as the order in which the original variables `x` and `y` were inserted, with `x_t` coming before `x_b`:
@@ -85,20 +80,20 @@ The `OdeResult` object returned by `gpac.integrate_odes` is the same returned by
85
80
  t_eval = np.linspace(0, 2*pi, 5)
86
81
  sol = gp.integrate_odes(tn_odes, tn_inits, t_eval)
87
82
  print(f'times = {sol.t}')
88
- print(f'x_t = {sol.y[0]}')
89
- print(f'x_b = {sol.y[1]}')
90
- print(f'y_t = {sol.y[2]}')
91
- print(f'y_b = {sol.y[3]}')
83
+ print(f'x_t = {sol.y[0]}')
84
+ print(f'x_b = {sol.y[1]}')
85
+ print(f'y_t = {sol.y[2]}')
86
+ print(f'y_b = {sol.y[3]}')
92
87
  ```
93
88
 
94
89
  which would print
95
90
 
96
91
  ```
97
92
  times = [0. 1.57079633 3.14159265 4.71238898 6.28318531]
98
- x_t = [2. 1.78280757 3.67207594 2.80592514 1.71859172]
99
- x_b = [1. 1.78425369 1.83663725 0.93260227 0.859926 ]
100
- y_t = [1. 1.87324904 2.14156469 2.10338162 2.74383426]
101
- y_b = [1. 0.93637933 0.71348949 1.05261915 2.78279691]
93
+ x_t = [2. 1.78280757 3.67207594 2.80592514 1.71859172]
94
+ x_b = [1. 1.78425369 1.83663725 0.93260227 0.859926 ]
95
+ y_t = [1. 1.87324904 2.14156469 2.10338162 2.74383426]
96
+ y_b = [1. 0.93637933 0.71348949 1.05261915 2.78279691]
102
97
  ```
103
98
 
104
99
 
@@ -0,0 +1,7 @@
1
+ ode2tn/__init__.py,sha256=b_mINIsNfCWzgG7QVYMsRsWKDLvp2QKFAzRqWtYqwDA,30
2
+ ode2tn/transform.py,sha256=8gQVHaCRTdiACQPZdkB3OPfc2KOZTA3YwMgbXDDnNkE,16155
3
+ ode2tn-1.0.2.dist-info/licenses/LICENSE,sha256=VV9UH0kkG-2edZvwJOqgtN12bZIzs2vn9_cq1SjoUJc,1091
4
+ ode2tn-1.0.2.dist-info/METADATA,sha256=MSGeKttEB-ImlNvBof07AeyxR1rOCBf48tUNinaIgS0,4095
5
+ ode2tn-1.0.2.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
6
+ ode2tn-1.0.2.dist-info/top_level.txt,sha256=fPQ9s5yLIYfazJS7wBBfU9EsWa9RGALq8VL-wUYRlao,7
7
+ ode2tn-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.1)
2
+ Generator: setuptools (79.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- ode2tn/__init__.py,sha256=b_mINIsNfCWzgG7QVYMsRsWKDLvp2QKFAzRqWtYqwDA,30
2
- ode2tn/transform.py,sha256=0ok_lcHA2lOV8yrB-MBC9es-i7zVP50EktKeuUuhs0k,16148
3
- ode2tn-1.0.1.dist-info/licenses/LICENSE,sha256=VV9UH0kkG-2edZvwJOqgtN12bZIzs2vn9_cq1SjoUJc,1091
4
- ode2tn-1.0.1.dist-info/METADATA,sha256=klLivWzfNVnR3VDVSkWvSuGQDnBrdLCpL7lUOpTCTlc,4228
5
- ode2tn-1.0.1.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
6
- ode2tn-1.0.1.dist-info/top_level.txt,sha256=fPQ9s5yLIYfazJS7wBBfU9EsWa9RGALq8VL-wUYRlao,7
7
- ode2tn-1.0.1.dist-info/RECORD,,