From f02a4a775b85b722188400e808080f9a15084d8b Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Thu, 3 Aug 2023 23:21:23 -0400 Subject: [PATCH] fixing filter saving in attributes --- modelseedpy/core/msatpcorrection.py | 2 +- modelseedpy/core/msgapfill.py | 7 ++++++- modelseedpy/core/msmodelutl.py | 12 ++---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/modelseedpy/core/msatpcorrection.py b/modelseedpy/core/msatpcorrection.py index 59055ca6..6a0fcec2 100644 --- a/modelseedpy/core/msatpcorrection.py +++ b/modelseedpy/core/msatpcorrection.py @@ -444,7 +444,7 @@ def expand_model_to_genome_scale(self): self.restore_noncore_reactions(noncore=True, othercompartment=False) # Extending model with non core reactions while retaining ATP accuracy self.filtered_noncore = self.modelutl.reaction_expansion_test( - self.noncore_reactions, tests,atp_expansion=True + self.noncore_reactions, tests,attribute_label="atp_expansion_filter" ) # Removing filtered reactions for item in self.filtered_noncore: diff --git a/modelseedpy/core/msgapfill.py b/modelseedpy/core/msgapfill.py index a3d5c5f3..f716c1fd 100644 --- a/modelseedpy/core/msgapfill.py +++ b/modelseedpy/core/msgapfill.py @@ -148,11 +148,16 @@ def prefilter(self, media, target): self.gfpkgmgr.getpkg("GapfillingPkg").filter_database_based_on_tests( self.test_conditions ) + with open("OriginalAttributes.json", 'w') as f: + json.dump(self.mdlutl.get_attributes(), f,indent=4,skipkeys=True) + with open("GapfillingAttributes.json", 'w') as f: + json.dump(self.gfpkgmgr.getpkg("GapfillingPkg").modelutl.get_attributes(), f,indent=4,skipkeys=True) gf_filter = self.gfpkgmgr.getpkg("GapfillingPkg").modelutl.get_attributes("gf_filter", {}) base_filter = self.mdlutl.get_attributes("gf_filter", {}) for media_id in gf_filter: base_filter[media_id] = gf_filter[media_id] - base_filter = self.mdlutl.save_attributes(base_filter, "gf_filter") + with open("FinalAttributes.json", 'w') as f: + json.dump(self.mdlutl.get_attributes(), f,indent=4,skipkeys=True) # Testing if gapfilling can work after filtering if not self.test_gapfill_database(media, target, before_filtering=False): diff --git a/modelseedpy/core/msmodelutl.py b/modelseedpy/core/msmodelutl.py index 607095c2..785c4f9c 100644 --- a/modelseedpy/core/msmodelutl.py +++ b/modelseedpy/core/msmodelutl.py @@ -902,7 +902,7 @@ def binary_expansion_test(self, reaction_list, condition, currmodel, depth=0): return filtered_list def reaction_expansion_test( - self, reaction_list, condition_list, binary_search=True,atp_expansion=False + self, reaction_list, condition_list, binary_search=True,attribute_label="gf_filter" ): """Adds reactions in reaction list one by one and appplies tests, filtering reactions that fail @@ -961,11 +961,7 @@ def reaction_expansion_test( + str(len(reaction_list)) ) # Adding filter results to attributes - gf_filter_att = self.get_attributes("gf_filter", {}) - if atp_expansion: - atp_analysis = self.get_attributes("ATP_analysis", {}) - atp_analysis["atp_expansion_filter"] = {} - gf_filter_att = atp_analysis["atp_expansion_filter"] + gf_filter_att = self.get_attributes(attribute_label, {}) if condition["media"].id not in gf_filter_att: gf_filter_att[condition["media"].id] = {} if condition["objective"] not in gf_filter_att[condition["media"].id]: @@ -1001,10 +997,6 @@ def reaction_expansion_test( gf_filter_att[condition["media"].id][condition["objective"]][ condition["threshold"] ][item[0].id][item[1]] = item[2] - if atp_expansion: - atp_analysis = self.save_attributes(atp_analysis, "ATP_analysis") - else: - gf_filter_att = self.save_attributes(gf_filter_att, "gf_filter") return filtered_list #################################################################################