Skip to content

Commit

Permalink
cleanup start
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jan 2, 2024
1 parent 830b36f commit 0e13090
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 41 deletions.
19 changes: 10 additions & 9 deletions src/COBREXA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,25 @@ include("io.jl")
include("solver.jl")

# these functions build or extend constrainttrees of metabolic models
include("builders/core.jl")
include("builders/genes.jl")
include("builders/objectives.jl")
include("builders/communities.jl")
include("builders/enzymes.jl")
include("builders/thermodynamic.jl")
include("builders/fbc.jl")
include("builders/knockouts.jl")
include("builders/loopless.jl")
include("builders/communities.jl")
include("builders/objectives.jl")
include("builders/thermodynamic.jl")
include("builders/unsigned.jl")

# these are the one shot analysis functions
include("frontend/flux_balance_analysis.jl")
include("frontend/parsimonious_flux_balance.jl")
include("frontend/minimization_of_metabolic_adjustment_analysis.jl")
include("frontend/enzyme_constrained_flux_balance_analysis.jl")
include("frontend/flux_balance_analysis.jl")
include("frontend/loopless_flux_balance_analysis.jl")
include("frontend/max_min_driving_force_analysis.jl")
include("frontend/minimization_of_metabolic_adjustment_analysis.jl")
include("frontend/parsimonious_flux_balance.jl")

include("misc/modifications.jl")
include("misc/bounds.jl")
include("misc/modifications.jl")
include("misc/utils.jl")

end # module COBREXA
47 changes: 47 additions & 0 deletions src/builders/fbc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# Copyright (c) 2021-2024, University of Luxembourg
# Copyright (c) 2021-2024, Heinrich-Heine University Duesseldorf
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
$(TYPEDSIGNATURES)
A constraint tree that models the content of the given instance of
`AbstractFBCModel`.
The constructed tree contains subtrees `fluxes` (with the reaction-defining
"variables") and `flux_stoichiometry` (with the metabolite-balance-defining
constraints), and a single constraint `objective` thad describes the objective
function of the model.
"""
function fbc_model_constraints(model::A.AbstractFBCModel)
rxns = Symbol.(A.reactions(model))
mets = Symbol.(A.metabolites(model))
lbs, ubs = A.bounds(model)
stoi = A.stoichiometry(model)
bal = A.balance(model)
obj = A.objective(model)

#TODO: is sparse() required below?
return C.ConstraintTree(
:fluxes^C.variables(keys = rxns, bounds = zip(lbs, ubs)) *
:flux_stoichiometry^C.ConstraintTree(
met => C.Constraint(value = C.LinearValue(sparse(row)), bound = C.EqualTo(b))
for (met, row, b) in zip(mets, eachrow(stoi), bal)
) *
:objective^C.Constraint(C.LinearValue(sparse(obj))),
)
end

export fbc_model_constraints
File renamed without changes.
33 changes: 1 addition & 32 deletions src/builders/core.jl → src/builders/unsigned.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,6 @@
"""
$(TYPEDSIGNATURES)
A constraint tree that models the content of the given instance of
`AbstractFBCModel`.
The constructed tree contains subtrees `fluxes` (with the reaction-defining
"variables") and `flux_stoichiometry` (with the metabolite-balance-defining
constraints), and a single constraint `objective` thad describes the objective
function of the model.
"""
function fbc_model_constraints(model::A.AbstractFBCModel)
rxns = Symbol.(A.reactions(model))
mets = Symbol.(A.metabolites(model))
lbs, ubs = A.bounds(model)
stoi = A.stoichiometry(model)
bal = A.balance(model)
obj = A.objective(model)

#TODO: is sparse() required below?
return C.ConstraintTree(
:fluxes^C.variables(keys = rxns, bounds = zip(lbs, ubs)) *
:flux_stoichiometry^C.ConstraintTree(
met => C.Constraint(value = C.LinearValue(sparse(row)), bound = C.EqualTo(b))
for (met, row, b) in zip(mets, eachrow(stoi), bal)
) *
:objective^C.Constraint(C.LinearValue(sparse(obj))),
)
end

export fbc_model_constraints

"""
$(TYPEDSIGNATURES)
Shortcut for allocation non-negative ("unsigned") variables. The argument
`keys` is forwarded to `ConstraintTrees.variables` as `keys`.
"""
Expand Down Expand Up @@ -97,6 +65,7 @@ sign_split_constraints(;

export sign_split_constraints

# TODO: docs, doesn't apply to fluxes only
function fluxes_in_direction(fluxes::C.ConstraintTree, direction = :forward)
keys = Symbol[]
for (id, flux) in fluxes
Expand Down

0 comments on commit 0e13090

Please sign in to comment.