Scripting bioLQM
bioLQM can use scripts to automate more complex actions than on the command line. Script mode is triggered with the -s switch as first argument. It requires the name of a script file to execute. Additional arguments (after the name of the script file) are used as arguments for the script. The following command launches the script in script.js and provides the name of a model file as script argument:
java -jar bioLQM.jar -s script.js model.sbml
In script mode, bioLQM creates an instance of LQMScriptLauncher, which serves as single entry point for the bioLQM API. This object is available as the lqm variable. bioLQM features which are not available through this object can be used by importing the right java classes, but their API is more likely to change. The script launcher provides the following methods wrapping the core features:
Retrieve a format with it's specialized import/export methods, using the getFormat method. Models can also be imported or exported directly from the script launcher using the loadModel and saveModel methods respectively.
Perform model modifications with the modifyModel method.
Run an analysis tool on a model through the getTool method.
Command line arguments are available in the lqm.args array
Using the built-in javascript engine
bioLQM supports script written in the javascript language, the script file must have a .js extension. The following example script opens a model given as argument, and generates all single knockout perturbations, saving each modified model in a new file.
filename = lqm.args[0]
model = lqm.loadModel(filename)
nodes = model.getComponents()
for (i in nodes) {
node = nodes[i]
perturbed = lqm.modifyModel(model, 'perturbation', node+'%0')
lqm.saveModel(perturbed, filename+"_perturbed_"+node+".boolfunctions", "boolfunctions")
}
Using you favorite engine
While Java supports only scripting with javascript out of the box, it provides a generic scripting API allowing other languages to be used, through additional script engines. JAR files containing supported engines can be placed in the extensions folder: they will be added to the classpath and bioLQM will use the right engine dependng on the extension of the script file. This feature has been tested with Jython but other engines should work as well.
For some reason, loading a python script through this API is much slower than using the Jython API explicitly. GINsim uses the same mechanism for scripting but explicitly depends on Jython and provides faster startup of python scripts, including the ones which use only bioLQM API (it also detects other languages properly).
A python version of the previous example.
filename = lqm.args[0]
model = lqm.loadModel(filename)
for node in model.getComponents():
perturbed = lqm.modifyModel(model, 'perturbation', node+'%0')
lqm.saveModel(perturbed, filename+"_perturbed_"+node+".boolfunctions", "boolfunctions")