Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
9761031e
Commit
9761031e
authored
Aug 03, 2021
by
Miroslav Kratochvil
🚴
Browse files
reduce copypasta
closes #119
parent
cc059367
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/readsbml.jl
View file @
9761031e
...
...
@@ -358,42 +358,23 @@ function extractModel(mdl::VPtr)::SBML.Model
end
# extract stoichiometry
stoi = Dict{String,Float64}()
add_stoi(sr, factor) = begin
s = get_string(sr, :SpeciesReference_getSpecies)
stoi[s] =
get(stoi, s, 0) +
ccall(sbml(:SpeciesReference_getStoichiometry), Cdouble, (VPtr,), sr) *
factor
end
# extract stoichiometry
substoi = Dict{String,Float64}()
add_sstoi(sr, factor) = begin
s = get_string(sr, :SpeciesReference_getSpecies)
substoi[s] =
ccall(sbml(:SpeciesReference_getStoichiometry), Cdouble, (VPtr,), sr) *
factor
end
# extract stoichiometry
prodstoi = Dict{String,Float64}()
add_pstoi(sr, factor) = begin
reactants = Dict{String,Float64}()
products = Dict{String,Float64}()
add_stoi(sr, coll) = begin
s = get_string(sr, :SpeciesReference_getSpecies)
prodstoi[s] =
ccall(sbml(:SpeciesReference_getStoichiometry), Cdouble, (VPtr,), sr) *
factor
coll[s] =
ccall(sbml(:SpeciesReference_getStoichiometry), Cdouble, (VPtr,), sr)
end
# reactants and products
for j = 1:ccall(sbml(:Reaction_getNumReactants), Cuint, (VPtr,), re)
sr = ccall(sbml(:Reaction_getReactant), VPtr, (VPtr, Cuint), re, j - 1)
add_stoi(sr, -1)
add_sstoi(sr, 1)
add_stoi(sr, reactants)
end
for j = 1:ccall(sbml(:Reaction_getNumProducts), Cuint, (VPtr,), re)
sr = ccall(sbml(:Reaction_getProduct), VPtr, (VPtr, Cuint), re, j - 1)
add_stoi(sr, 1)
add_pstoi(sr, 1)
add_stoi(sr, products)
end
# gene product associations
...
...
@@ -417,9 +398,8 @@ function extractModel(mdl::VPtr)::SBML.Model
reid = get_string(re, :Reaction_getId)
reactions[reid] = Reaction(
substoi,
prodstoi,
stoi,
reactants,
products,
lb,
ub,
haskey(objectives_fbc, reid) ? objectives_fbc[reid] : oc,
...
...
src/structs.jl
View file @
9761031e
...
...
@@ -99,17 +99,16 @@ end
$(TYPEDEF)
Reaction with stoichiometry that assigns reactants and products their relative
consumption/production rates
(accessible in field `stoichiometry`), lower/upper
bounds (in tuples `lb` and `ub`, with
unit names), and objective coefficient
(`oc`). Also may contains `notes` and
`annotation`.
consumption/production rates
, lower/upper bounds (in tuples `lb` and `ub`, with
unit names), and objective coefficient
(`oc`). Also may contains `notes` and
`annotation`.
# Fields
$(TYPEDFIELDS)
"""
struct
Reaction
substoich
::
Dict
{
String
,
Float64
}
prodstoich
::
Dict
{
String
,
Float64
}
stoichiometry
::
Dict
{
String
,
Float64
}
reactants
::
Dict
{
String
,
Float64
}
products
::
Dict
{
String
,
Float64
}
lb
::
Tuple
{
Float64
,
String
}
ub
::
Tuple
{
Float64
,
String
}
oc
::
Float64
...
...
@@ -118,8 +117,8 @@ struct Reaction
reversible
::
Bool
notes
::
Maybe
{
String
}
annotation
::
Maybe
{
String
}
Reaction
(
s
s
,
ps
,
s
,
l
,
u
,
o
,
as
,
km
,
r
,
n
=
nothing
,
an
=
nothing
)
=
new
(
s
s
,
ps
,
s
,
l
,
u
,
o
,
as
,
km
,
r
,
n
,
an
)
Reaction
(
r
s
,
ps
,
l
,
u
,
o
,
as
,
km
,
r
,
n
=
nothing
,
an
=
nothing
)
=
new
(
r
s
,
ps
,
l
,
u
,
o
,
as
,
km
,
r
,
n
,
an
)
end
"""
...
...
src/utils.jl
View file @
9761031e
...
...
@@ -18,8 +18,10 @@ function stoichiometry_matrix(
rowsd
=
Dict
(
k
=>
i
for
(
i
,
k
)
in
enumerate
(
rows
))
S
=
zeros
(
Float64
,
length
(
rows
),
length
(
cols
))
for
col
=
1
:
length
(
cols
)
stoi
=
m
.
reactions
[
cols
[
col
]]
.
stoichiometry
S
[
getindex
.
(
Ref
(
rowsd
),
keys
(
stoi
)),
col
]
.=
values
(
stoi
)
s
=
m
.
reactions
[
cols
[
col
]]
.
reactants
S
[
getindex
.
(
Ref
(
rowsd
),
keys
(
s
)),
col
]
.-=
values
(
s
)
s
=
m
.
reactions
[
cols
[
col
]]
.
products
S
[
getindex
.
(
Ref
(
rowsd
),
keys
(
s
)),
col
]
.+=
values
(
s
)
end
return
rows
,
cols
,
S
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment