Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
COBREXA.jl
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LCSB-BioCore
COBREXA.jl
Commits
cf0f49ef
Unverified
Commit
cf0f49ef
authored
3 years ago
by
Miroslav Kratochvil
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #443 from LCSB-BioCore/mk-eff-sparse
more efficient building of sparse stoichiometries
parents
6857bbc6
73774a74
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/base/types/JSONModel.jl
+25
-11
25 additions, 11 deletions
src/base/types/JSONModel.jl
src/base/types/StandardModel.jl
+29
-14
29 additions, 14 deletions
src/base/types/StandardModel.jl
with
54 additions
and
25 deletions
src/base/types/JSONModel.jl
+
25
−
11
View file @
cf0f49ef
...
...
@@ -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
"""
...
...
This diff is collapsed.
Click to expand it.
src/base/types/StandardModel.jl
+
29
−
14
View file @
cf0f49ef
...
...
@@ -108,24 +108,39 @@ n_genes(model::StandardModel)::Int = length(model.genes)
Return the stoichiometric matrix associated with `model` in sparse format.
"""
function
stoichiometry
(
model
::
StandardModel
)
::
SparseMat
S
=
SparseArrays
.
spzeros
(
n_metabolites
(
model
),
n_reactions
(
model
))
mets
=
metabolites
(
model
)
# vector of metabolite ids
n_entries
=
0
for
(
_
,
r
)
in
model
.
reactions
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
)
# establish the ordering
rxns
=
reactions
(
model
)
for
(
i
,
rid
)
in
enumerate
(
rxns
)
# column, in order
met_idx
=
Dict
(
mid
=>
i
for
(
i
,
mid
)
in
enumerate
(
metabolites
(
model
)))
# fill the matrix entries
for
(
ridx
,
rid
)
in
enumerate
(
rxns
)
for
(
mid
,
coeff
)
in
model
.
reactions
[
rid
]
.
metabolites
j
=
findfirst
(
==
(
mid
),
mets
)
# row
if
isnothing
(
j
)
throw
(
DomainError
(
mid
,
"Metabolite
$(mid)
not found in model but occurs in stoichiometry of
$(rid)
"
,
),
)
end
S
[
j
,
i
]
=
coeff
haskey
(
met_idx
,
mid
)
||
throw
(
DomainError
(
mid
,
"Metabolite
$(mid)
not found in model but occurs in stoichiometry of
$(rid)
"
,
),
)
push!
(
MI
,
met_idx
[
mid
])
push!
(
RI
,
ridx
)
push!
(
SV
,
coeff
)
end
end
return
S
return
S
parseArrays
.
sparse
(
MI
,
RI
,
SV
,
n_metabolites
(
model
),
n_reactions
(
model
))
end
"""
...
...
This diff is collapsed.
Click to expand it.
cylon-x
@cylon-x
mentioned in commit
0c4f05c0
·
3 years ago
mentioned in commit
0c4f05c0
mentioned in commit 0c4f05c0d5d55410611e3f09bfd8b7065d6456c6
Toggle commit list
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment