Skip to content

Commit 4047a83

Browse files
Merge pull request #26 from ChrisRackauckas/fix-formatting
Apply JuliaFormatter to fix code formatting
2 parents 36c185f + 4cb153d commit 4047a83

20 files changed

+211
-172
lines changed

.JuliaFormatter.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
style = "sciml"
2+
format_markdown = true
3+
format_docstrings = true

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
Finite State Projection [[1]](#1) algorithms for chemical reaction networks based on [Catalyst.jl](https://github.com/SciML/Catalyst.jl) and [ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl). Converts descriptions of reaction networks into `ODEProblem`s and `SteadyStateProblem`s for use with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl).
66

77
## Features:
8-
- Built on top of [Catalyst.jl](https://github.com/SciML/Catalyst.jl)
9-
- FSP equations are generated as `ODEFunction`/`ODEProblem`s and can be solved with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), with on-the-fly generation of targeted functions for improved performance
10-
- The Chemical Master Equation can be represented as a `SparseMatrixCSC`
8+
9+
- Built on top of [Catalyst.jl](https://github.com/SciML/Catalyst.jl)
10+
- FSP equations are generated as `ODEFunction`/`ODEProblem`s and can be solved with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), with on-the-fly generation of targeted functions for improved performance
11+
- The Chemical Master Equation can be represented as a `SparseMatrixCSC`
1112

1213
More information is available in the [documentation](https://kaandocal.github.io/FiniteStateProjection.jl/dev/). Please feel free to open issues and submit pull requests!
1314

1415
## Examples
16+
1517
### Birth-Death System
18+
1619
```julia
1720
using FiniteStateProjection
1821
using OrdinaryDiffEq
@@ -25,7 +28,7 @@ end
2528
sys = FSPSystem(rn)
2629

2730
# Parameters for our system
28-
ps = [ => 10.0, :d => 1.0 ]
31+
ps = [ => 10.0, :d => 1.0]
2932

3033
# Initial distribution (over 1 species)
3134
# Here we start with 0 copies of A
@@ -35,9 +38,11 @@ u0[1] = 1.0
3538
prob = ODEProblem(sys, u0, (0, 10.0), ps)
3639
sol = solve(prob, Vern7())
3740
```
41+
3842
![Visualisation](docs/src/assets/birth_death.png)
3943

4044
### Telegraph Model
45+
4146
```julia
4247
using FiniteStateProjection
4348
using OrdinaryDiffEq
@@ -52,16 +57,17 @@ end
5257
sys = FSPSystem(rn)
5358

5459
# Parameters for our system
55-
ps = [ :σ_on => 0.25, :σ_off => 0.15, => 15.0, :d => 1.0 ]
60+
ps = [:σ_on => 0.25, :σ_off => 0.15, => 15.0, :d => 1.0]
5661

5762
# Initial distribution (over two species)
5863
# Here we start with 0 copies of G_on and M
5964
u0 = zeros(2, 50)
60-
u0[1,1] = 1.0
65+
u0[1, 1] = 1.0
6166

6267
prob = ODEProblem(sys, u0, (0, 10.0), ps)
6368
sol = solve(prob, Vern7())
6469
```
70+
6571
![Visualisation](docs/src/assets/telegraph.png)
6672

6773
## References

demo/birth_death.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
sys = FSPSystem(rs)
1515

1616
# Parameters for our system
17-
ps = [ :r1 => 10.0, :r2 => 1.0 ]
17+
ps = [:r1 => 10.0, :r2 => 1.0]
1818

1919
# Initial values
2020
u0 = zeros(50)
@@ -26,12 +26,12 @@ prob = ODEProblem(sys, u0, 10.0, ps)
2626

2727
##
2828

29-
sol = solve(prob, Vern7(), dense=false, save_everystep=false, abstol=1e-6)
29+
sol = solve(prob, Vern7(), dense = false, save_everystep = false, abstol = 1e-6)
3030

3131
##
3232

3333
plt.suptitle(L"Distribution at $t = 10$")
34-
plt.bar(0:49, sol.u[end], width=1);
34+
plt.bar(0:49, sol.u[end], width = 1);
3535
plt.xlabel("# of Molecules")
3636
plt.ylabel("Probability")
3737
plt.xlim(-0.5, 49.5)

demo/telegraph.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
sys = FSPSystem(rs)
1717

1818
# Parameters for our system
19-
ps = [ :r1 => 0.25, :r2 => 0.15, :r3 => 15.0, :r4 => 1.0 ]
19+
ps = [:r1 => 0.25, :r2 => 0.15, :r3 => 15.0, :r4 => 1.0]
2020

2121
# Initial values
2222
# Since G_on + G_off = const. we do not have to model the two
@@ -29,20 +29,20 @@ ps = [ :r1 => 0.25, :r2 => 0.15, :r3 => 15.0, :r4 => 1.0 ]
2929
# 2
3030
#
3131
u0 = zeros(2, 50)
32-
u0[1,1] = 1.0
32+
u0[1, 1] = 1.0
3333

3434
##
3535

3636
prob = ODEProblem(sys, u0, 10.0, ps)
3737

3838
##
3939

40-
sol = solve(prob, Vern7(), dense=false, save_everystep=false, abstol=1e-6)
40+
sol = solve(prob, Vern7(), dense = false, save_everystep = false, abstol = 1e-6)
4141

4242
##
4343

4444
plt.suptitle(L"Distribution at $t = 10$")
45-
plt.bar(0:49, sol.u[end][1,:] + sol.u[end][2,:], width=1);
45+
plt.bar(0:49, sol.u[end][1, :] + sol.u[end][2, :], width = 1);
4646
plt.xlabel("# of mRNA")
4747
plt.ylabel("Probability")
4848
plt.xlim(-0.5, 49.5)

docs/make.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ using Documenter
22
using FiniteStateProjection
33
using SparseArrays
44

5-
makedocs(sitename="FiniteStateProjection.jl",
6-
modules=[FiniteStateProjection],
7-
format = Documenter.HTML(prettyurls = false),
8-
pages = [
9-
"Home" => "index.md",
10-
"Main API" => "mainapi.md",
11-
"Index Handlers" => "indexhandlers.md",
12-
"Matrix Conversions" => "matrix.md",
13-
"Internal API" => "internal.md",
14-
"Tips & Tricks" => "tips.md",
15-
"Troubleshooting" => "troubleshoot.md",
16-
"Examples" => "examples.md"
17-
])
18-
5+
makedocs(sitename = "FiniteStateProjection.jl",
6+
modules = [FiniteStateProjection],
7+
format = Documenter.HTML(prettyurls = false),
8+
pages = [
9+
"Home" => "index.md",
10+
"Main API" => "mainapi.md",
11+
"Index Handlers" => "indexhandlers.md",
12+
"Matrix Conversions" => "matrix.md",
13+
"Internal API" => "internal.md",
14+
"Tips & Tricks" => "tips.md",
15+
"Troubleshooting" => "troubleshoot.md",
16+
"Examples" => "examples.md"
17+
])
1918

20-
deploydocs(repo = "github.com/kaandocal/FiniteStateProjection.jl.git", devbranch="main")
19+
deploydocs(repo = "github.com/kaandocal/FiniteStateProjection.jl.git", devbranch = "main")

docs/src/examples.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
sys = FSPSystem(rn)
1717

1818
# Parameters for our system
19-
ps = [ 10.0, 1.0 ]
19+
ps = [10.0, 1.0]
2020

2121
# Initial distribution (over 1 species)
2222
# Here we start with 0 copies of A
@@ -26,6 +26,7 @@ u0[1] = 1.0
2626
prob = ODEProblem(sys, u0, (0, 10.0), ps)
2727
sol = solve(prob, Vern7())
2828
```
29+
2930
![Visualisation](assets/birth_death.png)
3031

3132
## Telegraph Model
@@ -35,7 +36,7 @@ Here we showcase the telegraph model, a simplistic description of mRNA transcrip
3536
The most straightforward description of this system includes three species: two gene states, `G_on` and `G_off`, and mRNA `M`. The state space for this system is 3-dimensional. We know, however, that `G_on` and `G_off` never occur at the same time, indeed the conservation law `[G_on] + [G_off] = 1` allows us to express the state of the system in terms of `G_on` and `M` only. The state space of this reduced system is 2-dimensional.If we use an mRNA cutoff of 100, the state space for the original model has size ``2 \times 2 \times 100 = 400``, while the reduced state space has size ``2 \times 100 = 200``, a two-fold saving. Since the FSP get computationally more expensive for each species in a system, eliminating redundant species as above is recommended for improved performance.
3637

3738
!!! note
38-
39+
3940
The class `ReducingIndexHandler`, which performed such reduction on the fly, has been deprecated and will be moved into [Catalyst.jl](https://github.com/SciML/Catalyst.jl).
4041

4142
```julia
@@ -52,14 +53,15 @@ end
5253
sys = FSPSystem(rn)
5354

5455
# Parameters for our system
55-
ps = [ 0.25, 0.15, 15.0, 1.0 ]
56+
ps = [0.25, 0.15, 15.0, 1.0]
5657

5758
# Initial distribution (over two species)
5859
# Here we start with 0 copies of G_on and M
5960
u0 = zeros(2, 50)
60-
u0[1,1] = 1.0
61+
u0[1, 1] = 1.0
6162

6263
prob = ODEProblem(sys, u0, (0, 10.0), ps)
6364
sol = solve(prob, Vern7())
6465
```
66+
6567
![Visualisation](assets/telegraph.png)

docs/src/index.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ CurrentModule=FiniteStateProjection
88

99
FiniteStateProjection.jl is a package that implements Finite State Projection algorithms for chemical reaction networks based on [Catalyst.jl](https://github.com/SciML/Catalyst.jl) and [ModelingToolkit](https://github.com/SciML/ModelingToolkit.jl). FiniteStateProjection.jl converts descriptions of reaction networks into `ODEProblem`s that can be used to compute approximate solutions of the Chemical Master Equation with packages such as [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl).
1010

11-
The Chemical Master Equation allows us to compute the probability of a reaction system to be in a given state ``\vec n`` at a time ``t``. The state of a system with ``s`` species is described by a vector ``\vec n = (n_1, n_2, \ldots, n_s)`` of length ``s``, where ``n_1, n_2, \ldots`` are the abundances of the different species. The reaction system itself can be represented by an ``s``-dimensional array ``P[n_1,\ldots,n_s]`` that describes the probability of the system being in state ``(n_1,\ldots,n_s)``. Here ``P`` depends on time as the system evolves. Given initial conditions ``P(0)``, the time evolution of ``P`` is given by the Chemical Master Equation, which is a set of linear ODEs that can be solved numerically to predict the probability distribution of the system in the future.
11+
The Chemical Master Equation allows us to compute the probability of a reaction system to be in a given state ``\vec n`` at a time ``t``. The state of a system with ``s`` species is described by a vector ``\vec n = (n_1, n_2, \ldots, n_s)`` of length ``s``, where ``n_1, n_2, \ldots`` are the abundances of the different species. The reaction system itself can be represented by an ``s``-dimensional array ``P[n_1,\ldots,n_s]`` that describes the probability of the system being in state ``(n_1,\ldots,n_s)``. Here ``P`` depends on time as the system evolves. Given initial conditions ``P(0)``, the time evolution of ``P`` is given by the Chemical Master Equation, which is a set of linear ODEs that can be solved numerically to predict the probability distribution of the system in the future.
1212

13-
Since the number of states for a system can be infinite, the Finite State Projection approximates the Chemical Master Equation by only considering a finite number of states, namely those which are most probable. There are various ways to truncate the state space, but the most common is to provide an upper limit for each species, that is, to require ``n_1 < M_1``, ``n_2 < M_2``, etc. for fixed thresholds ``M_1, M_2, \ldots``. The number of states considered will be ``M_1 \times M_2 \times \ldots \times M_s``, and ``P`` can be represented as an array with those dimensions. While truncating the CME allows us to solve the equations numerically, the amount of space required to store ``P`` increases quickly as more species are added.
13+
Since the number of states for a system can be infinite, the Finite State Projection approximates the Chemical Master Equation by only considering a finite number of states, namely those which are most probable. There are various ways to truncate the state space, but the most common is to provide an upper limit for each species, that is, to require ``n_1 < M_1``, ``n_2 < M_2``, etc. for fixed thresholds ``M_1, M_2, \ldots``. The number of states considered will be ``M_1 \times M_2 \times \ldots \times M_s``, and ``P`` can be represented as an array with those dimensions. While truncating the CME allows us to solve the equations numerically, the amount of space required to store ``P`` increases quickly as more species are added.
1414

1515
FiniteStateProjection.jl works by converting a `ReactionSystem` into a function that computes the right-hand side of the (truncated) Chemical Master Equation:
1616

@@ -19,11 +19,12 @@ FiniteStateProjection.jl works by converting a `ReactionSystem` into a function
1919
This function is generated dynamically as an `ODEFunction` for use with DifferentialEquations.jl and specialised for each `ReactionSystem`. Users can use their preferred array types and provide additional features by overloading the functions in this package. Alternatively the matrix `A` can be constructed as a `SparseMatrixCSC`. FiniteStateProjection.jl supports both the time-dependent Chemical Master Equation and its steady-state version.
2020

2121
## Features
22-
- Built on top of [Catalyst.jl](https://github.com/SciML/Catalyst.jl)
23-
- FSP equations are generated as `ODEFunction`/`ODEProblem`s and can be solved with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), with on-the-fly generation of targeted functions for improved performance
24-
- The Chemical Master Equation can be generated as a `SparseMatrixCSC`
25-
- Flexible API for user-defined array types via `IndexHandler`s
22+
23+
- Built on top of [Catalyst.jl](https://github.com/SciML/Catalyst.jl)
24+
- FSP equations are generated as `ODEFunction`/`ODEProblem`s and can be solved with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), with on-the-fly generation of targeted functions for improved performance
25+
- The Chemical Master Equation can be generated as a `SparseMatrixCSC`
26+
- Flexible API for user-defined array types via `IndexHandler`s
2627

2728
## Acknowledgments
2829

29-
Special thanks to [Xiamong Fu](https://github.com/palmtree2013), [Brian Munsky](https://www.engr.colostate.edu/~munsky/) and [Huy Vo](https://github.com/voduchuy) for their examples and suggestions and for contributing most of the content in the [Tips & Tricks](@ref tips) page!
30+
Special thanks to [Xiamong Fu](https://github.com/palmtree2013), [Brian Munsky](https://www.engr.colostate.edu/%7Emunsky/) and [Huy Vo](https://github.com/voduchuy) for their examples and suggestions and for contributing most of the content in the [Tips & Tricks](@ref tips) page!

docs/src/indexhandlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Index Handlers
22

3-
The task of an index handler is to provide a mapping between the system state and the way it is stored in memory, usually as a multidimensional array. The standard approach is to represent the states of a system with ``s`` reactions as an ``s``-dimensional array and have the index ``(i_1, \ldots, i_s)`` correspond to the state ``(n_1 = i_1, \ldots, n_s = i_s)``. This is implemented by the class [`DefaultIndexHandler`](@ref), which accepts an offset argument to deal with Julia's 1-based indexing (so the Julia index $(1,\ldots,1)$ corresponds to the state with no molecules).
3+
The task of an index handler is to provide a mapping between the system state and the way it is stored in memory, usually as a multidimensional array. The standard approach is to represent the states of a system with ``s`` reactions as an ``s``-dimensional array and have the index ``(i_1, \ldots, i_s)`` correspond to the state ``(n_1 = i_1, \ldots, n_s = i_s)``. This is implemented by the class [`DefaultIndexHandler`](@ref), which accepts an offset argument to deal with Julia's 1-based indexing (so the Julia index $(1,\ldots,1)$ corresponds to the state with no molecules).
44

55
See the [internal API](@ref index_handlers_internal) on how to define your own `IndexHandler` type.
66

docs/src/internal.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Internal API
2+
23
```@meta
34
CurrentModule = FiniteStateProjection
45
```
@@ -8,14 +9,16 @@ CurrentModule = FiniteStateProjection
89
### Index Handler Interface
910

1011
User-defined index handlers should inherit from `AbstractIndexHandler` and implement the following methods:
11-
- [`getsubstitutions`](@ref getsubstitutions)
12-
- [`build_rhs_header`](@ref build_rhs_header)
13-
- [`singleindices`](@ref singleindices)
14-
- [`pairedindices`](@ref pairedindices)
12+
13+
- [`getsubstitutions`](@ref getsubstitutions)
14+
- [`build_rhs_header`](@ref build_rhs_header)
15+
- [`singleindices`](@ref singleindices)
16+
- [`pairedindices`](@ref pairedindices)
1517

1618
For matrix conversions they should additionally implement:
17-
- [`LinearIndices`](@ref Base.LinearIndices)
18-
- [`vec`](@ref Base.vec)
19+
20+
- [`LinearIndices`](@ref Base.LinearIndices)
21+
- [`vec`](@ref Base.vec)
1922

2023
```@docs
2124
singleindices
@@ -26,11 +29,13 @@ LinearIndices
2629
```
2730

2831
### Built-in implementations
32+
2933
```@docs
3034
getsubstitutions(::DefaultIndexHandler, ::ReactionSystem)
3135
```
3236

3337
## Function Building
38+
3439
```@docs
3540
build_rhs
3641
unpackparams
@@ -40,6 +45,7 @@ build_rhs_secondpass
4045
```
4146

4247
## Steady-State Functions
48+
4349
```@docs
4450
build_rhs_ss
4551
build_rhs_singlepass_ss

docs/src/mainapi.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Main API
2+
23
```@meta
34
CurrentModule = FiniteStateProjection
45
```
@@ -13,8 +14,8 @@ FSPSystem
1314

1415
## Creating ODE systems
1516

16-
The following methods convert a reaction network into a system of ODEs representing the time-dependent FSP. This package provides a flexible way to represent the FSP in memory via index handlers, see [Index Handlers] for more information.
17-
17+
The following methods convert a reaction network into a system of ODEs representing the time-dependent FSP. This package provides a flexible way to represent the FSP in memory via index handlers, see [Index Handlers] for more information.
18+
1819
```@docs
1920
Base.convert(::Type{ODEFunction}, ::FSPSystem)
2021
DiffEqBase.ODEProblem(::FSPSystem, u0, tmax, p)

0 commit comments

Comments
 (0)