Coder Social home page Coder Social logo

bnediction / bonesis Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 655 KB

Synthesis and Reprogramming of Most Permissive Boolean Networks

Home Page: https://bnediction.github.io/bonesis/

License: Other

Python 100.00%
answer-set-programming boolean-networks synthesis systems-biology

bonesis's Introduction

BoNesis - Boolean Network synthesis

Synthesis of Most Permissive Boolean Networks from network architecture and dynamical properties

This software is distributed under the CeCILL v2.1 free software license (GNU GPL compatible).

For installation instructions and usage, see documentation.

bonesis's People

Contributors

pauleve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bonesis's Issues

Incomplete enumeration of local functions fails

Hi! One more small bug we ran into: If one uses bo.local_functions() to get a per-variable view of the inferred update functions, one has to always enumerate all functions, because otherwise the __exit__ method on the ProjectedBooleanNetworksContext will just crash with Program updates not supported!.

This can be reproduced by the following Python script:

import bonesis

influences = [
	("Pax6","Pax6",dict(sign=1)),
	("Pax6","Hes5",dict(sign=1)),
	("Pax6","Mash1",dict(sign=1)),
	("Hes5","Mash1",dict(sign=-1)),
	("Hes5","Scl",dict(sign=1)),
	("Hes5","Olig2",dict(sign=1)),
	("Hes5","Stat3",dict(sign=1)),
	("Mash1","Hes5",dict(sign=-1)),
	("Mash1","Zic1",dict(sign=1)),
	("Mash1","Brn2",dict(sign=1)),
	("Zic1","Tuj1",dict(sign=1)),
	("Brn2","Tuj1",dict(sign=1)),
	("Scl","Olig2",dict(sign=-1)),
	("Scl","Stat3",dict(sign=1)),
	("Olig2","Scl",dict(sign=-1)),
	("Olig2","Myt1L",dict(sign=1)),
	("Olig2","Sox8",dict(sign=1)),
	("Olig2","Brn2",dict(sign=-1)),
	("Stat3","Aldh1L1",dict(sign=1)),
	("Myt1L","Tuj1",dict(sign=1)),
]

dom = bonesis.InfluenceGraph(influences)

data = {
    "fMS": {"Pax6": 1, "Tuj1": 0, "Zic1": 0, "Brn2": 0, "Aldh1L1": 0, "Sox8": 1},
    "fA": {"Pax6": 1, "Tuj1": 0, "Zic1": 0, "Brn2": 0, "Aldh1L1": 1, "Sox8": 0},
}

bo = bonesis.BoNesis(dom, data)
bo.fixed(~bo.obs("fA"))
bo.fixed(~bo.obs("fMS"));

print(" >> Enumerating unrestricted.")
funs = bo.local_functions()
for node in dom.nodes():	
	with funs.view(node) as view:
		f = [f for f in view]
		print(f"Enumerated {len(f)} functions for node {node}.")

print(" >> Enumerating with limit.")
funs = bo.local_functions(limit=2)
for node in dom.nodes():	
	with funs.view(node) as view:
		f = [f for f in view]
		print(f"Enumerated {len(f)} functions for node {node}.")

At the moment, this is the output we are getting:

 >> Enumerating unrestricted.
Grounding...done in 0.1s
Enumerated 2 functions for node Pax6.
Enumerated 6 functions for node Hes5.
Enumerated 6 functions for node Mash1.
Enumerated 4 functions for node Scl.
Enumerated 4 functions for node Olig2.
Enumerated 4 functions for node Stat3.
Enumerated 2 functions for node Zic1.
Enumerated 3 functions for node Brn2.
Enumerated 19 functions for node Tuj1.
Enumerated 3 functions for node Myt1L.
Enumerated 1 functions for node Sox8.
Enumerated 1 functions for node Aldh1L1.
 >> Enumerating with limit.
Grounding...done in 0.0s
Enumerated 2 functions for node Pax6.
Traceback (most recent call last):
  File "/Users/daemontus/Downloads/test.py", line 47, in <module>
    with funs.view(node) as view:
  File "/opt/homebrew/lib/python3.11/site-packages/bonesis/views.py", line 271, in __exit__
    self.parent.control.assign_external(e, False)
  File "/opt/homebrew/lib/python3.11/site-packages/bonesis0/proxy_control.py", line 88, in assign_external
    return self.control.assign_external(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/clingo/control.py", line 368, in assign_external
    _handle_error(
  File "/opt/homebrew/lib/python3.11/site-packages/clingo/_internal.py", line 75, in _handle_error
    raise RuntimeError(msg)
RuntimeError: Program updates not supported!

We can work around this by not using the with environment, but this probably leaks some memory/process.

Bug: .boolean_networks() does not work

Good afternoon,

I have been going through your tutorial to learn how to use bonesis on my data and have noticed that the bo.boolean_networks() does not provide any solutions. At first, I thought that my dataset was the reason. However, I have then completely recreated your tutorial and still got the same error. Here is the error message that pops up:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [6], in <cell line: 1>()
----> 1 for bn in bo.boolean_networks(limit=2): # limit is optional
      2     print(bn)

File /media/ag-cherrmann/ischneider/bonesis-master/bonesis/views.py:96, in BonesisView.__iter__(self)
     95 def __iter__(self):
---> 96     self.configure()
     97     self._iterator = iter(self.control.solve(yield_=True))
     98     self._counter = 0

File /media/ag-cherrmann/ischneider/bonesis-master/bonesis/views.py:75, in BonesisView.configure(self, ground, **opts)
     73     print("Grounding...", end="", flush=True)
     74     start = time.process_time()
---> 75 self.control = self.bo.solver(*args, settings=settings,
     76         ground=False, **opts)
     77 self.interrupted = False
     78 self.configure_show()

File /media/ag-cherrmann/ischneider/bonesis-master/bonesis/__init__.py:84, in BoNesis.solver(self, *args, **kwargs)
     82 if "settings" not in kwargs:
     83     kwargs["settings"] = self.settings
---> 84 return self.aspmodel.solver(*args, **kwargs)

File /media/ag-cherrmann/ischneider/bonesis-master/bonesis/asp_encoding.py:65, in ASPModel_DNF.solver(self, ground, settings, *args, **kwargs)
     63 arguments = list(map(str,arguments))
     64 dbg(f"ProxyControl({arguments}, {kwargs})")
---> 65 control = ProxyControl(arguments, **kwargs)
     66 fd, progfile = tempfile.mkstemp(".lp", prefix="bonesis", text=True)
     67 try:

File /media/ag-cherrmann/ischneider/bonesis-master/bonesis0/proxy_control.py:8, in ProxyControl.__init__(self, arguments, **kwargs)
      6 self.cmdline_arguments = arguments
      7 self.input = ""
----> 8 self.control = clingo.Control(arguments, **kwargs)
      9 self.__simple = True

File ~/.local/lib/python3.10/site-packages/clingo/control.py:159, in Control.__init__(self, arguments, logger, message_limit)
    157         c_mem.append(_ffi.new("char[]", arg.encode()))
    158         c_args[i] = c_mem[-1]
--> 159     self._rep = _c_call('clingo_control_t *', _lib.clingo_control_new,
    160                         c_args, len(arguments), c_cb, c_handle, message_limit)
    161     self._free = True
    162 else:

File ~/.local/lib/python3.10/site-packages/clingo/_internal.py:41, in _c_call(c_type, c_fun, handler, *args)
     39 else:
     40     p_ret = c_type
---> 41 _handle_error(c_fun(*args, p_ret), handler)
     42 return p_ret[0]

File ~/.local/lib/python3.10/site-packages/clingo/_internal.py:65, in _handle_error(ret, handler)
     63 if code == _lib.clingo_error_bad_alloc:
     64     raise MemoryError(msg)
---> 65 raise RuntimeError(msg)

RuntimeError: In context '<libclingo>': '72' invalid value for: 'parallel-mode'

Could you please give me a hint what may be the reason for this error? Thanks a lot in advanced!

Kind regards,
Ilya Schneider

Problems with mixing `diverse` with optimization

Hi!

I'm not sure if my approach is correct, but I'm trying to do a diverse sampling of optimized networks using the following:

bo.maximize_nodes()
bo.maximize_strong_constants()
for bn in bo.diverse_boolean_networks():
    print(bn)

However, this fails with:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[7], line 31
     29 diverse = bonesis.DiverseBooleanNetworksView(bo)
     30 print(diverse.standalone())
---> 31 for bn in diverse:
     32     print(bn)

File ~/miniconda/envs/celloracle_env/lib/python3.8/site-packages/bonesis/views.py:173, in BonesisView.__next__(self)
    171             self._progressbar.close()
    172 elif self.mode == "optN":
--> 173     while not self.cur_model.optimality_proven:
    174         self.cur_model = next(self._iterator)
    175         self._progress_tick()

AttributeError: 'MPBooleanNetwork' object has no attribute 'optimality_proven'

Is this is a bug, or is the combination of diverse sampling and optimization currently unsupported?

I am also trying to run the ASP program returned by bonesis.DiverseBooleanNetworksView(bo).standalone(), and it is indeed returning something, but I haven't yet validated the results thoroughly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.