Skip to content

Commit

Permalink
rename biomass_function to objective_function, fixes issue #82 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
hritikb committed May 22, 2024
1 parent c51f0a5 commit 31a8ff8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 13 additions & 13 deletions dingo/MetabolicNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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."
Expand Down Expand Up @@ -112,25 +112,25 @@ def fva(self):
self._lb,
self._ub,
self._S,
self._biomass_function,
self._objective_function,
self._parameters["opt_percentage"],
)
else:
return slow_fva(
self._lb,
self._ub,
self._S,
self._biomass_function,
self._objective_function,
self._parameters["opt_percentage"],
)

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):
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions dingo/PolytopeSampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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:
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions tutorials/dingo_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@
},
"outputs": [],
"source": [
"model.biomass_function"
"model.objective_function"
]
},
{
Expand Down Expand Up @@ -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"
]
},
{
Expand All @@ -1129,7 +1129,7 @@
},
"outputs": [],
"source": [
"model.biomass_function = obj_fun"
"model.objective_function = obj_fun"
]
},
{
Expand All @@ -1153,7 +1153,7 @@
},
"outputs": [],
"source": [
"model.biomass_function"
"model.objective_function"
]
},
{
Expand Down Expand Up @@ -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 "
]
},
{
Expand Down Expand Up @@ -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. "
]
},
{
Expand Down

0 comments on commit 31a8ff8

Please sign in to comment.