Skip to content

Commit

Permalink
New heuristic for setting retained_set
Browse files Browse the repository at this point in the history
  • Loading branch information
giang-trinh committed May 16, 2023
1 parent 9d7fa56 commit f847dea
Show file tree
Hide file tree
Showing 26 changed files with 1,962 additions and 24 deletions.
81 changes: 60 additions & 21 deletions nfvsmotifs/SuccessionDiagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def __init__(self, network: BooleanNetwork):
# A Petri net representation of the original Boolean network.
self.petri_net = network_to_petrinet(network)
# Negative feedback vertex set.
self.nfvs = feedback_vertex_set(network, parity="negative")#find_minimum_NFVS(network)
self.nfvs = feedback_vertex_set(network, parity="negative")
#self.nfvs = find_minimum_NFVS(network)
print(f"|U-| = {len(self.nfvs)}")
#print(self.nfvs)
# A directed acyclic graph representing the succession diagram.
self.G = nx.DiGraph()
# A dictionary used for uniqueness checks on the nodes of the succession diagram.
Expand Down Expand Up @@ -307,29 +310,65 @@ def expand_attractors(self, node_id: int) -> list[dict[str, int]]:
# the space is a trap and this will remove the corresponding unnecessary
# Petri net transitions.
retained_set = node_space.copy()
for x in self.nfvs:
if x not in retained_set:
"""Set all nodes to 0"""
#retained_set[x] = 0

"""Set nodes to values based on the majority of satisfying values of functions"""
fx = self.network.get_update_function(x)
fx = aeon_to_pyeda(fx)
n_input = len(list(fx.support))
n_poss_sat = pow(2, n_input - 1)

n_sat = fx.satisfy_count()

if n_sat > n_poss_sat:
retained_set[x] = 1
elif n_sat < n_poss_sat:
retained_set[x] = 0
else:
retained_set[x] = random.randint(0, 1)


child_spaces = [self.node_space(child) for child in self.G.successors(node_id)]

# find the child space least common with NFVS
if (len(child_spaces) > 0):
least_common_child_space = child_spaces[0]
least_common_nodes = len(set(least_common_child_space) & set(self.nfvs))
for child_space in child_spaces:
common_nodes = len(set(child_space) & set(self.nfvs))
if (common_nodes < least_common_nodes):
least_common_nodes = common_nodes
least_common_child_space = child_space

for x in self.nfvs:
if x not in retained_set:
if x in least_common_child_space:
retained_set[x] = least_common_child_space[x]
else:
"""Set nodes to values based on the majority of satisfying values of functions"""
fx = self.network.get_update_function(x)
fx = aeon_to_pyeda(fx)
n_input = len(list(fx.support))
n_poss_sat = pow(2, n_input - 1)

n_sat = fx.satisfy_count()

if n_sat > n_poss_sat:
retained_set[x] = 1
elif n_sat < n_poss_sat:
retained_set[x] = 0
else:
#retained_set[x] = random.randint(0, 1)
retained_set[x] = 0
#retained_set[x] = 1
else:
for x in self.nfvs:
if x not in retained_set:
"""Set all nodes to 0"""
#retained_set[x] = 0

"""Set nodes to values based on the majority of satisfying values of functions"""
fx = self.network.get_update_function(x)
fx = aeon_to_pyeda(fx)
n_input = len(list(fx.support))
n_poss_sat = pow(2, n_input - 1)

n_sat = fx.satisfy_count()

if n_sat > n_poss_sat:
retained_set[x] = 1
elif n_sat < n_poss_sat:
retained_set[x] = 0
else:
#retained_set[x] = random.randint(0, 1)
retained_set[x] = 0
#retained_set[x] = 1



if len(retained_set) == self.network.num_vars() and len(child_spaces) == 0:
# There is only a single attractor remaining here,
# and its "seed" is the retain set.
Expand Down
6 changes: 3 additions & 3 deletions nfvsmotifs/motif_avoidant.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ def _preprocess_candidates(
function_bdd = expr2bdd(aeon_to_pyeda(function_expression))
update_functions[var_name] = function_bdd

print("Finish loading functions")
#print("Finish loading functions")
if is_in_an_mts == False:
#symbolic_candidates = state_list_to_bdd(candidates)
symbolic_candidates = deepcopy(candidates)
filtered_candidates = []
i = 1
for state in candidates:
print(f"Run outside mts - {i}")
#print(f"Run outside mts - {i}")
i += 1
#state_bdd = state_to_bdd(state)

Expand Down Expand Up @@ -150,7 +150,7 @@ def _preprocess_candidates(
else:
filtered_candidates = []
for i in range(max_iterations):
print(f"Run inside mts - {i + 1}")
#print(f"Run inside mts - {i + 1}")
random.shuffle(variables)
#symbolic_candidates = state_list_to_bdd(candidates)
symbolic_candidates = deepcopy(candidates)
Expand Down
25 changes: 25 additions & 0 deletions test.bnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
targets, fact|s
A, (!A & !B) | C
B, (!A & !B) | C
C, A & B

#A, !E | (A & B & C)
#B, !F | (A & B & C)
#C, !D | (A & B & C)
#D, A
#E, B
#F, C

#A, !E | (G & B & C)
#B, !F | (A & H & C)
#C, !D | (A & B & I)
#D, A
#E, B
#F, C
#G, A
#H, B
#I, C

#A, !A | !B
#B, !A | !B
#C, A & B
75 changes: 75 additions & 0 deletions test/A_model.bnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
targets, factors
a_secretase, (CREB|s_NMDAR)&(!ROCK|!Cholesterol)
Ab, ((APP&BACE1)&(Sortilin|PICALM|Cholesterol))&!Autophagy
ABCA7, SREBP2
AKT, (s_NMDAR&PI3K)&(!PTEN|!PP2A)&!CASP3
APOE4, APOE4
Apoer2, Reelin&!APOE4
Apoptosis, CASP3
APP, ERK&(!(a_secretase&(Sortilin|LRP6))|!SORL1|!(Dab1&Apoer2)|!(Dab1&Fyn))
ATM, ROS
Autophagy, (ULK1&LC3&p62&LAMP2&beclin1)&!(Cholesterol&ROS)
BACE1, (STAT3|Cholesterol)&!PGC1a
BAD, !AKT&PP2B
BAX, ((Bim&PUMA)&p53)&!AKT&!Bcl2
Bcl2, !BAD&(!p53|!JNK|!Bim)
BDNF, (CREB|PGC1a)&Sortilin
beclin1, (ROCK|JNK)&(!Bcl2|!CASP3)
Bim, EGR1|FOXO
Ca_ion, e_NMDAR
CASP2, p53
CASP3, BAX&Bim
Cdk5, Ca_ion|EGR1
Cholesterol, !CYP46A1&(SREBP2&HMGCR)|(!LPL|!ABCA7)
CIP2A, Ab
CLU, p53|EGR1
CREB, (ERK&Jacob&s_NMDAR)|!(Jacob&e_NMDAR)
CYP46A1, !APP&Ca_ion
Dab1, Apoer2&!Fyn
Dkk1, Ab&(CLU|PICALM)
DLK, APOE4
e_NMDAR, (Ab&Fyn)|PTEN
EGR1, JNK
ERK, !(pTau&PP2A)&((s_NMDAR&!STEP)|MKK7)
FOXO, JNK&!AKT
Fyn, ((Apoer2&Dab1)|mGluR)&!STEP
GSK3beta, (Ca_ion|PP2A)&!(AKT|LRP6)
Jacob, (s_NMDAR&ERK)|e_NMDAR
JNK, MKK7|Vangl2
LAMP2, PIP2|TFEB
LC3, PIP2|TFEB|!PICALM
LPL, SREBP2&!SORL1
LRP6, !APOE4|!Dkk1
MAPT, e_NMDAR&!CREB
MDM2, p53&(!ATM&!CASP2|!GSK3beta)
mGluR, Ab
MKK7, DLK|e_NMDAR
mTOR, (AKT|ERK|Cholesterol)&!SIRT1
p38, !STEP
p53, (p38|ATM)&!MDM2
p62, PIP2|TFEB|!PICALM
PGC1a, (CREB|SIRT1)&p38
PI3K, Dab1|s_NMDAR|BDNF
PICALM, !Ca_ion&!CASP3
PIP2, !synj1
PP2A, (!mGluR|!GSK3beta)&!APOE4&!CIP2A
PP2B, mGluR|Ca_ion
PTEN, ROCK
PUMA, !s_NMDAR&(FOXO|p53)
Reelin, !Apoptosis
RhoA, CASP2|Vangl2
ROCK, RhoA|!SIRT1
ROS, (Ca_ion|Ab)&!PGC1a
s_NMDAR, (Fyn|BDNF)&!STEP&!pTau
SORL1, !ROCK|BDNF
Sortilin, ROCK
SREBP2, (!Cholesterol|!APP|!ABCA7)|AKT
STAT3, Cdk5
STEP, (PP2B)&(!s_NMDAR|!e_NMDAR)
synj1, APOE4|(!Cdk5&PP2B)
pTau, (MAPT&(GSK3beta|Cdk5|ERK))&!PP2A&!Autophagy
TFEB, (!APOE4|!mTOR)&PP2B
ULK1, !mTOR
Vangl2, Dkk1
SIRT1, (!APOE4|!ROS)
HMGCR, BDNF|SREBP2
66 changes: 66 additions & 0 deletions test/CASCADE1.bnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
targets, factors
AKT1S1, !AKT_f
AKT_f, !mTORC2_c&PDPK1|mTORC2_c
AXIN1, !LRP_f
BTRC, !GSK3_f&!AXIN1&CK1_f|!GSK3_f&AXIN1|GSK3_f
CHU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
PTEN, PTEN_g&!GSK3_f
PTEN_g, EGR1
PTPN11, GAB_f
RAC_f, !mTORC2_c&DVL_f|mTORC2_c
RAF_f, !AKT_f&!ERK_f&KRAS&!RHEB
RHEB, !TSC_f
RSK_f, !ERK_f&PDPK1|ERK_f
RTPK_f, !MAPK14&!RTPK_g&!MEK_f&MMP_f|!MAPK14&RTPK_g&!MEK_f
RTPK_g, FOXO_f
S6K_f, !mTORC1_c&PDPK1|mTORC1_c
SFRP1, SFRP1_g
SFRP1_g, !MYC
SHC1, RTPK_f&!PTEN
SOS1, GRB2&!ERK_f
TAB_f, !MAPK14
TCF7_f, !NLK&CTNNB1
TP53, MAPK14&!MDM2
TSC_f, !AKT_f&!ERK_f&!RSK_f&!IKBKB&GSK3_f
mTORC1_c, !RHEB&RSK_f&!AKT1S1|RHEB&!AKT1S1
mTORC2_c, !S6K_f&TSC_f
Loading

1 comment on commit f847dea

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
nfvsmotifs
   SuccessionDiagram.py1662088%5–6, 62, 70–73, 103, 115, 161, 187, 197, 201, 211, 215, 292–295, 362, 417
   interaction_graph_utils.py132596%5, 55, 66, 88–89
   motif_avoidant.py135497%17, 59, 93, 225
   petri_net_translation.py84693%21–22, 47, 58–59, 85
   pyeda_utils.py913463%9, 49–59, 82, 87, 90–104, 122–126
   space_utils.py1021387%11, 26–33, 41, 151, 167, 221
   state_utils.py51492%11, 62, 69, 77
   terminal_restriction_space.py43393%5–6, 68
   trappist_core.py1571292%8–10, 65, 186–188, 211, 222–223, 296, 363
nfvsmotifs/FVSpython3
   FVS.py481079%90–91, 97, 133, 183–189
   FVS_localsearch_10_python.py90199%179
TOTAL119711291% 

Tests Skipped Failures Errors Time
220 0 💤 0 ❌ 0 🔥 2m 47s ⏱️

Please sign in to comment.