Tuesday, May 29, 2012

libScopes interfacing in Python

After finishing off an easy task for the biographer project, it was time to move onto more challenging stuff.

At the outset interfacing libScopes with Python seemed straightforward. Just use ctypes and the library will be magically imported into Python. But soon I realised that ctypes works well only with C libraries and not C++. There are ways to get around issues like name mangling by using extern "C",  but then I ran into many problems with classes.

After spending a considerable amount of time on this method I finally decided to abandon ship and choose SWIG over ctypes. SWIG for Python converts your C/C++ code into Python extensions. It does this by generating a lot of wrapper code. Though this may potentially slow down processing, at least SWIG supports C++.

SWIG took quite a while to get used to. SWIG uses .i files to define the Python interfaces to your C++ code. I just %include'd all the C++ headers and thankfully it worked. Just a few issues with some typedefs that had to be redefined. A few modifications also had to be made to the libScopes library, mainly commenting out functions that had been defined in the header file but the function source was missing. Also included definitions in the Makefile to use SWIG to generate the Python Extension. Takes a bit of time to compile.

Phew! The Python library is ready, but what was the point of all this? Well, to run simulations of SBML files, libScopes had to be run on the server. I chose to run it as a module in Python. The code to import the SBML file and run a single iteration(dScopeStep) can be found in the models/scopes.py file in the server repository. An additional controller has been added for the simulator. Also JSON exchange(import/export) code had to be written on the server and client to communicate the states of the boolean network.

There is one small flaw in the method that I've used. The SBML is imported for every single iteration on the server. I could not avoid this as the session variable in web2py can only store objects that can be pickled(can be converted to a string). Apparently SwigPyObject cannot be pickled. The network is stored in a Net class object whose type in Python is SwigPyObject. I'm looking into alternatives like mmap.

A live server can be tested at

 
A bit of lag can be seen at every iteration. This is due to the SBML file being imported every time. Also the reaction nodes are also turning green. 

Quite a long post! Now I have to look into Lian's libSBGN.js code and check how it can be integrated. Also the simulator using libScopes output has to be verified.

Saturday, May 19, 2012

R BoolNet import done!

It has been an exciting week. Completed the first task of my timeline, that is importing R's BoolNet files into jSBGN. The coding part wasn't difficult, reused most of the code written for booleannet import. Most of the time was spent in navigating HTML, including js files and reading chromium's console logs. It is quite surprising that to find one small bug I had to write multiple console.log statements across 2-3 files. Finally caught the bug and the fix was just 9 characters! Desperately need to find a better method of debugging js code.

Also learnt two new tools this week, jslint and jsdoc. Both are pretty cool and do their job well. Though, jslint does not come across as a likeable person. Also had some discussion on the dev mailing list about reorganising the repos. That too is an important task. Workload for the weekend: thinking about the repo layout and getting started with libscopes in preparation for next week.

PS: Got my GSoC package. Don't have it in my hands, can't wait to get back to the institute!

Wednesday, May 9, 2012

Importing Boolean Network formats and libscopes

On to the second week of GSoC, started with editing the ServerInstallation page of the wiki. Modified it to support Ubuntu. The installation scripts present in the server repository are a bit outdated and need to be modified to run on the latest Debian/Ubuntu systems.

Then I moved on to studying the source code of BooleanNet import module. It has been written in javascript and converts BooleanNet files to jSBGN objects which consists of nodes, edges and update rules. The layouting is done by graphviz currently(on the server side) which generates an SVG of the network. The simulator runs on the client side and consists of code to modify the SVG's at every  iteration.

I also looked into R's BoolNet. It's file format closely matches BooleanNet's and the existing function for importing BooleanNet only has to slightly modified to support BoolNet. I'll start writing code for this next week.

I had a discussion on the biographer-dev list about how to incorporate libscopes in the boolean network simulation module. It was decided that libscopes can be used for simulating SBGN PD networks and the simulation code would utilise libscopes API. Hence the boolean network simulation for PD has to be executed on the server side. For the libscopes API ctypes seems a better option as it has lesser overhead and provides a more direct route.

Finally, the remaining task for this week is to analyse the biographer-ui.

Thursday, May 3, 2012

Biographer: Boolean Network Simulation

I know this is a bit late, but still here it is. I got selected into GSoC 2012! My project is on Boolean Network Simulation and the organisation is biographer. I'm totally psyched to work on this project.

On the first day of work, I updated my system to Ubuntu 12.04, got all the necessary softwares installed, took a lot of bandwidth and time on my 3G dongle. But it was worth it. Ubuntu 12.04 is really awesome, Unity is finally usable, but my laptop being a bit old I need to run Unity2D without all the flashy effects.

Ok. So back to the topic of the post. I needed to get the biographer server up and running. So installed all the dependencies including web2py, python-simplejson, graphviz, libsbml, the layouter and the ui. I had to use the latest version of libsbml as the old version wasn't compiling. The scripts were a bit out outdated so fixed them for Ubuntu, replaced the experimental layouter with the normal one. Then copied the simulator code to the static directory. Modified Get.py to use my local installation of the simulator. And voila, it worked, a huge network popped up in my browser(which I had to change from my usual Firefox to Chrome).

That was a bit detailed, but as it was the first day I still have the enthuthasiasm to blabber about every small thing that I'm doing. Next few days understanding the existing tools in Boolean network simulation like the python booleannet and R's BoolNet. Followup posts would hopefully focus more on the ideas and a shorter summary of the work.