Skip to content

Commit f125ee8

Browse files
committed
revert network analysis order
1 parent 629dd30 commit f125ee8

File tree

1 file changed

+59
-57
lines changed

1 file changed

+59
-57
lines changed

src/network_analysis.jl

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
### Reaction Complex Handling ###
22

3+
# get the species indices and stoichiometry while filtering out constant species.
4+
function filter_constspecs(specs, stoich::AbstractVector{V}, smap) where {V <: Integer}
5+
isempty(specs) && (return Vector{Int}(), Vector{V}())
6+
7+
if any(isconstant, specs)
8+
ids = Vector{Int}()
9+
filtered_stoich = Vector{V}()
10+
for (i, s) in enumerate(specs)
11+
if !isconstant(s)
12+
push!(ids, smap[s])
13+
push!(filtered_stoich, stoich[i])
14+
end
15+
end
16+
else
17+
ids = map(Base.Fix1(getindex, smap), specs)
18+
filtered_stoich = copy(stoich)
19+
end
20+
ids, filtered_stoich
21+
end
22+
323
"""
424
reactioncomplexmap(rn::ReactionSystem)
525
@@ -48,26 +68,6 @@ function reactioncomplexmap(rn::ReactionSystem)
4868
complextorxsmap
4969
end
5070

51-
# get the species indices and stoichiometry while filtering out constant species.
52-
function filter_constspecs(specs, stoich::AbstractVector{V}, smap) where {V <: Integer}
53-
isempty(specs) && (return Vector{Int}(), Vector{V}())
54-
55-
if any(isconstant, specs)
56-
ids = Vector{Int}()
57-
filtered_stoich = Vector{V}()
58-
for (i, s) in enumerate(specs)
59-
if !isconstant(s)
60-
push!(ids, smap[s])
61-
push!(filtered_stoich, stoich[i])
62-
end
63-
end
64-
else
65-
ids = map(Base.Fix1(getindex, smap), specs)
66-
filtered_stoich = copy(stoich)
67-
end
68-
ids, filtered_stoich
69-
end
70-
7171
@doc raw"""
7272
reactioncomplexes(network::ReactionSystem; sparse=false)
7373
@@ -396,6 +396,25 @@ function deficiency(rn::ReactionSystem)
396396
nps.deficiency
397397
end
398398

399+
# Used in the subsequent function.
400+
function subnetworkmapping(linkageclass, allrxs, complextorxsmap, p)
401+
rxinds = sort!(collect(Set(rxidx for rcidx in linkageclass
402+
for rxidx in complextorxsmap[rcidx])))
403+
rxs = allrxs[rxinds]
404+
specset = Set(s for rx in rxs for s in rx.substrates if !isconstant(s))
405+
for rx in rxs
406+
for product in rx.products
407+
!isconstant(product) && push!(specset, product)
408+
end
409+
end
410+
specs = collect(specset)
411+
newps = Vector{eltype(p)}()
412+
for rx in rxs
413+
Symbolics.get_variables!(newps, rx.rate, p)
414+
end
415+
rxs, specs, newps # reactions and species involved in reactions of subnetwork
416+
end
417+
399418
"""
400419
subnetworks(rn::ReactionSystem)
401420
@@ -433,24 +452,6 @@ function subnetworks(rs::ReactionSystem)
433452
subnetworks
434453
end
435454

436-
function subnetworkmapping(linkageclass, allrxs, complextorxsmap, p)
437-
rxinds = sort!(collect(Set(rxidx for rcidx in linkageclass
438-
for rxidx in complextorxsmap[rcidx])))
439-
rxs = allrxs[rxinds]
440-
specset = Set(s for rx in rxs for s in rx.substrates if !isconstant(s))
441-
for rx in rxs
442-
for product in rx.products
443-
!isconstant(product) && push!(specset, product)
444-
end
445-
end
446-
specs = collect(specset)
447-
newps = Vector{eltype(p)}()
448-
for rx in rxs
449-
Symbolics.get_variables!(newps, rx.rate, p)
450-
end
451-
rxs, specs, newps # reactions and species involved in reactions of subnetwork
452-
end
453-
454455
"""
455456
linkagedeficiencies(network::ReactionSystem)
456457
@@ -625,25 +626,7 @@ function conservationlaws(nsm::T; col_order = nothing) where {T <: AbstractMatri
625626
T(N')
626627
end
627628

628-
"""
629-
conservationlaws(rs::ReactionSystem)
630-
631-
Return the conservation law matrix of the given `ReactionSystem`, calculating it if it is
632-
not already stored within the system, or returning an alias to it.
633-
634-
Notes:
635-
- The first time being called it is calculated and cached in `rn`, subsequent calls should
636-
be fast.
637-
"""
638-
function conservationlaws(rs::ReactionSystem)
639-
nps = get_networkproperties(rs)
640-
!isempty(nps.conservationmat) && (return nps.conservationmat)
641-
nsm = netstoichmat(rs)
642-
nps.conservationmat = conservationlaws(nsm; col_order = nps.col_order)
643-
cache_conservationlaw_eqs!(rs, nps.conservationmat, nps.col_order)
644-
nps.conservationmat
645-
end
646-
629+
# Used in the subsequent function.
647630
function cache_conservationlaw_eqs!(rn::ReactionSystem, N::AbstractMatrix, col_order)
648631
nullity = size(N, 1)
649632
r = numspecies(rn) - nullity # rank of the netstoichmat
@@ -681,6 +664,25 @@ function cache_conservationlaw_eqs!(rn::ReactionSystem, N::AbstractMatrix, col_o
681664
nothing
682665
end
683666

667+
"""
668+
conservationlaws(rs::ReactionSystem)
669+
670+
Return the conservation law matrix of the given `ReactionSystem`, calculating it if it is
671+
not already stored within the system, or returning an alias to it.
672+
673+
Notes:
674+
- The first time being called it is calculated and cached in `rn`, subsequent calls should
675+
be fast.
676+
"""
677+
function conservationlaws(rs::ReactionSystem)
678+
nps = get_networkproperties(rs)
679+
!isempty(nps.conservationmat) && (return nps.conservationmat)
680+
nsm = netstoichmat(rs)
681+
nps.conservationmat = conservationlaws(nsm; col_order = nps.col_order)
682+
cache_conservationlaw_eqs!(rs, nps.conservationmat, nps.col_order)
683+
nps.conservationmat
684+
end
685+
684686
"""
685687
conservedquantities(state, cons_laws)
686688

0 commit comments

Comments
 (0)