Commit 39f0ea09 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil 🚴
Browse files

output sparse S matrix

parent 2263ee90
......@@ -39,6 +39,10 @@ git-tree-sha1 = "8e924324b2e9275a51407a4e06deb3455b1e359f"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.0+7"
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
......@@ -77,6 +81,10 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
......@@ -8,6 +8,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SBML_jll = "bb12108a-f4ef-5f88-8ef3-0b33ff7017f1"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
module SBML
using SBML_jll, Libdl, Pkg
using SparseArrays
function getS(m::Model)::Tuple{Vector{String},Vector{String},Matrix{Float64}}
function getS(m::Model; zeros=spzeros)::Tuple{Vector{String},Vector{String},AbstractMatrix{Float64}}
Extract the vector of species (aka metabolite) identifiers, vector of reaction
identifiers, and the (dense) stoichiometry matrix from an existing `Model`.
Returns a tuple with these values.
function getS(m::Model)::Tuple{Vector{String},Vector{String},Matrix{Float64}}
#TODO this will need a sparse version and faster row ID lookup
rows = [k for k in keys(m.species)] #TODO this too
The matrix is sparse by default (initially constructed by
`SparseArrays.spzeros`). You can fill in a custom empty matrix constructed to
argument `zeros`; e.g. running with `zeros=zeros` will produce a dense matrix.
function getS(
zeros = spzeros,
rows = [k for k in keys(m.species)]
cols = [k for k in keys(m.reactions)]
rowsd = Dict(k => i for (i, k) in enumerate(rows))
S = zeros(Float64, length(rows), length(cols))
for ri = 1:length(cols)
stoi = m.reactions[cols[ri]].stoichiometry
S[indexin(keys(stoi), rows), ri] .= values(stoi)
for col = 1:length(cols)
stoi = m.reactions[cols[col]].stoichiometry
S[getindex.(Ref(rowsd), keys(stoi)), col] .= values(stoi)
return rows, cols, S
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment