[Feature] Threshold Warning + Cosmetics (#277)

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#277
This commit is contained in:
2025-12-20 02:11:47 +13:00
parent a4a4179261
commit 7c60a28801
10 changed files with 304 additions and 165 deletions

View File

@ -1489,6 +1489,7 @@ class SPathway(object):
self.smiles_to_node: Dict[str, SNode] = dict(**{n.smiles: n for n in self.root_nodes})
self.edges: Set["SEdge"] = set()
self.done = False
self.empty_due_to_threshold = False
@staticmethod
def from_pathway(pw: "Pathway", persist: bool = True):
@ -1601,9 +1602,24 @@ class SPathway(object):
sub.app_domain_assessment = app_domain_assessment
candidates = self.prediction_setting.expand(self, sub)
expansion_result = self.prediction_setting.expand(self, sub)
# We don't have any substrate, but technically we have at least one rule that triggered.
# If our substrate is a root node a.k.a. depth == 0 store that info in SPathway
if (
len(expansion_result["transformations"]) == 0
and expansion_result["rule_triggered"]
and sub.depth == 0
):
self.empty_due_to_threshold = True
# Emit directly
if self.persist is not None:
self.persist.kv["empty_due_to_threshold"] = True
self.persist.save()
# candidates is a List of PredictionResult. The length of the List is equal to the number of rules
for cand_set in candidates:
for cand_set in expansion_result["transformations"]:
if cand_set:
# cand_set is a PredictionResult object that can consist of multiple candidate reactions
for cand in cand_set:
@ -1727,10 +1743,6 @@ class SPathway(object):
for queued_val in queue:
node_and_probs.append((queued_val, node_probs[queued_val]))
from pprint import pprint
pprint(node_and_probs)
# re-order the queue and only pick smiles
queue = [
n[0] for n in sorted(node_and_probs, key=lambda x: x[1], reverse=True)