Skip to content

Commit 01b1383

Browse files
author
Christopher Henry
committed
Improvements to support building models from other annotations
1 parent 6d48d67 commit 01b1383

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

modelseedpy/core/annotationontology.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,39 @@ def get_msgenome(self,prioritized_event_list=None,ontologies=None,merge_all=Fals
452452
)
453453
newgenome.annoont = self
454454
return newgenome
455-
455+
456+
def get_events_from_priority_list(self,priority_list):
457+
event_list = []
458+
for item in priority_list:
459+
selected_merge = None
460+
for event in self.events:
461+
if item == "all":
462+
if event.id not in event_list:
463+
event_list.append(event.id)
464+
elif item == "RAST":
465+
if len(event.method) > 4 and event.method[0:4] == "RAST" and event.id not in event_list:
466+
event_list.append(event.id)
467+
elif item == "Prokka":
468+
if len(event.method) > 6 and event.method[0:6] == "Prokka" and event.id not in event_list:
469+
event_list.append(event.id)
470+
elif item == "DRAM":
471+
if len(event.method) > 4 and event.method[0:4] == "DRAM" and event.id not in event_list:
472+
event_list.append(event.id)
473+
elif item == "GLM4EC":
474+
if len(event.method) > 6 and event.method[0:6] == "GLM4EC" and event.id not in event_list:
475+
event_list.append(event.id)
476+
elif item == "PDB":
477+
if event.method == "KBAnnotationApps.PDBAnnotation" and event.ontology.id == "EC" and event.id not in event_list:
478+
event_list.append(event.id)
479+
elif item == "SNEKMER":
480+
if len(event.method) > 7 and event.method[0:7] == "Snekmer" and event.id not in event_list:
481+
event_list.append(event.id)
482+
elif item == "Import":
483+
if len(event.method) > 6 and event.method[0:6] == "Import" and event.id not in event_list:
484+
event_list.append(event.id)
485+
elif item == "Merge":
486+
if len(event.method) > 5 and event.method[0:5] == "Merge" and event.id not in event_list:
487+
selected_merge = event.id
488+
if selected_merge:
489+
event_list.append(selected_merge)
490+
return event_list

modelseedpy/core/msmodelutl.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def get_atp_tests(self,core_template=None,atp_media_filename=None,recompute=Fals
498498
return self.atp_tests
499499
#Attempting to pull ATP tests from attributes
500500
if not recompute:
501-
print("Getting tests from attributes")
501+
logger.debug("Getting tests from attributes")
502502
atp_analysis = self.get_attributes("ATP_analysis",None)
503503
if atp_analysis:
504504
if "tests" in atp_analysis:
@@ -948,7 +948,7 @@ def is_core(self,rxn):
948948
if not isinstance(rxn, str):
949949
rxn = rxn.id
950950
if "core_reactions" in self.get_attributes():
951-
print("Using core reactions attribute!")
951+
logger.debug("Using core reactions attribute!")
952952
if rxn in self.get_attributes("core_reactions"):
953953
return True
954954
return False
@@ -1291,7 +1291,7 @@ def test_solution(self,solution,targets,medias,thresholds=[0.1],remove_unneeded_
12911291
return unneeded
12921292

12931293
def add_gapfilling(self, solution):
1294-
print("Adding gapfilling",str(solution))
1294+
logger.debug("Adding gapfilling:"+str(solution))
12951295
self.integrated_gapfillings.append(solution)
12961296

12971297
def create_kb_gapfilling_data(self, kbmodel, atpmedia_ws="94026"):
@@ -1439,7 +1439,7 @@ def test_single_condition(self, condition, apply_condition=True, model=None,repo
14391439
self.model.reactions.get_by_id(condition["objective"]).lower_bound = 0
14401440
return False
14411441
elif value <= condition["threshold"] and not condition["is_max_threshold"]:
1442-
print("Failed low:"+condition["media"].id+":"+str(new_objective)+";"+str(condition["threshold"]))
1442+
logger.debug("Failed low:"+condition["media"].id+":"+str(new_objective)+";"+str(condition["threshold"]))
14431443
return False
14441444
self.test_objective = new_objective
14451445
logger.debug("Passed:"+condition["media"].id+":"+str(new_objective)+";"+str(condition["threshold"]))
@@ -1544,11 +1544,11 @@ def binary_expansion_test(self, reaction_list, condition, currmodel, depth=0,pos
15441544
filtered_list = []
15451545
# First run the full test
15461546
if self.test_single_condition(condition,apply_condition=False,model=currmodel,rxn_list=reaction_list):
1547-
#print("Reaction set passed"," ".join(map(str, reaction_list)))
1547+
#logger.debug("Reaction set passed"," ".join(map(str, reaction_list)))
15481548
return []
15491549
# Check if input list contains only one reaction:
15501550
if len(reaction_list) == 1:
1551-
#print("Failed:"+reaction_list[0][1]+reaction_list[0][0].id)
1551+
#logger.debug("Failed:"+reaction_list[0][1]+reaction_list[0][0].id)
15521552
if reaction_list[0][1] == ">":
15531553
reaction_list[0].append(reaction_list[0][0].upper_bound)
15541554
reaction_list[0][0].upper_bound = 0
@@ -1561,7 +1561,7 @@ def binary_expansion_test(self, reaction_list, condition, currmodel, depth=0,pos
15611561
#Testing positive growth conditions
15621562
for pos_condition in positive_growth:
15631563
if not self.test_single_condition(pos_condition,apply_condition=True,model=currmodel):
1564-
print("Does not pass positive growth tests:"+reaction_list[0][1]+reaction_list[0][0].id)
1564+
logger.debug("Does not pass positive growth tests:"+reaction_list[0][1]+reaction_list[0][0].id)
15651565
success = False
15661566
break
15671567
#Restoring current test condition
@@ -1601,7 +1601,7 @@ def binary_expansion_test(self, reaction_list, condition, currmodel, depth=0,pos
16011601
for item in new_filter:
16021602
filtered_list.append(item)
16031603
if self.breaking_reaction != None:
1604-
print("Ending early due to breaking reaction:"+self.breaking_reaction.id)
1604+
logger.debug("Ending early due to breaking reaction:"+self.breaking_reaction.id)
16051605
return filtered_list
16061606
# Submitting second half of reactions for testing - now only breaking reactions are removed from the first list
16071607
for i, item in enumerate(reaction_list):
@@ -1667,14 +1667,14 @@ def reaction_expansion_test(
16671667
scores = self.assign_reliability_scores_to_reactions()
16681668
reaction_list = sorted(reaction_list, key=lambda x: scores[x[0].id][x[1]])
16691669
for item in reaction_list:
1670-
print(item[0].id+":"+item[1]+":"+str(scores[item[0].id][item[1]]))
1670+
logger.debug(item[0].id+":"+item[1]+":"+str(scores[item[0].id][item[1]]))
16711671
for condition in condition_list:
16721672
logger.debug(f"testing condition {condition}")
16731673
currmodel = self.model
16741674
tic = time.perf_counter()
16751675
new_filtered = []
16761676
if not self.check_if_solution_exists(reaction_list, condition, currmodel):
1677-
print("No solution exists that passes tests for condition "+condition["media"].id)
1677+
logger.debug("No solution exists that passes tests for condition "+condition["media"].id)
16781678
return None
16791679
with currmodel:
16801680
self.apply_test_condition(condition)
@@ -1691,13 +1691,13 @@ def reaction_expansion_test(
16911691
done = True
16921692
else:
16931693
#Remove breaking reaction from reaction_list
1694-
print("Keeping breaking reaction:"+self.breaking_reaction.id)
1694+
logger.debug("Keeping breaking reaction:"+self.breaking_reaction.id)
16951695
for i in range(len(reaction_list)):
16961696
if reaction_list[i][0] == self.breaking_reaction:
16971697
del reaction_list[i]
16981698
break
16991699
if not self.check_if_solution_exists(reaction_list, condition, currmodel):
1700-
print("No solution exists after retaining breaking reaction:"+self.breaking_reaction.id)
1700+
logger.debug("No solution exists after retaining breaking reaction:"+self.breaking_reaction.id)
17011701
return None
17021702
self.breaking_reaction = None
17031703
else:

modelseedpy/core/mstemplate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,16 @@ def remove_reactions(
15151515
associated_groups = self.get_associated_groups(reaction)
15161516
for group in associated_groups:
15171517
group.remove_members(reaction) """
1518-
1518+
1519+
#*************************Curation Functions*************************
1520+
def auto_fix_protons(self):
1521+
for rxn in self.reactions:
1522+
mb = rxn.check_mass_balance()
1523+
if 'charge' in mb and mb.get('H') == mb.get('charge'):
1524+
print(f'auto fix charge for {rxn.id}')
1525+
rxn.add_metabolites({
1526+
self.compcompounds.cpd00067_c: -1 * mb['charge']
1527+
})
15191528

15201529
class MSTemplateBuilder:
15211530
def __init__(

modelseedpy/fbapkg/gapfillingpkg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
logging.INFO
2525
) # When debugging - set this to INFO then change needed messages below from DEBUG to INFO
2626

27-
base_blacklist = {"rxn04656":"=","rxn07589":"=","rxn07588":"="}
27+
base_blacklist = {"rxn04656":"=","rxn07589":"<","rxn07588":"<"}
2828
zero_threshold = 1e-8
2929

3030

0 commit comments

Comments
 (0)