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

Extend community model #696

Merged
merged 7 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions src/io/show/BalancedGrowthCommunityModel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Base.show(io::Base.IO, ::MIME"text/plain", cm::CommunityMember)
stelmo marked this conversation as resolved.
Show resolved Hide resolved
println(
io,
"A $(typeof(cm.model)) community member with $(n_reactions(cm.model)) reactions, $(n_metabolites(cm.model)) metabolites, and abundance $(cm.abundance*100)%.",
)
end

function Base.show(io::Base.IO, ::MIME"text/plain", cm::BalancedGrowthCommunityModel)
println(
io,
"A balanced growth community model comprised of $(length(cm.members)) underlying models.",
)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't very useful, I guess the generic show will suffice for now. I'll eventually make a bigger PR with MultiModelWrapper that fixes this forever

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as in, pls remove the custom shows here)

33 changes: 33 additions & 0 deletions src/reconstruction/ObjectModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,36 @@ function change_objective!(
end

change_objective!(model::ObjectModel, rxn_id::String) = change_objective!(model, [rxn_id])

"""
$(TYPEDSIGNATURES)

Add a biomass metabolite called `biomass_metabolite_id` with stoichiometry 1 to
the biomass reaction, called `biomass_rxn_id` in `model`.
"""
function add_biomass_metabolite!(
model::ObjectModel,
biomass_rxn_id::String;
biomass_metabolite_id = "biomass",
)
model.reactions[biomass_rxn_id].metabolites[biomass_metabolite_id] = 1.0
add_metabolite!(model, Metabolite(biomass_metabolite_id))
end

function add_biomass_metabolite(
model::ObjectModel,
biomass_rxn_id::String;
biomass_metabolite_id = "biomass",
)
m = copy(model)
m.metabolites = copy(m.metabolites)
m.metabolites[biomass_metabolite_id] = Metabolite(biomass_metabolite_id)

m.reactions = copy(model.reactions)
m.reactions[biomass_rxn_id] = copy(model.reactions[biomass_rxn_id])
m.reactions[biomass_rxn_id].metabolites =
copy(model.reactions[biomass_rxn_id].metabolites)
m.reactions[biomass_rxn_id].metabolites[biomass_metabolite_id] = 1.0

m
end
Loading