From 31a8ff87e2873d6ad65f52fb3c40d8e51dcfaa72 Mon Sep 17 00:00:00 2001 From: Hritik Bana <79982592+hritikb@users.noreply.github.com> Date: Wed, 22 May 2024 15:35:57 +0530 Subject: [PATCH] rename biomass_function to objective_function, fixes issue #82 (#97) --- README.md | 2 +- dingo/MetabolicNetwork.py | 26 +++++++++++++------------- dingo/PolytopeSampler.py | 26 +++++++++++++------------- tutorials/dingo_tutorial.ipynb | 12 ++++++------ 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 1dbe7733..6dea67be 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ You could also set an alternative objective function. For example, to maximize t n = model.num_of_reactions() obj_fun = np.zeros(n) obj_fun[0] = 1 -model.biomass_function(obj_fun) +model.objective_function(obj_fun) # apply FVA using the new objective function fva_output = model.fva() diff --git a/dingo/MetabolicNetwork.py b/dingo/MetabolicNetwork.py index eec1a8b5..518f2f5b 100644 --- a/dingo/MetabolicNetwork.py +++ b/dingo/MetabolicNetwork.py @@ -47,7 +47,7 @@ def __init__(self, tuple_args): self._metabolites = tuple_args[3] self._reactions = tuple_args[4] self._biomass_index = tuple_args[5] - self._biomass_function = tuple_args[6] + self._objective_function = tuple_args[6] self._medium = tuple_args[7] self._medium_indices = tuple_args[8] self._exchanges = tuple_args[9] @@ -58,9 +58,9 @@ def __init__(self, tuple_args): or self._lb.size != self._S.shape[1] or len(self._metabolites) != self._S.shape[0] or len(self._reactions) != self._S.shape[1] - or self._biomass_function.size != self._S.shape[1] + or self._objective_function.size != self._S.shape[1] or (self._biomass_index < 0) - or (self._biomass_index > self._biomass_function.size) + or (self._biomass_index > self._objective_function.size) ): raise Exception( "Wrong tuple format given to initialize a metabolic network object." @@ -112,7 +112,7 @@ def fva(self): self._lb, self._ub, self._S, - self._biomass_function, + self._objective_function, self._parameters["opt_percentage"], ) else: @@ -120,7 +120,7 @@ def fva(self): self._lb, self._ub, self._S, - self._biomass_function, + self._objective_function, self._parameters["opt_percentage"], ) @@ -128,9 +128,9 @@ def fba(self): """A member function to apply the FBA method on the metabolic network.""" if self._parameters["fast_computations"]: - return fast_fba(self._lb, self._ub, self._S, self._biomass_function) + return fast_fba(self._lb, self._ub, self._S, self._objective_function) else: - return slow_fba(self._lb, self._ub, self._S, self._biomass_function) + return slow_fba(self._lb, self._ub, self._S, self._objective_function) @property def lb(self): @@ -157,8 +157,8 @@ def biomass_index(self): return self._biomass_index @property - def biomass_function(self): - return self._biomass_function + def objective_function(self): + return self._objective_function @property def medium(self): @@ -181,7 +181,7 @@ def get_as_tuple(self): self._metabolites, self._reactions, self._biomass_index, - self._biomass_function, + self._objective_function, self._medium, self._inter_medium, self._exchanges @@ -217,9 +217,9 @@ def reactions(self, value): def biomass_index(self, value): self._biomass_index = value - @biomass_function.setter - def biomass_function(self, value): - self._biomass_function = value + @objective_function.setter + def objective_function(self, value): + self._objective_function = value @medium.setter diff --git a/dingo/PolytopeSampler.py b/dingo/PolytopeSampler.py index 4fe9dca7..54f30050 100644 --- a/dingo/PolytopeSampler.py +++ b/dingo/PolytopeSampler.py @@ -77,8 +77,8 @@ def get_polytope(self): ): ( - max_biomass_flux_vector, - max_biomass_objective, + max_flux_vector, + max_objective, ) = self._metabolic_network.fba() if ( @@ -90,7 +90,7 @@ def get_polytope(self): self._metabolic_network.lb, self._metabolic_network.ub, self._metabolic_network.S, - self._metabolic_network.biomass_function, + self._metabolic_network.objective_function, self._parameters["opt_percentage"], ) else: @@ -104,8 +104,8 @@ def get_polytope(self): ( min_fluxes, max_fluxes, - max_biomass_flux_vector, - max_biomass_objective, + max_flux_vector, + max_objective, ) = self._metabolic_network.fva() A, b, Aeq, beq = get_matrices_of_low_dim_polytope( @@ -123,11 +123,11 @@ def get_polytope(self): ): raise Exception("Preprocess for full dimensional polytope failed.") - A = np.vstack((A, -self._metabolic_network.biomass_function)) + A = np.vstack((A, -self._metabolic_network.objective_function)) b = np.append( b, - -np.floor(max_biomass_objective / self._parameters["tol"]) + -np.floor(max_objective / self._parameters["tol"]) * self._parameters["tol"] * self._parameters["opt_percentage"] / 100, @@ -293,8 +293,8 @@ def round_polytope( def sample_from_fva_output( min_fluxes, max_fluxes, - biomass_function, - max_biomass_objective, + objective_function, + max_objective, S, opt_percentage=100, ess=1000, @@ -307,8 +307,8 @@ def sample_from_fva_output( Keyword arguments: min_fluxes -- minimum values of the fluxes, i.e., a n-dimensional vector max_fluxes -- maximum values for the fluxes, i.e., a n-dimensional vector - biomass_function -- the biomass objective function - max_biomass_objective -- the maximum value of the biomass objective function + objective_function -- the objective function + max_objective -- the maximum value of the objective function S -- stoichiometric matrix opt_percentage -- consider solutions that give you at least a certain percentage of the optimal solution (default is to consider @@ -323,12 +323,12 @@ def sample_from_fva_output( S, min_fluxes, max_fluxes, opt_percentage, tol ) - A = np.vstack((A, -biomass_function)) + A = np.vstack((A, -objective_function)) b = np.append( b, -(opt_percentage / 100) * self._parameters["tol"] - * math.floor(max_biomass_objective / self._parameters["tol"]), + * math.floor(max_objective / self._parameters["tol"]), ) A, b, N, N_shift = get_matrices_of_full_dim_polytope(A, b, Aeq, beq) diff --git a/tutorials/dingo_tutorial.ipynb b/tutorials/dingo_tutorial.ipynb index 1b1b7e5a..e79cd784 100644 --- a/tutorials/dingo_tutorial.ipynb +++ b/tutorials/dingo_tutorial.ipynb @@ -874,7 +874,7 @@ }, "outputs": [], "source": [ - "model.biomass_function" + "model.objective_function" ] }, { @@ -1118,7 +1118,7 @@ "id": "jWEhcWmJm1Qu" }, "source": [ - "Now we can replace the `biomass_function` parameter of our model with our new objective function" + "Now we can replace the `objective_function` parameter of our model with our new objective function" ] }, { @@ -1129,7 +1129,7 @@ }, "outputs": [], "source": [ - "model.biomass_function = obj_fun" + "model.objective_function = obj_fun" ] }, { @@ -1153,7 +1153,7 @@ }, "outputs": [], "source": [ - "model.biomass_function" + "model.objective_function" ] }, { @@ -1249,7 +1249,7 @@ "\n", "**Remember!** \n", "\n", - "In the previous step, we replaced the `biomass_function` of our model. So if we run FVA in our current model, then the first reaction of our model " + "In the previous step, we replaced the `objective_function` of our model. So if we run FVA in our current model, then the first reaction of our model " ] }, { @@ -1279,7 +1279,7 @@ "id": "qGVto8ckp7LS" }, "source": [ - "We can go with that or if we need to go back in using the actual biomass function of our model, we can either do the same process as before to change again the `biomass_function` or we can just build a new instance of the `MetabolicNetwork` class. " + "We can go with that or if we need to go back in using the actual biomass function of our model, we can either do the same process as before to change again the `objective_function` or we can just build a new instance of the `MetabolicNetwork` class. " ] }, {