Unverified Commit 523c6eb0 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #521 from LCSB-BioCore/tp-grr-coremodel

Gene-reaction rules for CoreModel and CoreModelCoupled #439
parents 0cb74ae7 94c43617
Pipeline #49935 passed with stages
in 23 minutes and 54 seconds
......@@ -18,6 +18,7 @@ mutable struct CoreModel <: MetabolicModel
xu::Vector{Float64}
rxns::Vector{String}
mets::Vector{String}
grrs::Vector{Maybe{GeneAssociation}}
function CoreModel(
S::MatType,
......@@ -27,14 +28,19 @@ mutable struct CoreModel <: MetabolicModel
xu::VecType,
rxns::StringVecType,
mets::StringVecType,
grrs::Vector{Maybe{GeneAssociation}} = Vector{Maybe{GeneAssociation}}(
nothing,
length(rxns),
),
)
all([length(b), length(mets)] .== size(S, 1)) ||
throw(DimensionMismatch("inconsistent number of metabolites"))
all([length(c), length(xl), length(xu), length(rxns)] .== size(S, 2)) ||
throw(DimensionMismatch("inconsistent number of reactions"))
all(
[length(c), length(xl), length(xu), length(rxns), length(grrs)] .== size(S, 2),
) || throw(DimensionMismatch("inconsistent number of reactions"))
new(sparse(S), sparse(b), sparse(c), collect(xl), collect(xu), rxns, mets)
new(sparse(S), sparse(b), sparse(c), collect(xl), collect(xu), rxns, mets, grrs)
end
end
......@@ -96,6 +102,31 @@ Return the stoichiometry of reaction at index `ridx`.
reaction_stoichiometry(m::CoreModel, ridx)::Dict{String,Float64} =
Dict(m.mets[k] => v for (k, v) in zip(findnz(m.S[:, ridx])...))
"""
reaction_gene_association_vec(model::CoreModel)::Vector{Maybe{GeneAssociation}}
Retrieve a vector of all gene associations in a [`CoreModel`](@ref), in the
same order as `reactions(model)`.
"""
reaction_gene_association_vec(model::CoreModel)::Vector{Maybe{GeneAssociation}} = model.grrs
"""
reaction_gene_association(model::CoreModel, ridx::Int)::Maybe{GeneAssociation}
Retrieve the [`GeneAssociation`](@ref) from [`CoreModel`](@ref) by reaction
index.
"""
reaction_gene_association(model::CoreModel, ridx::Int)::Maybe{GeneAssociation} =
model.grrs[ridx]
"""
reaction_gene_association(model::CoreModel, rid::String)::Maybe{GeneAssociation}
Retrieve the [`GeneAssociation`](@ref) from [`CoreModel`](@ref) by reaction ID.
"""
reaction_gene_association(model::CoreModel, rid::String)::Maybe{GeneAssociation} =
model.grrs[first(indexin([rid], model.rxns))]
"""
Base.convert(::Type{CoreModel}, m::M) where {M <: MetabolicModel}
......@@ -115,5 +146,8 @@ function Base.convert(::Type{CoreModel}, m::M) where {M<:MetabolicModel}
xu,
reactions(m),
metabolites(m),
Vector{Maybe{GeneAssociation}}([
reaction_gene_association(m, id) for id in reactions(m)
]),
)
end
......@@ -108,6 +108,32 @@ function reaction_stoichiometry(m::CoreModelCoupled, ridx)::Dict{String,Float64}
reaction_stoichiometry(m.lm, ridx)
end
"""
reaction_gene_association_vec(model::CoreModelCoupled)::Vector{Maybe{GeneAssociation}}
Retrieve a vector of gene associations in a [`CoreModelCoupled`](@ref), in the
same order as `reactions(model)`.
"""
reaction_gene_association_vec(model::CoreModelCoupled)::Vector{Maybe{GeneAssociation}} =
reaction_gene_association_vec(model.lm)
"""
reaction_gene_association(model::CoreModelCoupled, ridx::Int)::Maybe{GeneAssociation}
Retrieve the [`GeneAssociation`](@ref) from [`CoreModelCoupled`](@ref) by reaction
index.
"""
reaction_gene_association(model::CoreModelCoupled, ridx::Int)::Maybe{GeneAssociation} =
reaction_gene_association(model.lm, ridx)
"""
reaction_gene_association(model::CoreModelCoupled, rid::String)::Maybe{GeneAssociation}
Retrieve the [`GeneAssociation`](@ref) from [`CoreModelCoupled`](@ref) by reaction ID.
"""
reaction_gene_association(model::CoreModelCoupled, rid::String)::Maybe{GeneAssociation} =
reaction_gene_association(model.lm, rid)
"""
Base.convert(::Type{CoreModelCoupled}, mm::MetabolicModel)
......
......@@ -4,3 +4,16 @@
@test reaction_stoichiometry(model, "EX_ac_e") == Dict("ac_e" => -1)
@test reaction_stoichiometry(model, 44) == Dict("ac_e" => -1)
end
@testset "Conversion from and to StandardModel" begin
cm = load_model(CoreModel, model_paths["e_coli_core.mat"])
sm = convert(StandardModel, cm)
cm2 = convert(CoreModel, sm)
@test Set(reactions(cm)) == Set(reactions(sm))
@test Set(reactions(cm)) == Set(reactions(cm2))
@test reaction_gene_association(sm, reactions(sm)[1]) ==
reaction_gene_association(cm, reactions(sm)[1])
end
......@@ -5,3 +5,27 @@
@test reaction_stoichiometry(model, 44) == Dict("ac_e" => -1)
end
@testset "Conversion from and to StandardModel" begin
cm = load_model(CoreModelCoupled, model_paths["e_coli_core.mat"])
sm = convert(StandardModel, cm)
cm2 = convert(CoreModelCoupled, sm)
@test Set(reactions(cm)) == Set(reactions(sm))
@test Set(reactions(cm)) == Set(reactions(cm2))
@test reaction_gene_association(sm, reactions(sm)[1]) ==
reaction_gene_association(cm, reactions(sm)[1])
@test reaction_gene_association_vec(cm)[1:3] == [
[["b3916"], ["b1723"]],
[
["b0902", "b0903", "b2579"],
["b0902", "b0903"],
["b0902", "b3114"],
["b3951", "b3952"],
],
[["b4025"]],
]
end
Markdown is supported
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