from biodivine_aeon import *
from pathlib import Path
model = BooleanNetwork.from_sbml(Path('t-lgl-survival.sbml').read_text())
rg = model.graph()
# Fix input variables according to [4]
model.set_update_function("Stimuli", "true")
model.set_update_function("IL15", "true")
model.set_update_function("PDGF", "true")
model.set_update_function("Stimuli2", "false")
model.set_update_function("CD45", "false")
model.set_update_function("TAX", "false")
graph = SymbolicAsyncGraph(model)
attractors = find_attractors(graph)
print("Attractor sets:", len(attractors))
A1 = attractors[0]
A2 = attractors[1]
A3 = attractors[2]
print("A1:", A1.vertices().cardinality())
print("A2:", A2.vertices().cardinality())
print("A3:", A3.vertices().cardinality())
apoptosis = graph.fix_variable("Apoptosis", True)
proliferation = graph.fix_variable("Proliferation", True)
cytoskeleton = graph.fix_variable("Cytoskeleton_signaling", True)
tcr = graph.fix_variable("TCR", True)
ctla4 = graph.fix_variable("CTLA4", True)
p2 = graph.fix_variable("P2", True)
print("==== A1 Phenotypes ====")
print("A1[Apoptosis] is always True:", A1.minus(apoptosis).is_empty())
print("A1[Proliferation] is always False:", A1.intersect(proliferation).is_empty())
print("A1[Cytoskeleton] is always False:", A1.intersect(cytoskeleton).is_empty())
print("==== A2 Phenotypes ====")
print("A2[Apoptosis] is always False:", A2.intersect(apoptosis).is_empty())
print("A2[Proliferation] is always False:", A2.intersect(proliferation).is_empty())
print("A2[Cytoskeleton] is always True:", A2.minus(cytoskeleton).is_empty())
print("A2[TCR] is always True:", A2.minus(tcr).is_empty())
print("A2[TCR] is always False:", A2.intersect(tcr).is_empty())
print("A2[CTLA4] is always True:", A2.minus(ctla4).is_empty())
print("A2[CTLA4] is always False:", A2.intersect(ctla4).is_empty())
print("A2[P2] is always False:", A2.intersect(p2).is_empty())
print("==== A3 Phenotypes ====")
print("A3[Apoptosis] is always False:", A3.intersect(apoptosis).is_empty())
print("A3[Proliferation] is always False:", A3.intersect(proliferation).is_empty())
print("A3[Cytoskeleton] is always True:", A3.minus(cytoskeleton).is_empty())
print("A3[CTLA4] is always True:", A3.minus(ctla4).is_empty())
print("A3[CTLA4] is always False:", A3.intersect(ctla4).is_empty())
print("A3[P2] is always False:", A3.minus(p2).is_empty())
complexAttr = A2.union(A3)
alwaysTrue = []
alwaysFalse = []
for variable in model.variables():
isTrue = graph.fix_variable(variable, True)
isFalse = graph.fix_variable(variable, False)
if complexAttr.is_subset(isTrue):
alwaysTrue.append(rg.get_variable_name(variable))
if complexAttr.is_subset(isFalse):
alwaysFalse.append(rg.get_variable_name(variable))
alwaysTrue = sorted(alwaysTrue, key=str.casefold)
alwaysFalse = sorted(alwaysFalse, key=str.casefold)
print("Always *true* in complex attractors:", alwaysTrue)
print("Always *false* in complex attractors:", alwaysFalse)
A1_weak = reach_bwd(graph, A1)
A2_weak = reach_bwd(graph, A2)
A3_weak = reach_bwd(graph, A3)
all_states_card = graph.unit_colored_vertices().vertices().cardinality()
A1_strong = A1_weak.minus(A2_weak).minus(A3_weak)
A1_strong_card = A1_strong.vertices().cardinality()
print("A1 strong basin:", (A1_strong_card / all_states_card) * 100.0, "%")
A1_realistic_strong = A1_strong.minus(apoptosis)
A1_realistic_strong_card = A1_realistic_strong.vertices().cardinality()
print("A1[Apoptosis = false] strong basin:", (A1_realistic_strong_card / all_states_card) * 100.0, "%")
A2_strong = A2_weak.minus(A1_weak).minus(A3_weak)
A2_strong_card = A2_strong.vertices().cardinality()
print("A2 strong basin:", (A2_strong_card / all_states_card) * 100.0, "%")
A3_strong = A3_weak.minus(A1_weak).minus(A2_weak)
A3_strong_card = A3_strong.vertices().cardinality()
print("A3 strong basin:", (A3_strong_card / all_states_card) * 100.0, "%")
A2_A3_strong = A2_weak.union(A3_weak).minus(A1_weak)
A2_A3_strong_card = A2_A3_strong.vertices().cardinality()
print("A2/A3 strong basin:", (A2_A3_strong_card / all_states_card) * 100.0, "%")
all_three = A1_weak.intersect(A2_weak).intersect(A3_weak)
print("Undetermined:", (all_three.vertices().cardinality() / all_states_card) * 100.0, "%")
all_phenotypes = A1_weak.intersect(A2_weak.union(A3_weak))
print("Undetermined phenotype:", (all_phenotypes.vertices().cardinality() / all_states_card) * 100.0, "%")
# Reload the graph and recompute attractors without fixing parameters.
model = BooleanNetwork.from_sbml(Path('t-lgl-survival.sbml').read_text())
rg = model.graph()
graph = SymbolicAsyncGraph(model)
attractors = find_attractors(graph)
print("Attractor sets:", len(attractors))
healthy = graph.empty_colored_vertices()
diseased = graph.empty_colored_vertices()
apoptosis = graph.fix_variable("Apoptosis", True)
for attr in attractors:
healthy_colors = attr.intersect(apoptosis).colors()
diseased_colors = attr.minus(apoptosis).colors()
assert healthy_colors.intersect(diseased_colors).is_empty()
healthy = healthy.union(attr.intersect_colors(healthy_colors))
diseased = diseased.union(attr.intersect_colors(diseased_colors))
print("Parametrisations with healthy:", healthy.colors().cardinality())
print("Parametrisations with diseased:", diseased.colors().cardinality())
cd45 = graph.fix_variable("CD45", True)
il15 = graph.fix_variable("IL15", True)
# This number should be 48, since that is the number of parametrisations
# where cd45 or il15 are true.
print(diseased.intersect(cd45.union(il15)).colors().cardinality(), "colors have diseased attractors.")
proliferation = graph.fix_variable("Proliferation", True)
assert healthy.intersect(proliferation).is_empty()
assert diseased.intersect(proliferation).is_empty()
# Reload the graph and recompute attractors without fixing parameters.
model = BooleanNetwork.from_aeon(Path('t-lgl-proliferation.aeon').read_text())
rg = model.graph()
graph = SymbolicAsyncGraph(model)
attractors = find_attractors(graph)
print("Attractor sets:", len(attractors))
healthy = graph.empty_colored_vertices()
diseased = graph.empty_colored_vertices()
apoptosis = graph.fix_variable("Apoptosis", True)
proliferation = graph.fix_variable("Proliferation", True)
for attr in attractors:
attr = attr.intersect(proliferation)
healthy_colors = attr.intersect(apoptosis).colors()
diseased_colors = attr.minus(apoptosis).colors()
assert healthy_colors.intersect(diseased_colors).is_empty()
healthy = healthy.union(attr.intersect_colors(healthy_colors))
diseased = diseased.union(attr.intersect_colors(diseased_colors))
print("Parametrisations with healthy attr. and proliferation:", healthy.colors().cardinality())
print("Parametrisations with diseased attr. and proliferation:", diseased.colors().cardinality())