Skip to content

Commit

Permalink
added verbose boolean variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SotirisTouliopoulos committed Aug 14, 2024
1 parent 3fd6967 commit c5cb6f2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
41 changes: 24 additions & 17 deletions dingo/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@

class PreProcess:

def __init__(self, model, tol=1e-6, open_exchanges=False):
def __init__(self, model, tol = 1e-6, open_exchanges = False, verbose = False):

"""
model parameter gets a cobra model as input
model -- parameter gets a cobra model as input
tol parameter gets a cutoff value used to classify
zero-flux and mle reactions and compare FBA solutions
before and after reactions removal
tol -- parameter gets a cutoff value used to classify
zero-flux and mle reactions and compare FBA solutions
before and after reactions removal
open_exchanges parameter is used in the function that identifies blocked reactions
It controls whether or not to open all exchange reactions to very high flux ranges
open_exchanges -- parameter is used in the function that identifies blocked reactions
It controls whether or not to open all exchange reactions
to very high flux ranges.
verbose -- A boolean type variable that if True
additional information for preprocess is printed.
"""

self._model = model
self._tol = tol

if self._tol > 1e-6:
print("Tolerance value set to",self._tol,"while default value is 1e-6. A looser check will be performed")


self._open_exchanges = open_exchanges
self._verbose = verbose

if self._tol > 1e-6 and verbose == True:
print("Tolerance value set to",self._tol,"while default value is 1e-6. A looser check will be performed")

self._objective = self._objective_function()
self._initial_reactions = self._initial()
self._reaction_bounds_dict = self._reaction_bounds_dictionary()
Expand Down Expand Up @@ -204,8 +209,9 @@ def reduce(self, extend=False):

elif extend == False:

print(len(self._removed_reactions), "of the", len(self._initial_reactions), \
"reactions were removed from the model with extend set to", extend)
if self._verbose == True:
print(len(self._removed_reactions), "of the", len(self._initial_reactions), \
"reactions were removed from the model with extend set to", extend)

# call this functon to convert cobra to dingo model
self._dingo_model = MetabolicNetwork.from_cobra_model(self._model)
Expand Down Expand Up @@ -266,10 +272,11 @@ def reduce(self, extend=False):
# restore bounds
self._model.reactions.get_by_id(reaction).bounds = self._reaction_bounds_dict[reaction]


print(len(self._removed_reactions), "of the", len(self._initial_reactions), \
"reactions were removed from the model with extend set to", extend)
print(additional_removed_reactions_count, "additional reaction(s) removed")

if self._verbose == True:
print(len(self._removed_reactions), "of the", len(self._initial_reactions), \
"reactions were removed from the model with extend set to", extend)
print(additional_removed_reactions_count, "additional reaction(s) removed")

# call this functon to convert cobra to dingo model
self._dingo_model = MetabolicNetwork.from_cobra_model(self._model)
Expand Down
6 changes: 4 additions & 2 deletions dingo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_matrices_of_full_dim_polytope(A, b, Aeq, beq):


def correlated_reactions(steady_states, reactions=[], pearson_cutoff = 0.90, indicator_cutoff = 10,
cells = 10, cop_coeff = 0.3, lower_triangle = True):
cells = 10, cop_coeff = 0.3, lower_triangle = True, verbose = False):
"""A Python function to calculate the pearson correlation matrix of a model
and filter values based on the copula's indicator
Expand All @@ -217,6 +217,7 @@ def correlated_reactions(steady_states, reactions=[], pearson_cutoff = 0.90, ind
cells -- Number of cells to compute the copula
cop_coeff -- A value that narrows or widens the width of the copula's diagonal
lower_triangle -- A boolean variable that if True plots only the lower triangular matrix
verbose -- A boolean variable that if True additional information is printed as an output.
"""

if cop_coeff > 0.4 or cop_coeff < 0.2:
Expand Down Expand Up @@ -328,7 +329,8 @@ def correlated_reactions(steady_states, reactions=[], pearson_cutoff = 0.90, ind
'indicator': indicator,
'classification': "no correlation"}

print("Completed process of",i+1,"from",corr_indices.shape[0],"copulas")
if verbose == True:
print("Completed process of",i+1,"from",corr_indices.shape[0],"copulas")

if lower_triangle == True:
filtered_corr_matrix[np.triu_indices(filtered_corr_matrix.shape[0], 1)] = np.nan
Expand Down
6 changes: 4 additions & 2 deletions tests/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_correlation(self):
reactions = reactions,
indicator_cutoff = 5,
pearson_cutoff = 0.999999,
lower_triangle = False)
lower_triangle = False,
verbose = False)

# sum values in the diagonal of the correlation matrix ==> 95*pearson ==> 95*1
self.assertTrue(np.trace(corr_matrix) == len(reactions))
Expand All @@ -38,7 +39,8 @@ def test_correlation(self):
corr_matrix = correlated_reactions(steady_states,
indicator_cutoff = 0,
pearson_cutoff = 0,
lower_triangle = True)
lower_triangle = True,
verbose = False)

# sum values in the diagonal of the correlation matrix ==> 95*pearson ==> 95*1
self.assertTrue(np.trace(corr_matrix) == len(reactions))
Expand Down
4 changes: 2 additions & 2 deletions tests/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_preprocess(self):

# call the reduce function from the PreProcess class
# with extend=False to remove reactions from the model
obj = PreProcess(cobra_model, tol=1e-5, open_exchanges=False)
obj = PreProcess(cobra_model, tol=1e-5, open_exchanges=False, verbose=False)
removed_reactions, final_dingo_model = obj.reduce(extend=False)

# calculate the count of removed reactions with extend set to False
Expand All @@ -46,7 +46,7 @@ def test_preprocess(self):

# call the reduce function from the PreProcess class
# with extend=True to remove additional reactions from the model
obj = PreProcess(cobra_model, tol=1e-6, open_exchanges=False)
obj = PreProcess(cobra_model, tol=1e-6, open_exchanges=False, verbose=False)
removed_reactions, final_dingo_model = obj.reduce(extend=True)

# calculate the count of removed reactions with extend set to True
Expand Down

0 comments on commit c5cb6f2

Please sign in to comment.