New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New BioNetGen interfaces for console and file based access #168
Conversation
Call any arbitrary BNG command using a context manager and Python kwargs. Example: with BngConsole(model) as con: con.action('simulate_ssa', t_end=10, n_steps=100) The context manager automatically loads the model into BNG and cleans up on exit.
'simlulate_ssa' to 'simulate({method=>"ssa",...})', which is the preferred call method. Note that the "ssa" argument has to be passed to BNG with enclosing quotes. This is true of all string arguments. So we'll have to keep this in mind as we implement more wrappers around BNG actions using the console interface. Any args passed in as strings will have to be type checked and enclosed in quotes when building the action call.
BioNetGen requires string arguments to be double quoted and booleans as 0 or 1. A small class method _bng_param now handles this automatically. Also, two quick fixes: BngConsole now extends object, and network generation in run_ssa() should be done within try block, not finally block (more fault tolerant).
Both BNGFileInterface and BNGConsole have very similar API and usage. The difference is that BNGConsole executes commands instantly and waits for the response using the pexpect library. BNGFileInterface buffers all BNG commands and outputs them to the .bngl file for execution in one go. BNGFileInterface is typically faster (no repeated command/response lag) and cross-platform; BNGConsole is great for interactive use and development.
Cleanup and verbose arguments to run_ssa and generate_network are now handled better - verbose is passed to BNG's generate_network, and cleanup is now passed to the BngFileInterface constructor rather than the BNG simulate call as expected. Thanks to @JamesPino for catching the cleanup arg issue.
Looks good to me. @jmuhlich, do you want to take a look? |
@@ -12,7 +12,7 @@ before_install: | |||
- conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib sympy networkx | |||
nose h5py | |||
- pip install -i https://pypi.binstar.org/pypi/simple pygraphviz==1.3rc1 | |||
- pip install python-coveralls | |||
- pip install python-coveralls pexpect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also pedantic: I think anaconda offers pexpect (see http://docs.continuum.io/anaconda/pkg-docs), so ideally we'd install that with conda rather than pip.
I think I've addressed all your feedback @jmuhlich - let me know if there's anything I missed. The |
Hmm, it's good to note that your "allow synthesis instead of initial conditions" fix is rolled up in here too. |
I've added two new classes,
BngFileInterface
andBngConsole
, for interacting with BioNetGen. Both extend an abstract base classBngBaseInterface
. I've adjustedgenerate_network
andrun_ssa
to useBngFileInterface
.Both
BngFileInterface
andBngConsole
have very similar API and usage. The difference is thatBngConsole
executes commands instantly and waits for the response using thepexpect
library and the BNG Console interface.BngFileInterface
buffers all BNG commands and outputs them to the .bngl file for execution in one go.BngFileInterface
is typically faster (no repeated command/response lag) and cross-platform;BngConsole
is great for interactive use and development, but thepexpect
library doesn't support Windows.