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`:
```
......@@ -10,5 +10,5 @@ s.t. S x = b
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)
......@@ -5,7 +5,7 @@
optimizer,
workers = [myid()];
gamma::AbstractFloat = 1.0,
)::Matrix{Float64} where {LM<:AbstractCobraModel}
)::Matrix{Float64} where {LM<:MetabolicModel}
# Flux variability analysis (FVA)
......@@ -31,7 +31,7 @@ function fluxVariabilityAnalysis(
optimizer,
workers = [myid()];
gamma::AbstractFloat = 1.0,
)::Matrix{Float64} where {LM<:AbstractCobraModel}
)::Matrix{Float64} where {LM<:MetabolicModel}
if any(reactions .< 1) || any(reactions .> nReactions(model))
throw(DomainError(reactions, "Index exceeds number of reactions."))
......@@ -70,7 +70,7 @@ end
model::LM,
optimizer;
gamma::AbstractFloat = 1.0,
) where {LM<:AbstractCobraModel}
) where {LM<:MetabolicModel}
A simpler version of FVA that maximizes and minimizes all reactions in the model.
"""
......@@ -78,7 +78,7 @@ function fluxVariabilityAnalysis(
model::LM,
optimizer;
gamma::AbstractFloat = 1.0,
) where {LM<:AbstractCobraModel}
) where {LM<:MetabolicModel}
n = nReactions(model)
return fluxVariabilityAnalysis(model, collect(1:n), optimizer; gamma = gamma)
end
......
......@@ -3,7 +3,7 @@
model::LM,
optimizer;
sense = MOI.MAX_SENSE,
) where {LM<:AbstractCobraModel}
) where {LM<:MetabolicModel}
Convert LinearModel to a JuMP model, and place objectives, flux bounds and
equality "balance" constraint.
......@@ -12,7 +12,7 @@ function makeOptimizationModel(
model::LM,
optimizer;
sense = MOI.MAX_SENSE,
) where {LM<:AbstractCobraModel}
) where {LM<:MetabolicModel}
m, n = size(stoichiometry(model))
xl, xu = bounds(model)
......@@ -25,12 +25,12 @@ function makeOptimizationModel(
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
contains the new model and a vector of its variables.
Use JuMP to optimize an instance of a [`MetabolicModel`](@ref). Returns a tuple
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)
JuMP.optimize!(optimization_model)
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
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.
"""
abstract type AbstractCobraModel end
abstract type MetabolicModel end
const SparseMat = SparseMatrixCSC{Float64,Int}
const SparseVec = SparseVector{Float64,Int}
......@@ -17,101 +17,101 @@ const StringVecType = AbstractVector{String}
_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.
"""
function reactions(a::LM)::Vector{String} where {LM<:AbstractCobraModel}
function reactions(a::LM)::Vector{String} where {LM<:MetabolicModel}
_missingImplError(reactions, (a,))
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.
"""
function metabolites(a::LM)::Vector{String} where {LM<:AbstractCobraModel}
function metabolites(a::LM)::Vector{String} where {LM<:MetabolicModel}
_missingImplError(metabolites, (a,))
end
"""
nReactions(a::LM)::Int where {LM<:AbstractCobraModel}
nReactions(a::LM)::Int where {LM<:MetabolicModel}
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))
end
"""
nMetabolites(a::LM)::Int where {LM<:AbstractCobraModel}
nMetabolites(a::LM)::Int where {LM<:MetabolicModel}
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))
end
"""
stoichiometry(a::LM)::SparseMat where {LM<:AbstractCobraModel}
stoichiometry(a::LM)::SparseMat where {LM<:MetabolicModel}
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,))
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.
"""
function bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:AbstractCobraModel}
function bounds(a::LM)::Tuple{SparseVec,SparseVec} where {LM<:MetabolicModel}
_missingImplError(bounds, (a,))
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`).
"""
function balance(a::LM)::SparseVec where {LM<:AbstractCobraModel}
function balance(a::LM)::SparseVec where {LM<:MetabolicModel}
_missingImplError(balance, (a,))
end
"""
objective(a::LM)::SparseVec where {LM<:AbstractCobraModel}
objective(a::LM)::SparseVec where {LM<:MetabolicModel}
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,))
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.
"""
function coupling(a::LM)::SparseMat where {LM<:AbstractCobraModel}
function coupling(a::LM)::SparseMat where {LM<:MetabolicModel}
_missingImplError(coupling, (a,))
end
"""
nCouplingConstraints(a::LM)::Int where {LM<:AbstractCobraModel}
nCouplingConstraints(a::LM)::Int where {LM<:MetabolicModel}
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)
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
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,))
end
"""
struct LinearModel <: AbstractCobraModel
struct LinearModel <: MetabolicModel
A concrete linear optimization problem of the form:
```
......@@ -10,7 +10,7 @@ s.t. S x = b
xₗ ≤ x ≤ xᵤ
```
"""
mutable struct LinearModel <: AbstractCobraModel
mutable struct LinearModel <: MetabolicModel
S::SparseMat
b::SparseVec
C::SparseMat
......
struct FakeModel <: AbstractCobraModel
struct FakeModel <: MetabolicModel
dummy::Int
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