From c5cb6f2408bff348f00a4c44c191ba49b5baa73c Mon Sep 17 00:00:00 2001 From: SotirisTouliopoulos Date: Thu, 15 Aug 2024 00:04:01 +0300 Subject: [PATCH] added verbose boolean variable --- dingo/preprocess.py | 41 ++++++++++++++++++++++++----------------- dingo/utils.py | 6 ++++-- tests/correlation.py | 6 ++++-- tests/preprocess.py | 4 ++-- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/dingo/preprocess.py b/dingo/preprocess.py index 341631b6..4f711ff2 100644 --- a/dingo/preprocess.py +++ b/dingo/preprocess.py @@ -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() @@ -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) @@ -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) diff --git a/dingo/utils.py b/dingo/utils.py index e8d3d567..3fb0888c 100644 --- a/dingo/utils.py +++ b/dingo/utils.py @@ -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 @@ -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: @@ -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 diff --git a/tests/correlation.py b/tests/correlation.py index 0e935bb0..fdb21b75 100644 --- a/tests/correlation.py +++ b/tests/correlation.py @@ -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)) @@ -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)) diff --git a/tests/preprocess.py b/tests/preprocess.py index 6093b579..64edce9c 100644 --- a/tests/preprocess.py +++ b/tests/preprocess.py @@ -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 @@ -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