Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
COBREXA.jl
Commits
939d677b
Commit
939d677b
authored
Aug 18, 2021
by
Miroslav Kratochvil
Browse files
efficient building of JSONModel stoichiometry
parent
f20e41f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/base/types/JSONModel.jl
View file @
939d677b
...
...
@@ -107,22 +107,36 @@ function stoichiometry(model::JSONModel)
rxn_ids
=
reactions
(
model
)
met_ids
=
metabolites
(
model
)
S
=
SparseArrays
.
spzeros
(
length
(
met_ids
),
length
(
rxn_ids
))
n_entries
=
0
for
r
in
model
.
rxns
for
_
in
r
[
"metabolites"
]
n_entries
+=
1
end
end
MI
=
Vector
{
Int
}()
RI
=
Vector
{
Int
}()
SV
=
Vector
{
Float64
}()
sizehint!
(
MI
,
n_entries
)
sizehint!
(
RI
,
n_entries
)
sizehint!
(
SV
,
n_entries
)
for
(
i
,
rid
)
in
enumerate
(
rxn_ids
)
r
=
model
.
rxns
[
model
.
rxn_index
[
rid
]]
for
(
mid
,
coeff
)
in
r
[
"metabolites"
]
if
!
haskey
(
model
.
met_index
,
mid
)
throw
(
DomainError
(
met_id
,
"Unknown metabolite found in stoichiometry of
$
(rxn_ids[i])"
,
),
)
end
S
[
model
.
met_index
[
mid
],
i
]
=
coeff
haskey
(
model
.
met_index
,
mid
)
||
throw
(
DomainError
(
met_id
,
"Unknown metabolite found in stoichiometry of
$
(rxn_ids[i])"
,
),
)
push!
(
MI
,
model
.
met_index
[
mid
])
push!
(
RI
,
i
)
push!
(
SV
,
coeff
)
end
end
return
S
return
S
parseArrays
.
sparse
(
MI
,
RI
,
SV
,
length
(
met_ids
),
length
(
rxn_ids
))
end
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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