1
- # collection of utility functions for getting mass action jumps out of
1
+ # collection of utility functions for getting mass action jumps out of
2
2
# DiffEqBiological reaction network structures
3
3
4
4
# return a map from species symbol to species index
5
5
function species_to_indices (network)
6
6
specs = network. syms
7
- Dict ( specs[i] => i for i in eachindex (specs) )
7
+ Dict ( specs[i] => i for i in eachindex (specs) )
8
8
end
9
9
10
10
# return a map from reaction param symbol to rate index
@@ -13,7 +13,7 @@ function rate_to_indices(network)
13
13
Dict ( rates[i] => i for i in eachindex (rates) )
14
14
end
15
15
16
- # get substrate stoichiometry for a reaction
16
+ # get substrate stoichiometry for a reaction
17
17
function get_substrate_stoich (rs, specmap)
18
18
reactant_stoich = Vector {Pair{Int,Int}} ()
19
19
for substrate in rs. substrates
@@ -79,7 +79,7 @@ function network_to_jumpset(rn, specmap, ratemap, params)
79
79
majumpvec = Vector {typeof(empty_majump)} ()
80
80
cjumpvec = Vector {ConstantRateJump} ()
81
81
82
- for (i,rs) in enumerate (rn. reactions)
82
+ for (i,rs) in enumerate (rn. reactions)
83
83
if rs. is_pure_mass_action
84
84
push! (majumpvec, make_majump (rs, specmap, ratemap, params))
85
85
else
@@ -104,7 +104,7 @@ function rxidxs_to_jidxs_map(rn, num_majumps)
104
104
cjidx = num_majumps + 1
105
105
numrxs = length (rn. reactions)
106
106
rxi_to_ji = zeros (Int, numrxs)
107
- for i = 1 : numrxs
107
+ for i = 1 : numrxs
108
108
if rn. reactions[i]. is_pure_mass_action
109
109
rxi_to_ji[i] = majidx
110
110
majidx += 1
@@ -116,15 +116,29 @@ function rxidxs_to_jidxs_map(rn, num_majumps)
116
116
rxi_to_ji
117
117
end
118
118
119
+ # map from jump to vector of species it changes
120
+ function jump_to_dep_specs_map (rn, specmap, rxidxs_jidxs)
121
+ numrxs = length (rn. reactions)
122
+ numspec = length (specmap)
123
+
124
+ # map from a jump to vector of species that depend on it
125
+ jtos_vec = Vector {Vector{valtype(specmap)}} (undef, numrxs)
126
+ for rx in 1 : numrxs
127
+ jidx = rxidxs_jidxs[rx]
128
+ jtos_vec[jidx] = sort! ( [ns. first for ns in get_net_stoich (rn. reactions[rx], specmap)] )
129
+ end
130
+
131
+ jtos_vec
132
+ end
133
+
119
134
# map from species to Set of jumps depending on that species
120
135
function spec_to_dep_jumps_map (rn, specmap, rxidxs_to_jidxs)
121
-
122
136
numrxs = length (rn. reactions)
123
137
numspec = length (specmap)
124
138
125
139
# map from a species to jumps that depend on it
126
140
spec_to_dep_jumps = [Set {Int} () for n = 1 : numspec]
127
- for rx in 1 : numrxs
141
+ for rx in 1 : numrxs
128
142
for specsym in rn. reactions[rx]. dependants
129
143
push! (spec_to_dep_jumps[specmap[specsym]], rxidxs_to_jidxs[rx])
130
144
end
@@ -134,26 +148,17 @@ function spec_to_dep_jumps_map(rn, specmap, rxidxs_to_jidxs)
134
148
end
135
149
136
150
# given a reaction network and species map, construct a jump dependency graph
137
- function depgraph_from_network (rn, specmap, jset)
138
-
139
- numrxs = length (rn. reactions)
140
- numspec = length (specmap)
141
- num_majumps = get_num_majumps (jset. massaction_jump)
142
-
143
- # map reaction indices to jump indices
144
- rxidxs_to_jidxs = rxidxs_to_jidxs_map (rn, num_majumps)
145
-
146
- # map from species to jumps that depend on it
147
- spec_to_dep_jumps = spec_to_dep_jumps_map (rn, specmap, rxidxs_to_jidxs)
151
+ function depgraph_from_network (rn, specmap, jset, rxidxs_to_jidxs, spec_to_dep_jumps)
148
152
149
153
# create map from a jump to jumps depending on it
154
+ numrxs = length (rn. reactions)
150
155
dep_sets = [SortedSet {Int} () for n = 1 : numrxs]
151
- for rx in 1 : numrxs
156
+ for rx in 1 : numrxs
152
157
jidx = rxidxs_to_jidxs[rx]
153
158
154
159
# get the net reaction stoichiometry
155
160
net_stoich = get_net_stoich (rn. reactions[rx], specmap)
156
-
161
+
157
162
# rx changes spec, hence rxs depending on spec depend on rx
158
163
for (spec,stoch) in net_stoich
159
164
for dependent_jump in spec_to_dep_jumps[spec]
@@ -169,4 +174,4 @@ function depgraph_from_network(rn, specmap, jset)
169
174
end
170
175
171
176
dep_graph
172
- end
177
+ end
0 commit comments