Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary docstrings #754

Merged
merged 22 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/types/accessors/AbstractMetabolicModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"""
$(TYPEDSIGNATURES)

Return a vector of reaction identifiers in a model. The vector precisely
Return a vector of variable identifiers in a model. The vector precisely
corresponds to the columns in [`stoichiometry`](@ref) matrix.

For technical reasons, the "reactions" may sometimes not be true reactions but
various virtual and helper pseudo-reactions that are used in the metabolic
modeling, such as metabolite exchanges, separate forward and reverse reactions,
supplies of enzymatic and genetic material and virtual cell volume, etc. To
simplify the view of the model contents use [`reaction_variables`](@ref).
Usually, variables correspond to reactions. However, for technical reasons, the
reactions may sometimes not be true reactions, but various virtual and helper
pseudo-reactions that are used in the metabolic modeling, such as metabolite
exchanges, separate forward and reverse reactions, supplies of enzymatic and
genetic material and virtual cell volume, etc. To simplify the view of the model
contents use [`reaction_variables`](@ref).
"""
function variables(a::AbstractMetabolicModel)::Vector{String}
missing_impl_error(variables, (a,))
Expand Down Expand Up @@ -59,13 +60,7 @@ end
"""
$(TYPEDSIGNATURES)

Get the sparse stoichiometry matrix of a model. A feasible solution `x` of a
model `m` is defined as satisfying the equations:

- `stoichiometry(m) * x .== balance(m)`
- `x .>= lbs`
- `y .<= ubs`
- `(lbs, ubs) == bounds(m)
Get the sparse stoichiometry matrix of a model.
"""
function stoichiometry(a::AbstractMetabolicModel)::SparseMat
missing_impl_error(stoichiometry, (a,))
Expand Down
113 changes: 18 additions & 95 deletions src/types/models/BalancedGrowthCommunityModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ $(TYPEDFIELDS)
3. The objective created by this model is the equal growth rate/balanced growth
objective. In short, all biomass metabolites are produced at the same rate.
4. The flux units are `mmol X/gDW_total/h` for some metabolite `X`.

# Implementation notes
1. All reactions have the `id` of each respective underlying
[`CommunityMember`](@ref) appended as a prefix with the delimiter `#`.
Consequently, exchange reactions of the original model will look like
`species1#EX_...`. All exchange environmental reactions have `EX_` as a
prefix followed by the environmental metabolite id.
2. All metabolites have the `id` of each respective underlying
[`CommunityMember`](@ref) appended as a prefix with the delimiter `#`. The
environmental metabolites have no prefix.
3. All genes have the `id` of the respective underlying
[`CommunityMember`](@ref) appended as a prefix with the delimiter `#`.
4. Each bound from the underlying community members is multiplied by the
abundance of that member.
5. This objective is assumed to be the equal growth rate/balanced growth
objective. Consequently, the relation `community_growth *
abundance_species_i = growth_species_i` should hold.
"""
Base.@kwdef mutable struct BalancedGrowthCommunityModel <: AbstractMetabolicModel
"Models making up the community."
Expand All @@ -53,95 +70,43 @@ Base.@kwdef mutable struct BalancedGrowthCommunityModel <: AbstractMetabolicMode
Dict{String,Tuple{Float64,Float64}}()
end

"""
$(TYPEDSIGNATURES)

Return the reactions in `cm`, which is a [`BalancedGrowthCommunityModel`](@ref).
All reactions have the `id` of each respective underlying
[`CommunityMember`](@ref) appended as a prefix with the delimiter `#`.
Consequently, exchange reactions of the original model will look like
`species1#EX_...`. All exchange environmental reactions have `EX_` as a prefix
followed by the environmental metabolite id.
"""
function Accessors.variables(cm::BalancedGrowthCommunityModel)
rxns = [add_community_prefix(m, rid) for m in cm.members for rid in variables(m.model)]
env_exs = ["EX_" * env_met for env_met in get_env_mets(cm)]
return [rxns; env_exs; cm.objective_id]
end

"""
$(TYPEDSIGNATURES)

Return the number of reactions in `cm`, which is a
[`BalancedGrowthCommunityModel`](@ref).
"""
function Accessors.n_variables(cm::BalancedGrowthCommunityModel)
num_model_reactions = sum(n_variables(m.model) for m in cm.members)
# assume each env metabolite gets an env exchange
num_env_metabolites = length(get_env_mets(cm))
return num_model_reactions + num_env_metabolites + 1 # add 1 for the community biomass
end

"""
$(TYPEDSIGNATURES)

Return the metabolites in `cm`, which is a
[`BalancedGrowthCommunityModel`](@ref). All metabolites have the `id` of each
respective underlying [`CommunityMember`](@ref) appended as a prefix with the
delimiter `#`. The environmental metabolites have no prefix.
"""
function Accessors.metabolites(cm::BalancedGrowthCommunityModel)
mets =
[add_community_prefix(m, mid) for m in cm.members for mid in metabolites(m.model)]
return [mets; "ENV_" .* get_env_mets(cm)]
end

"""
$(TYPEDSIGNATURES)

Return the number of metabolites in `cm`, which is a
[`BalancedGrowthCommunityModel`](@ref).
"""
function Accessors.n_metabolites(cm::BalancedGrowthCommunityModel)
num_model_reactions = sum(n_metabolites(m.model) for m in cm.members)
# assume each env metabolite gets an env exchange
num_env_metabolites = length(get_env_mets(cm))
return num_model_reactions + num_env_metabolites
end

"""
$(TYPEDSIGNATURES)

Return the genes in `cm`, which is a [`BalancedGrowthCommunityModel`](@ref). All
genes have the `id` of the respective underlying [`CommunityMember`](@ref)
appended as a prefix with the delimiter `#`.
"""
Accessors.genes(cm::BalancedGrowthCommunityModel) =
[add_community_prefix(m, gid) for m in cm.members for gid in genes(m.model)]

"""
$(TYPEDSIGNATURES)
Return the balance of `cm`, which is a [`BalancedGrowthCommunityModel`](@ref).
"""
Accessors.balance(cm::BalancedGrowthCommunityModel) = [
vcat([balance(m.model) .* m.abundance for m in cm.members]...)
spzeros(length(get_env_mets(cm)))
]

"""
$(TYPEDSIGNATURES)

Return the number of metabolites in `cm`, which is a [`BalancedGrowthCommunityModel`](@ref).
"""
Accessors.n_genes(cm::BalancedGrowthCommunityModel) =
sum(n_genes(m.model) for m in cm.members)

"""
$(TYPEDSIGNATURES)

Return the overall stoichiometric matrix for a [`BalancedGrowthCommunityModel`](@ref), built
from the underlying models.
"""
function Accessors.stoichiometry(cm::BalancedGrowthCommunityModel)
env_mets = get_env_mets(cm)

Expand All @@ -164,14 +129,6 @@ function Accessors.stoichiometry(cm::BalancedGrowthCommunityModel)
]
end

"""
$(TYPEDSIGNATURES)

Returns the simple variable bounds on `cm`. Assumes the objective can only go
forward at maximum rate `constants.default_reaction_bound`. Note, each bound
from the underlying community members is multiplied by the abundance of that
member.
"""
function Accessors.bounds(cm::BalancedGrowthCommunityModel)
models_lbs = vcat([first(bounds(m.model)) .* m.abundance for m in cm.members]...)
models_ubs = vcat([last(bounds(m.model)) .* m.abundance for m in cm.members]...)
Expand All @@ -189,45 +146,21 @@ function Accessors.bounds(cm::BalancedGrowthCommunityModel)
)
end

"""
$(TYPEDSIGNATURES)

Returns the objective of `cm`. This objective is assumed to be the equal growth
rate/balanced growth objective. Consequently, the relation `community_growth *
abundance_species_i = growth_species_i` should hold.
"""
function Accessors.objective(cm::BalancedGrowthCommunityModel)
vec = spzeros(n_variables(cm))
vec[end] = 1.0
return vec
end

"""
$(TYPEDSIGNATURES)

Coupling constraint matrix for a [`BalancedGrowthCommunityModel`](@ref).
"""
function Accessors.coupling(cm::BalancedGrowthCommunityModel)
coups = blockdiag([coupling(m.model) for m in cm.members]...)
n = n_variables(cm)
return [coups spzeros(size(coups, 1), n - size(coups, 2))]
end

"""
$(TYPEDSIGNATURES)

The number of coupling constraints in a [`BalancedGrowthCommunityModel`](@ref).
"""
Accessors.n_coupling_constraints(cm::BalancedGrowthCommunityModel) =
sum(n_coupling_constraints(m.model) for m in cm.members)

"""
$(TYPEDSIGNATURES)

Coupling bounds for a [`BalancedGrowthCommunityModel`](@ref). Note, each bound
from the underlying community members is multiplied by the abundance of that
member.
"""
function Accessors.coupling_bounds(cm::BalancedGrowthCommunityModel)
lbs = vcat([first(coupling_bounds(m.model)) .* m.abundance for m in cm.members]...)
ubs = vcat([last(coupling_bounds(m.model)) .* m.abundance for m in cm.members]...)
Expand All @@ -248,22 +181,12 @@ function Accessors.reaction_variables_matrix(cm::BalancedGrowthCommunityModel)
blockdiag(rfs, spdiagm(fill(1, nr)))
end

"""
$(TYPEDSIGNATURES)

Returns the semantically meaningful reactions of the model.
"""
Accessors.reactions(cm::BalancedGrowthCommunityModel) = [
vcat([add_community_prefix.(Ref(m), reactions(m.model)) for m in cm.members]...)
["EX_" * env_met for env_met in get_env_mets(cm)]
cm.objective_id
]

"""
$(TYPEDSIGNATURES)

Return the semantically meaningful reactions of the model.
"""
Accessors.n_reactions(cm::BalancedGrowthCommunityModel) =
sum(n_reactions(m.model) for m in cm.members) + length(get_env_mets(cm)) + 1

Expand All @@ -290,7 +213,7 @@ for (func, def) in (
(:metabolite_name, nothing),
(:gene_name, nothing),
)
@eval begin # TODO add docstrings somehow
@eval begin
Accessors.$func(cm::BalancedGrowthCommunityModel, id::String) =
access_community_member(cm, id, $func; default = $def)
end
Expand Down
Loading