Skip to content

Commit

Permalink
fixing filter saving in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cshenry committed Aug 4, 2023
1 parent 8c70448 commit f02a4a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modelseedpy/core/msatpcorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion modelseedpy/core/msgapfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 2 additions & 10 deletions modelseedpy/core/msmodelutl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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

#################################################################################
Expand Down

0 comments on commit f02a4a7

Please sign in to comment.