jcrozum / pystablemotifs

Python library for attractor identification and control in Boolean networks
MIT License
28 stars 7 forks source link

bug: attractor not showing up properly #94

Closed kyuhyongpark closed 9 months ago

kyuhyongpark commented 9 months ago
import pystablemotifs as sm
import networkx as nx
import matplotlib.pyplot as plt

rules="""
A, !a & !B | C
B, !A & !b | C
C, A & B
a, A
b, B
"""

primes = sm.format.create_primes(rules)
sm.format.pretty_print_prime_rules(primes)

ar = sm.AttractorRepertoire.from_primes(primes, max_simulate_size=20)

ar.summary()

for a in ar.attractors:
    if a.n_unfixed == 0: continue # skip steady states
    print(a.attractor_dict)
    nx.draw(a.stg,with_labels=True)
    plt.show()
    print(len(a.stg.nodes()))

I get output

There are 2 attractors.
{'A': 'X', 'B': 'X', 'C': 0, 'a': '0', 'b': 'X'}

{'A': 1, 'B': 1, 'C': 1, 'a': 1, 'b': 1}

This cannot be right, since A oscillates and hence a should as well.

jcrozum commented 9 months ago

@kyuhyongpark I'm working on this. I think the problem is that there are some conflicting ways of converting to and from the binary string representation. For example, the first attractor has '00000' in it, but sometimes we can figure out that C=0 in the whole attractor, so it only stores four digits, i.e., '0000'. Then, if we read the long version thinking it's the short version, we skip the C place, so a reads the value of C and b reads the value of a.