Commit 3a17bb05 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

rename the abstract type to avoid ambiguity

parent 2f461a6b
""" """
fluxBalanceAnalysis(model::LM, optimizer) where {LM<:AbstractCobraModel} fluxBalanceAnalysis(model::LM, optimizer) where {LM<:MetabolicModel}
Flux balance analysis solves the following problem for the input `model`: Flux balance analysis solves the following problem for the input `model`:
``` ```
...@@ -10,5 +10,5 @@ s.t. S x = b ...@@ -10,5 +10,5 @@ s.t. S x = b
Returns a solved model from [`optimizeModel`](@ref). Returns a solved model from [`optimizeModel`](@ref).
""" """
fluxBalanceAnalysis(model::LM, optimizer) where {LM<:AbstractCobraModel} = fluxBalanceAnalysis(model::LM, optimizer) where {LM<:MetabolicModel} =
optimizeModel(model, optimizer; sense = MOI.MAX_SENSE) optimizeModel(model, optimizer; sense = MOI.MAX_SENSE)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
optimizer, optimizer,
workers = [myid()]; workers = [myid()];
gamma::AbstractFloat = 1.0, gamma::AbstractFloat = 1.0,
)::Matrix{Float64} where {LM<:AbstractCobraModel} )::Matrix{Float64} where {LM<:MetabolicModel}
# Flux variability analysis (FVA) # Flux variability analysis (FVA)
...@@ -31,7 +31,7 @@ function fluxVariabilityAnalysis( ...@@ -31,7 +31,7 @@ function fluxVariabilityAnalysis(
optimizer, optimizer,
workers = [myid()]; workers = [myid()];
gamma::AbstractFloat = 1.0, gamma::AbstractFloat = 1.0,
)::Matrix{Float64} where {LM<:AbstractCobraModel} )::Matrix{Float64} where {LM<:MetabolicModel}
if any(reactions .< 1) || any(reactions .> nReactions(model)) if any(reactions .< 1) || any(reactions .> nReactions(model))
throw(DomainError(reactions, "Index exceeds number of reactions.")) throw(DomainError(reactions, "Index exceeds number of reactions."))
...@@ -70,7 +70,7 @@ end ...@@ -70,7 +70,7 @@ end
model::LM, model::LM,
optimizer; optimizer;
gamma::AbstractFloat = 1.0, gamma::AbstractFloat = 1.0,
) where {LM<:AbstractCobraModel} ) where {LM<:MetabolicModel}
A simpler version of FVA that maximizes and minimizes all reactions in the model. A simpler version of FVA that maximizes and minimizes all reactions in the model.
""" """
...@@ -78,7 +78,7 @@ function fluxVariabilityAnalysis( ...@@ -78,7 +78,7 @@ function fluxVariabilityAnalysis(
model::LM, model::LM,
optimizer; optimizer;
gamma::AbstractFloat = 1.0, gamma::AbstractFloat = 1.0,
) where {LM<:AbstractCobraModel} ) where {LM<:MetabolicModel}
n = nReactions(model) n = nReactions(model)
return fluxVariabilityAnalysis(model, collect(1:n), optimizer; gamma = gamma) return fluxVariabilityAnalysis(model, collect(1:n), optimizer; gamma = gamma)
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
model::LM, model::LM,
optimizer; optimizer;
sense = MOI.MAX_SENSE, sense = MOI.MAX_SENSE,
) where {LM<:AbstractCobraModel} ) where {LM<:MetabolicModel}
Convert LinearModel to a JuMP model, and place objectives, flux bounds and Convert LinearModel to a JuMP model, and place objectives, flux bounds and
equality "balance" constraint. equality "balance" constraint.
...@@ -12,7 +12,7 @@ function makeOptimizationModel( ...@@ -12,7 +12,7 @@ function makeOptimizationModel(
model::LM, model::LM,
optimizer; optimizer;
sense = MOI.MAX_SENSE, sense = MOI.MAX_SENSE,
) where {LM<:AbstractCobraModel} ) where {LM<:MetabolicModel}
m, n = size(stoichiometry(model)) m, n = size(stoichiometry(model))
xl, xu = bounds(model) xl, xu = bounds(model)
...@@ -25,12 +25,12 @@ function makeOptimizationModel( ...@@ -25,12 +25,12 @@ function makeOptimizationModel(
end end
""" """
optimizeModel(model::LM, optimizer; sense = MOI.MIN_SENSE) where {LM<:AbstractCobraModel} optimizeModel(model::LM, optimizer; sense = MOI.MIN_SENSE) where {LM<:MetabolicModel}
Use JuMP to optimize an instance of a COBRA model. Returns a tuple that Use JuMP to optimize an instance of a [`MetabolicModel`](@ref). Returns a tuple
contains the new model and a vector of its variables. that contains the new model and a vector of its variables.
""" """
function optimizeModel(model::LM, optimizer; sense = MOI.MIN_SENSE) where {LM<:AbstractCobraModel} function optimizeModel(model::LM, optimizer; sense = MOI.MIN_SENSE) where {LM<:MetabolicModel}
optimization_model, x = makeOptimizationModel(model, optimizer; sense = sense) optimization_model, x = makeOptimizationModel(model, optimizer; sense = sense)
JuMP.optimize!(optimization_model) JuMP.optimize!(optimization_model)
return (optimization_model, x) return (optimization_model, x)
......
""" """
abstract type AbstractCobraModel end abstract type MetabolicModel end
A helper supertype that wraps everything usable as a linear-like model for A helper supertype that wraps everything usable as a linear-like model for
COBREXA functions. If you want to use your own type, make it a subtype (so that COBREXA functions. If you want to use your own type, make it a subtype (so that
the functions typecheck) and add instances for the data accessor methods below. the functions typecheck) and add instances for the data accessor methods below.
""" """
abstract type AbstractCobraModel end abstract type MetabolicModel end
const SparseMat = SparseMatrixCSC{Float64,Int} const SparseMat = SparseMatrixCSC{Float64,Int}
const SparseVec = SparseVector{Float64,Int} const SparseVec = SparseVector{Float64,Int}
...@@ -17,101 +17,101 @@ const StringVecType = AbstractVector{String} ...@@ -17,101 +17,101 @@ const StringVecType = AbstractVector{String}
_missingImplError = (m, a) -> throw(MethodError(m, a)) _missingImplError = (m, a) -> throw(MethodError(m, a))
""" """
reactions(a::LM)::Vector{String} where {LM<:AbstractCobraModel} reactions(a::LM)::Vector{String} where {LM<:MetabolicModel}
Return a vector of reaction identifiers in a model. Return a vector of reaction identifiers in a model.
""" """
function reactions(a::LM)::Vector{String} where {LM<:AbstractCobraModel} function reactions(a::LM)::Vector{String} where {LM<:MetabolicModel}
_missingImplError(reactions, (a,)) _missingImplError(reactions, (a,))
end end
""" """
metabolites(a::LM)::Vector{String} where {LM<:AbstractCobraModel} metabolites(a::LM)::Vector{String} where {LM<:MetabolicModel}
Return a vector of metabolite identifiers in a model. Return a vector of metabolite identifiers in a model.
""" """
function metabolites(a::LM)::Vector{String} where {LM<:AbstractCobraModel} function metabolites(a::LM)::Vector{String} where {LM<:MetabolicModel}
_missingImplError(metabolites, (a,)) _missingImplError(metabolites, (a,))
end end
""" """
nReactions(a::LM)::Int where {LM<:AbstractCobraModel} nReactions(a::LM)::Int where {LM<:MetabolicModel}
Get the number of reactions in a model. Get the number of reactions in a model.
""" """
function nReactions(a::LM)::Int where {LM<:AbstractCobraModel} function nReactions(a::LM)::Int where {LM<:MetabolicModel}
length(reactions(a)) length(reactions(a))
end end
""" """
nMetabolites(a::LM)::Int where {LM<:AbstractCobraModel} nMetabolites(a::LM)::Int where {LM<:MetabolicModel}
Get the number of metabolites in a model. Get the number of metabolites in a model.
""" """
function nMetabolites(a::LM)::Int where {LM<:AbstractCobraModel} function nMetabolites(a::LM)::Int where {LM<:MetabolicModel}
length(metabolites(a)) length(metabolites(a))
end end
""" """
stoichiometry(a::LM)::SparseMat where {LM<:AbstractCobraModel} stoichiometry(a::LM)::SparseMat where {LM<:MetabolicModel}
Get the sparse stoichiometry matrix of a model. Get the sparse stoichiometry matrix of a model.
""" """
function stoichiometry(a::LM)::SparseMat where {LM<:AbstractCobraModel} function stoichiometry(a::LM)::SparseMat where {LM<:MetabolicModel}
_missingImplError(stoichiometry, (a,)) _missingImplError(stoichiometry, (a,))
end end
""" """
bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:AbstractCobraModel} bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:MetabolicModel}
Get the lower and upper flux bounds of a model. Get the lower and upper flux bounds of a model.
""" """
function bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:AbstractCobraModel} function bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:MetabolicModel}
_missingImplError(bounds, (a,)) _missingImplError(bounds, (a,))
end end
""" """
balance(a::LM)::SparseVec where {LM<:AbstractCobraModel} balance(a::LM)::SparseVec where {LM<:MetabolicModel}
Get the sparse balance vector of a model (ie. the `b` from `S x = b`). Get the sparse balance vector of a model (ie. the `b` from `S x = b`).
""" """
function balance(a::LM)::SparseVec where {LM<:AbstractCobraModel} function balance(a::LM)::SparseVec where {LM<:MetabolicModel}
_missingImplError(balance, (a,)) _missingImplError(balance, (a,))
end end
""" """
objective(a::LM)::SparseVec where {LM<:AbstractCobraModel} objective(a::LM)::SparseVec where {LM<:MetabolicModel}
Get the objective vector of a model. Get the objective vector of a model.
""" """
function objective(a::LM)::SparseVec where {LM<:AbstractCobraModel} function objective(a::LM)::SparseVec where {LM<:MetabolicModel}
_missingImplError(objective, (a,)) _missingImplError(objective, (a,))
end end
""" """
coupling(a::LM)::SparseMat where {LM<:AbstractCobraModel} coupling(a::LM)::SparseMat where {LM<:MetabolicModel}
Get a matrix of coupling constraint definitions of a model. Get a matrix of coupling constraint definitions of a model.
""" """
function coupling(a::LM)::SparseMat where {LM<:AbstractCobraModel} function coupling(a::LM)::SparseMat where {LM<:MetabolicModel}
_missingImplError(coupling, (a,)) _missingImplError(coupling, (a,))
end end
""" """
nCouplingConstraints(a::LM)::Int where {LM<:AbstractCobraModel} nCouplingConstraints(a::LM)::Int where {LM<:MetabolicModel}
Get the number of coupling constraints in a model. Get the number of coupling constraints in a model.
""" """
function nCouplingConstraints(a::LM)::Int where {LM<:AbstractCobraModel} function nCouplingConstraints(a::LM)::Int where {LM<:MetabolicModel}
size(coupling(a), 1) size(coupling(a), 1)
end end
""" """
couplingBounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:AbstractCobraModel} couplingBounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:MetabolicModel}
Get the lower and upper bounds for each coupling bound in a model, as specified Get the lower and upper bounds for each coupling bound in a model, as specified
by `coupling`. by `coupling`.
""" """
function couplingBounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:AbstractCobraModel} function couplingBounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:MetabolicModel}
_missingImplError(couplingBounds, (a,)) _missingImplError(couplingBounds, (a,))
end end
""" """
struct LinearModel <: AbstractCobraModel struct LinearModel <: MetabolicModel
A concrete linear optimization problem of the form: A concrete linear optimization problem of the form:
``` ```
...@@ -10,7 +10,7 @@ s.t. S x = b ...@@ -10,7 +10,7 @@ s.t. S x = b
xₗ ≤ x ≤ xᵤ xₗ ≤ x ≤ xᵤ
``` ```
""" """
mutable struct LinearModel <: AbstractCobraModel mutable struct LinearModel <: MetabolicModel
S::SparseMat S::SparseMat
b::SparseVec b::SparseVec
C::SparseMat C::SparseMat
......
struct FakeModel <: AbstractCobraModel struct FakeModel <: MetabolicModel
dummy::Int dummy::Int
end end
......
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