Download Links

Simulate 3D | SBW (Win32) | Bifurcation Discovery | FluxBalance

Monday, March 8, 2010

Nested Simulation Experiments

A couple of days ago, I posted a proposal for a Nested Simulation Experiment for SED-ML. There I proposed that instead of defining a new Simulation class for each experiment you’d like to run, it would be better for implementers and modelers alike to be able to compose simulation experiments out of primitives. That is instead of defining:

  • a TimeCourse Simulation experiment like this:

    <timeCourse id="s1" name="time course definition" algorithm="KiSAO:0000019">
    <uniformRange start="0" end="100" numberOfPoints="10" />
    </timeCourse>
  • and next like this:

    <timeCourse id="s1" name="time course definition" algorithm="KiSAO:0000019">
    <vectorRange>
    <value> 1 </value>
    <value> 4 </value>
    <value> 10 </value>
    <value> 23 </value>
    <value> 42 </value>
    </vectorRange>
    </timeCourse>

one could compose these same experiments with primitives. (Just as an aside, note that in the cases above a simulator supporting the simulation experiment would have to implement a different set of operations).

The Primitives

I would envision three primitives:

  • OneStep: this calculates one further output step for the model from its current state. Note that this does NOT have to mean one integration step. The simulator is allowed to take as many steps as needed, all that has to be fulfilled with this simulation class, is that, at the end, the desired output time is reached.
  • SteadyState: This brings the model from its current state to a steady state. This simulation class will also just provide one output row for attached data generators, the state of the model at steady state.
  • SetValue: This is not a simulation class, but rather a convenience function, to change a model variable/parameter. In this way it is akin to ChangeMath / ChangeAttribute / ChangeXML we would have to discuss the actual syntax of it.

These primitives then are used in a nested simulation experiment to describe virtually any simulation experiment. Through the nested class construct. This construct allows to refer to:

  • A task object, which defines the model and simulation experiment to be called repeatedly,
  • A range object, which defines how often the simulation task above is to be called,
  • A SetValue construct describing how model variables are to be changed. Note:that the SetValue construct will have to be able to refer to the ranges current value.

Additionally, flags would indicate, whether the model is supposed to be reset after each run or not.

Examples

So far the proposal, so how would this look in an example. Lets go through each one and make up some examples as we go along.

  • OneStep: This is a simulation class, causing the model time variable to be adapted from the current time with a given step (that determines where the desired output point is):

    <listOfSimulations>
    <oneStep id="s1" algorithm="KiSAO:0000019" step="0.1"/>
    </listOfSimulations>

    when used in a task, this simulation task simulates the model from 0 to 0.1. The data generators are supposed to be calculated to yield the desired outputs for time point 0.1.
  • SteadyState: This is another simulation class, so we would define it as such. Unfortunately KISAO does not currently describe any steady state solvers and instead mostly integrators. So suppose in the following that:

    KISAO:0000099 = steady state solver (it would probably somewhere below KISAO:0000018)

    <listOfSimulations>
    <steadyState id="s2" algorithm="KiSAO:0000099" />
    </listOfSimulations>

    when used in a task, this simulation task brings the model to steady state. Once finished the data generators are supposed to be calculated to yield the desired output points for the model variables at steady state.
  • NestedSimulation: So how would this now look in a nested simulation experiment:
  • <listOfSimulations>
        <nestedSimulation id="s3" algorithm="KiSAO:0000019"
                             resetModel="false" originalTask="task1">
        <vectorRange>
             <value> 1 </value>
            <value> 4 </value>
            <value> 10 </value>
        </vectorRange>
        <setValue target="/sbml/model/listOfParameters/parameter[@id='w']">
         <listOfVariables>
             <variable id="current" name="current range value" target="#current" />
         <listOfVariables/>
         <math>
             <ci>current</ci>
         </math>
        </setValue>
       </nestedSimulation>
    </listOfSimulations>

    The nested simulation above, would carry out task1 3 times. Each time the value of a model parameter ‘w’ is varied by applying one of the three values.  If task1 specifies a steady state primitive, then this snippet produces the steady state values for w=1, w=4 and w=10.

    Or we could have used a uniform range to sweep the parameter. Or a functional range, to vary the parameter in logScale for example.

    If task1 would refer to a uniformTimeCourse Simulation then this would actually perform a simulation, where a parameter is changed in steps. After each time we would see how the model reacts to this discrete parameter change.

Note that you could even define a uniform time course simulation using this approach. Here task1 refers to a ‘oneStep’ simulation task. We would just vary the models time each time:

<listOfSimulations>
    <nestedSimulation id="s3" algorithm="KiSAO:0000019"
                         resetModel="false" originalTask="task1">
    <uniformRange start="0" end="100" numberOfPoints="10" />
    <setValue target="#time">
     <listOfVariables>
         <variable id="current" name="current range value" target="#current" />
     <listOfVariables/>
     <math>
         <ci>current</ci>
     </math>
    </setValue>
   </nestedSimulation>
</listOfSimulations>

You could even think about nesting the nestedSimulation experiments in order to for example perform 2D parameter scans or what have you.

Conclusions

Defining simulation experiments through these primitives will open up SED-ML and make it really useful. These primitives are easy to implement. In fact they are already implemented in available simulators. They are what is needed to implement the proposed Range construct anyway.

So let us not be shackled by having to each time define a new simulation class. The nested approach here will be what is needed to define most simulation experiments. By adding new primitives later on it can be easily extended.

I’m perfectly happy to open it up further. What one could envision would be multiple <setValue> elements to change multiple parameters. or even multiple ranges, though then each would have to have an id, to be used in the SetValue constructs. But I’m sure it could be sorted out.

Wednesday, March 3, 2010

Supporting SED-ML

SED-ML, the Simulation Experiment Description – Markup Language, offers the possibility to exchange simulation experiments. That is, instead of receiving a model and wondering how you can make it do what it is supposed to do, you would simply run the accompanying SED-ML document and see the figures reproduced.

SimulationTool

As with any new standards initiative, it will only be taken up if there are computational resources, that make it easy to use, and of course if the standard can be helpful. Currently, with SED-ML in a very early stage it is already possible to exchange time course simulation experiments, but not much more. However, it could be extended easily, such as by using a Nested Simulation Experiment, as described at the link below.

But what about computational resources? As it so happens, I’ve created a new project:

LibSedML - libsedml.sourceforge.net/ 

There, I provide three libraries:

  • LibSedML – a .NET library for reading and writing SED-ML
  • LibSedMLRunner  – a library on top of LibSedML, that schedules and runs simulation experiments.
  • LibSedMLScript – a utility library, turning a human readable script format into SED-ML.

Three applications support these libraries so far:

  • SED-ML Script: This application provides an easy way to define new Simulation Experiments using the human readable script format. No more struggling with API calls or XML, a simple script defines a simulation experiment. It can also be readily tested right then and there.
    multipleplots
  • A web application provides the same functionality and provides a test bed, without having to download any software.
  • A plug-in for the SBW Simulation Tool, allows to run SED-ML files directly from it and provides capabilities for saving simple simulation experiments. (screenshot at beginning of this post)

The libraries and tools have been implemented using .NET, and have been confirmed to run fine on Windows, Linux and OS X!

 

Bergmann, Frank. A Simple Nested Simulation for SED-ML. Available from Nature Precedings <http://dx.doi.org/10.1038/npre.2010.4257.1> (2010)

Saturday, February 13, 2010

RoadRunner & C++/CLI vs. Embedding the MONO Runtime

RoadRunner, our simulation main simulation engine in the Systems Biology Workbench, has been written in C#. This allows RoadRunner to be used in scripting scenarios with languages like IronPython, or even from the csharp-shell or Windows PowerShell. But what if you wanted to use RoadRunner from plain old C / C++?

C++ / CLI

On Windows operating systems the obvious choice would probably be C++/CLI.  And really, the task could not be easier. Just add the RoadRunner reference to the application include the RoadRunner namespace and you are good to go:

   1: // RoadRunnerCLI.cpp : main project file.



   2:  



   3: #include "stdafx.h"



   4:  



   5: using namespace System;



   6: using namespace CSharpSimulator;



   7:  



   8: static void PrintResult(cli::array<double, 2>^ data)



   9:     {



  10:         for (int i = 0; i < data->GetLength(0); i++)



  11:         {



  12:             for (int j = 0; j < data->GetLength(1); j++)



  13:             {



  14:                 Console::Write(data[i,j]);



  15:                 Console::Write("\t");



  16:             }



  17:             Console::WriteLine();



  18:         }



  19:     }



  20:  



  21: int main(array<System::String ^> ^args)



  22: {



  23:  



  24:     sbwInterface roadRunnerInstance;



  25:  



  26:     roadRunnerInstance.loadSBMLFromFile



  27:         (L"C:\\Users\\fbergmann\\Documents\\SBML Models\\BorisEJB.xml");



  28:     roadRunnerInstance.setTimeStart(0.0);



  29:     roadRunnerInstance.setTimeEnd(100.0);



  30:     roadRunnerInstance.setNumPoints(11);



  31:     



  32:     cli::array<double, 2>^ result = roadRunnerInstance.simulate();



  33:  



  34:     PrintResult(result);



  35:  



  36:     return 0;



  37: }




The only drawback would be that this will not work on Linux or OS X.



MONO Embedding



So what about MONO Embedding? Or in other words, writing a C++ application, that would embed the MONO Runtime. This enables the C++ application to directly reference RoadRunner. The idea is basically the same as when using any SBW Module. First we get a hold of the RoadRunner module, or in this case an instance of the RoadRunner class:





   1: mono_set_dirs(NULL, NULL);



   2: domain = mono_jit_init ("LibRoadRunner.dll");



   3: mono_set_dirs(NULL, NULL);



   4: mono_config_parse(NULL);



   5: assembly = mono_domain_assembly_open (domain, "LibRoadRunner.dll");



   6: if (assembly == NULL)



   7:     cout << "Couldn't load RR assembly" << endl;



   8: image = mono_assembly_get_image (assembly);



   9: rr_class = mono_class_from_name (image, "CSharpSimulator", "sbwInterface");



  10: if (rr_class == NULL)



  11:     cout << "Couldn't get hold of the RoadRunner class" << endl;



  12:  



  13: // create new roadRunner instance



  14: rr_instance = mono_object_new (domain, rr_class);   



  15: // call constructor



  16: mono_runtime_object_init (rr_instance);




Next one would get hold of all the method one would like to call, as in:





   1: // get the loadSBML 



   2: methodLoadSBML = mono_class_get_method_from_name(rr_class, "loadSBML", -1);



   3: if (methodLoadSBML == NULL) 



   4:     cout << "Couldn't get loadSBML" << endl;



   5:     






finally for calling the method all that’s needed is to wrap the arguments into arguments that MONO would understand:





   1: void HostRR::LoadSBML(const char* model)



   2: {



   3:     MonoString *str = mono_string_new (domain, model);



   4:     void *args[1]; args[0] = str; 



   5:     MonoObject *exception = NULL;



   6:     mono_runtime_invoke(methodLoadSBML, rr_instance, args, &exception);



   7:     if (exception != NULL)



   8:     {



   9:         PrintException("Error while loading SBML", exception);



  10:     }



  11: }






continuing like that for the remaining methods that have to be available for C++. For a client calling into RoadRunner the result would look like this:





   1: #include "HostRR.h"



   2: #include <iostream>



   3: #include <iomanip>



   4:  



   5: using namespace std;



   6:  



   7: void PrintResult(double** data, int numRows, int numCols)



   8: {



   9:     if (data == NULL) return;



  10:  



  11:     for (int y = 0; y < numRows; y++) 



  12:     {



  13:         for (int x = 0; x < numCols; x++) 



  14:         {



  15:             cout << setiosflags(ios::fixed) 



  16:                  << setw(7) << setprecision(2) << setfill(' ') 



  17:                  <<  data[y][x] << "\t";



  18:         }



  19:         cout << endl;



  20:     }



  21:     cout << endl;



  22: }



  23:  



  24: int main(int argc, char* argv[])



  25: {



  26:     HostRR instance;



  27:     



  28:     instance.LoadSBMLFromFile("BorisEJB.xml");



  29:  



  30:     instance.SetTimeStart(0.0);



  31:     instance.SetTimeEnd(1100.0);



  32:     instance.SetNumPoints(100);



  33:     



  34:     int numRows; int numCols;



  35:     double** result = instance.Simulate(&numRows,&numCols);



  36:     



  37:     PrintResult(result, numRows, numCols);



  38:     



  39:     return 0;



  40: }






And the advantage? It runs like a charm on Linux and OS X. However I did struggle a bit with getting it compiled. After all one draws several dependencies when embedding mono, the most troublesome for me proved to be glib2 and OS X. At the end the problem turned out to be that Snow Leopard liked the executable to be 64bit by default, but the glib libraries were only available for 32bit and ppc. Since I have Qt installed on all my systems, I used a qmake project, to generate the make files (or Xcode projects as the case may be). So here is what worked for me:





   1:  



   2: TEMPLATE = app



   3: CONFIG = console



   4: TARGET = HostRR



   5: DEPENDPATH += .



   6: INCLUDEPATH += . 



   7:  



   8: mac { 



   9: CONFIG += x86 



  10: CFLAGS += -arch i386



  11: INCLUDEPATH += /Library/Frameworks/Mono.framework/Versions/2.6.1/include/mono-1.0 /sw/include/glib-2.0 /sw/lib/glib-2.0/include



  12: LIBS += -L/Library/Frameworks/Mono.framework/Versions/2.6.1/lib -L/sw/lib -pthread -lmono -lpthread -lm -lgthread-2.0 -lglib-2.0 -lintl



  13: }



  14:  



  15: unix { 



  16: DEFINES +=_REENTRANT -pthread 



  17: INCLUDEPATH += /usr/include/mono-1.0 /usr/include/glib-2.0 /usr/lib/glib-2.0/include



  18: LIBS += -Wl,--export-dynamic -pthread -lmono -ldl -lpthread -lm -lgthread-2.0 -lrt -lglib-2.0 



  19: }



  20:  



  21: win32 {



  22: INCLUDEPATH += "C:\Program Files (x86)\Mono-2.6\include\glib-2.0"  "C:\Program Files (x86)\Mono-2.6\lib\glib-2.0\include" "C:\Program Files (x86)\Mono-2.6\include\mono-1.0"



  23: LIBS +=  -L"." -lmono



  24: }



  25:  



  26: # Input



  27: HEADERS += HostRR.h



  28: SOURCES += HostRR.cpp main.cpp



  29:  




If you’d like to give it a try, I’ve posted all the source to sourceforge. The results are right here:



http://jdesigner.svn.sourceforge.net/viewvc/jdesigner/trunk/csharp/HostRR/



Conclusions



We’ve seen, that accessing a .NET assembly from C/C++ is really no issue at all. C++/CLI is a great language it provides access to all of the .NET framework in a snap, however it will lock you in to the Windows world. With MONO Embedding, it is easy to break out! Given the reflection capabilities of .NET I believe the way to go forward would be to have a wrapper generator, that would just write the wrapper code.



Going forward if I were to use C++ to interact with RoadRunner, I’d probably combine the best of two worlds by falling back to C++/CLI on Windows systems and Mono embedding on Linux / OS X. But this might be a personal preference. 

Tuesday, February 9, 2010

Computational Tools for the Annotation of SBML Models

I was asked to give a brief talk  for the Semantic Web in Biomedicine Seminar, on computational tools that make the task of using all the great ontologies (like MIRIAM, SBO, ChEBI, UniProt, KEGG) that we have come to love easier.

I will add the full presentation below. However, as always without all too much text, thus I’m going to continue below.

I’m deeply involved with the Systems Biology Workbench (SBW), a lightweight framework that enables applications to share their functionality regardless of operating system or programming language. With SBW we also deliver a full toolset for modeling, simulating and analyzing SBML models. About five years back we started to get involved with SBGN. So today it would be great if we could automatically generate SBGN diagrams out of our SBML models. What is needed for that are annotations. Not just any annotations but annotations in the form of SBO ( the material entity branch) would be perfect. Unfortunately this is not quite enough. Additional MIRIAM annotations are needed for example to describe complexes in more detail.

I’ve been looking at this for some time and there are a couple of interesting developments to mention, of course first and foremost the EBI Web Services. They certainly make the work much easier. I introduce the:

  • BioModels Web Service
  • SBO Web Service
  • MIRIAM Web Service
  • Ontology Lookup Web Service

Each web service is briefly tested, using a Generic Soap Client, as this will allow to show the sort of information that is being provided first hand.

Of course it would be great if one would not have to hunt each Web Service down and it would seem that others had the same idea. I mention libAnnotationSBML first, a neat Java library that promises to provide a unified interface for a whole list of web services:

image

(photo grabbed from Neil’s presentation on Slideshare). The only drawback I could find with it is that the library is IMHO not quite ready to use by non Java geniuses. Everyone hearing me: If you are developing a library … especially a library for Java / .NET or any of the other cross platform virtual machines … please please provide a binary for people to use.  It’s been a while that I worked with Java, and an ant build script that won’t work is trouble for me. As it turned out the build failed because just of a couple of missing jar files and a test failure due to changes in the SBO. Still at the end of it all I ended up with a jar file and no instructions on what to do with it. I’ve seen great demos of libAnnoationSBML with the SBMLReactionBalancer for example. This could be made available online as binary as is …

The presentation will go on to introduce SAINT: a lightweight integration environment for model annotation. It follows the same great idea as in libAnnoationSBML of hunting down the individual web services for annotations of your SBML file. However, whereas libAnnotationSBML is a Java library, SAINT is nifty web application based on the Google Web Toolkit(GWT). As such it really brings a long a snappy AJAX UI. SAINT has a lot of potential, but again it would seem I was out of luck, I could not manage to get a model annotated. Here is what went wrong: a) no upload button, but that is fine copying the SBML to clipboard and pasting it was not all that hard b) once I clicked “Annotate” however a whole bunch of Asynchronous worker bee's must have been sent out in order to fetch all my new Annotations. But when they came back they brought along a whole list of annotations I had no interested in:

image

The above image represents all the results found for “glucose”. And while it is great to find so many Pathway Commons Identifiers, the link to Pathway Commons lead to 404. The trick seems to be for me to disable the “New Reactions” checkbox in advanced options. Then I received a couple of SBO terms for my model, however not much more. But SBO terms are a good start, so from here I went to the “Get Annotated Model Code” tab, but try as I might I was never able to actually retrieve my annotated model. 

image

Looking at other currently available software tools like CellDesigner and COPASI, both tools that support MIRIAM annotations I am not sure whether users of the tools will take full advantage of the Annotation process. Thus I end the presentation with a couple of screenshots of software tools using the EBI Web Services, to interact with the BioModels Database, resolve the publication citation and visualize the annotations in a way better suited to the community.

image

Why should we just display the ChEBI identifiers, when we could just as well show a formula, or the name, with a click revealing the full set of annotations.

Tuesday, January 19, 2010

RoadRunner and the new test suite

Yesterday the SBML team announced a new release of test data for the SBML Test suite. So of course I had to check how roadRunner fares in it.  A re-run of the test suite with only SBML Algebraic Rules and the ‘fast’ flag disabled gives the expected result of:

2010-01-19_-_TestSuiteResults 

All green! Just as it was meant to be. I really should make a new release of SBW soon! Lots of new things up and coming the highlights for roadRunner will include acronyms like SED-ML and SBRML …

Stay tuned!