Category: Science

Ipython notebook ans some statistical distributions

Bernoulli distribution

It was quite a bit that I wanted to have a go to play with the ipython notebook, but I wanted to do it with something that was quite interesting and useful.

The IPython Notebook is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document

– from the docs

This means that you can document your process and or exploration using Markdown, which is than beautiful rendered in html, and have also python code executed, with the graphs that are going to be embedded and will stay in the document.

I think it’s a very valuable tool, in particular when you are doing exploratory work, because the process of discovery can be documented and written down, and it a great way to write interactive tutorials.

For example, in this notebook, I’ve plotted the Probability Density Function of several statistical distributions, to have an idea how they are shaped, and which one to pick as base when creating new bayesian model.

You can see how it looks like on nbviewer

exponantial distribution

Ggplot2 graph style with matplotlib

Gg2plot is an amazing library to plot and it’s available for R to create stunning graphs. GGplot2 takes a different approach from the classic library, and instead of offering a classic line/points approach permits to combine these elements (example), which is a similar root took by D3js. If you are using the scientific python stack (matplotlib, numpy, scipy, ipython) you have the very good matplotlib to plot and have all your graph app.

For example a bunch of sin and cosine generated by the following code:

look like this:


Instead if we set up a ggplot2 style, the graph looks like this:


You may prefer one or the other. Anyway if you like the last one, just download this matplotlibrc and save it as ~/.matplotlib/matplotlibrc, and all your graph will have that style as default.

The matplotlibrc has been inspired by this post, I’ve just updated with the latest matplotlibrc from matplotlib 1.2.1 version.

Have fun!

Edit: Bonus plot, code in the gist.


How to use Neuronvisio to select particular sections of a NEURON based multi-compartment model

Displaying and visualizing selected sections in multi-compartmental models in 3D it’s quite an hard task, however the info and the clarity that is possible to achieve is worth the effort.

Let’s say you have your multi-compartiment model ready in NEURON and you are interested to show in 3D selected sections of the model with arbitrary colors (for example, to show where certain stimuli are applied), like I did in my Medium Spiny Neuron model to show which spines get stimulated:

spiny MSN with stimulated with different trains in selected spines

spiny MSN with stimulated with different trains in selected spines

Neuronvisio offers a nice API, from the visio module, accessible as controls.visio.select_sections(secs_list, scalar_value), which makes this operation easy.

For example, let’s take the pyramidal neuron model that comes as an example with Neuronvisio.

Let’s say that we want to select the soma, the iseg and the first section of the myelin, and we want to give them arbitrary colors.

To achieve that we can easily run:

controls.visio.select_sections([“soma”, “iseg”, “myelin[0]”], [1, 0.5, 0.2]), obtaining this picture:

Selecting and coloring special sections with Neuronvisio

Selecting and coloring special sections with Neuronvisio

Quite handy and pretty fast, don’t you think?

Some thoughts about NeuroML and standardization

I’m pleased to say that we have released Neuronvisio 0.8.5, which has several small improvements and better documentation. I’m pretty sure that there is always room to improve the documentation.

Anyway, first of all the cerebellum network rendered in Neuronvisio, with the model taken from the NeuroML website


Cerebellum Network, taken from the NeuroML example pack

The idea with this release was to demonstrate the ability of Neuronvisio to visualize also Network models which are instantiated in NEURON. To note, this ability has been there from version 0.1.0, but now we are beaming on it.

Neuronvisio is able to import 3 different files: hdf5 structured in Neuronvisio format, hoc files, and NeuroML.

The first file is our way to approach hdf5, which gives us the ability to save all the data of a simulation, plus the model itself in one single file, which can then be reloaded and moved. We do all the work here.

The other two are files format where Neuronvisio does not import directly, but let’s NEURON do the heavy-lifting, to avoid any duplication. The hoc format is classic NEURON interpreted script, while NeuroML is an effort to standardize the way neuronal model are encoded.

In particular I would like to stress the last point: Neuronvisio does not have an ad-hoc NeuroML importer, but re-use the one provided by NEURON. We now just exposing an easy way to load a NeuroML file directly in Neuronvisio with the load method from the Controls class

from neuronvisio.controls import Controls
controls = Controls() # starting the GUI
controls.load('path/to/my_model.xml') #or .h5 or .hoc

or directly launching the program, if you prefer

$ neuronvisio [path/to/my_model.xml] # or .h5 or .hoc

this gives us one powerful interface to simplify the life of a user.

Of course, if your model is in python, you can always run it within Ipython as standard python file

$ neuronvisio
In [1]: run path/to/my_model_in_python

The only problem is the NeuroML importer from NEURON does not handle properly the Network file of NeuroML, and this has been registered as issue #50 on our bug-tracker. This belong more to NEURON then Neuronvisio, but they don’t have a bug-tracker, so we logged on ours tracker and we will link any other place where the discussion will take place. NEURON has an amazing forum with quite instantaneous answers from the NEURON community, including Hines and Carnevale, and we will bring the issue over there.

So, we didn’t write our NeuroML importer, because there is no point to replicate what a software already does. That’s why we are now collaborating with the writing of the libNeuroML library, to have one good library that permits to load any NeuroML model properly, and then give the ability to the developer to map it to its own data-structure.

This is the same approach used in the SBML community, which I think is very powerful.

P.S.: So how did we manage to load the Network in NEURON and visualize it in Neuronvisio, if the NEURON (sorry, NEURON has to be written all capital to be precise…) NeuroML importer is not up to the job yet? We have used the neuroConstruct program, which is able to export a model to NEURON, and used the hoc files to load the model up.

Tools for a computational scientist

So, how do you keep track of your work?

If you are in a wet lab, usually you end up using a lab book, where all the experiments are recorded. You can replicate the experiment, and do something new. It’s pretty cool system, although I think it’s not great for computational scientist. In computational science there is the same problem of recording what is going on, and what happened before. On top of that there is also the problem of sharing the program with other people to address reproducibility. Therefore the problem can be broken down to two different sub problems:

  • record the changes happening in a computational project, in particular to the code used to run the project
  • record the results of different execution and link them with a certain state of the code.
A classic approach is “do nothing”. The code sits on your hard drive somewhere. Maybe it is organized in folders, and descriptive file name. However there is not history attached, you have no idea what’s going on, and which is the latest version. As you guessed this is not a cool position, ’cause you spend time thinking how to track your work instead of doing your work, and you have the feeling that you don’t know what’s going on. This is bad. 
Fortunately, this can be solved 🙂
This is one of the problem which could be solved using a Version Control System, which are exactly invented to track changes in text files (and more).
I found very useful to work with Git, which is an amazing Distributed Version Control System (DVCS). The most important benefit that you get one using a version control system, and in particular git is that you have the ability to be more brave. This is because Git makes very easy to create a branch and test something new as you go on.

Branch in Git are quick and cheap! Easy to experiment!

Did you ever find yourself in a situation where you wanted to try something new, which could break a lot of different things in your repository, however you didn’t want to mess with your current code?
Well, Git gives you the ability to create a branch very cheaply, to test your new crazy idea and see if it works, in a completely isolated environment from the code that is sitting on your master branch. This means you can try new things, which tends to be quite important in science, because we don’t usually know where we are going, and try more than one solution opens up a lot of different possibilities.
The other good thing is you have a log, with whatever happened, and you can try to go back to the version that was working and restart from there. For example, this is the commits log from neuronvisio.
I’ve ran a hands-on crash course at the EBI about Git, (the repo). The course was very well-welcomed and people started to understand the power of using fast tools to free some mental space.
Another big plus for Git is the ability to host your project on github, which makes collaboration super-easy. These are the contributors for Neuronvisio for example.
Using a version controlled system is a good idea, and integrating it with Sumatra is also a very good idea. Sumatra automatically tracks all the parameters and versions of the programs used. I’ll talk about it in a later post, for now have a look to the slides:
Sumatra and git [slideshare id=3802681&w=425&h=355&sc=no]

Few tips how to write a good paper

There are tons of guides published on journals how to write a good paper, so these are some quick tips which could be added on top of these. I’m trying to be general, but I’m writing this mostly for my use and they reflect my view.

I’m using the second person, so it’s more direct and motivational.

Feel free to leave comments/integrate these.

First of all, state the problem.

If you are working on something, most probably you are trying to solve a problem. Well, you’re not alone. People are working on something that is close to your research topic (if not the same) and you have to review their work. In big depth and with a big breath.  It means you have to address the problem from all (at least the majority) of the points that comes to your mind.

Dont’ talk about your solution, yet.

Then you have to talk about the different solution people provided so far. Go into the details, pick up if have been re-used somewhere else and follow that lead. On and On. Be exhaustive.

Basically put the readers in the position where she will be able to say exactly what are the already proposed solutions so far, their strength and their weakness.

When you are finished with that, then you can start to present your solution, and what exactly it is the matter.

Describe the key points and be very careful to be as objective as possible.

It works it may be good enough in a non-academic environment. But not in academic environment. You have to motivate why it works with hard data, numbers, and logic arguments. Anything that can back up what you are saying is paramount. Possibly comparison or exact pros and contros. If you don’t do that then, it’s not good enough. Even if it works. You will be asked for more.

The assumption that you have made, or reason why you have used some solutions instead of others need to be explained. It’s difficult to pick these up, because you are very familiar with these choices. Most of the time this will look like self-explanatory. But it’s only for you.

Scientific methods described plainly

Why you are doing something and what is your thinking process is very important. A reader expect to follow you in the journey. That’s why you need rational hypothesis to drive your research.

You state your hypothesis, then you run experiments and simulations to disprove them. Try everything you have to bring them down. If you can’t, well then maybe you have something that you can put under more scrutiny, but you are on something.

Good luck.

Neuronvisio ModelDb plugged in released into the wild

We have just released Neuronvisio 0.7.0.

With this release it is possible to browse the models present on the ModelDb database, and have a look at the readme and at the properties of the Model.

Model Information and properties are presented in a quick way to the user

The Load Model button permits to download, extract, compile and load the model in one click. Sweet.

The other big things is that I didn’t write all this code, but actually 0.7.0 it’s the first release that features a contribution from another person (before was one man band!). Uri wrote the scraper for ModelDb and I’ve hooked it together in the GUI. We developed using the pull-request framework, which github makes very nice and clean.

If you’re interested in computational Neuroscience, and you are using NEURON, give Neuronvisio a go.

Impacts graph on Neuronvisio repo

Lately, github has rolled out a series of graphs to visualize the commit through the time.

An interesting one is the impact graph. This is when everything started


Neuronvisio started as one man band project, actually as a spin-off of my PhD, when I realized that I was building something that was missing and that could be useful for other people as well. So I just detached the neuronvisio code in is own package, and released online. With time, Neuronvisio started to get some users, and people actually wrote enthusiastically on the ML about it. I was proud. Last August/September Uri decided to contribute to the software, to increase the features of it, in particular to plug it with ModelDB, making easy to browse the database, and to download and load a model directly with one button. I helped on the GUI part, while he took care of the ModelDB representation.

This is the graph of his impact on the software, at later stage.

I really enjoyed the Pull request method, and I have to say that github made the collaboration very easy and nice.It was good fun and I’m looking forward to other contributions.

The new features are not yet released (we’ll do in a bit of time), however if you can’t wait, you can grab the code from github master and give it a go!




The last ride

atlantis take off

The shuttle Atlantis is in the space. Today for the first and last time, I just followed the launch in streaming from the NASA tv. Before I saw only movies with the shuttles, like the sci-fi Armageddon.

But today I was able to follow the whole launch, just streamed directly from the NASAHDTV channel.
I’ve followed the lift-off’s procedures and I saw it live. It was emotional.

Thinking that after 1 min and 40 seconds the Atlantis was already up in space. It was possible to see our planet just down below. These guys were up in space. And yes I know there is the ISS floating up there (BTW it’s exactly where the shuttle is going) with people inside all the time, but seeing the stream and thinking that in so small amount of time the shuttle was flying so high it’s something big.

Now the shuttle program will be shut down and NASA is looking for something new. Let’s see what they come up with, if funding holds. ESA and other players are still up and running, and also the NASA has some plans for the future.

For the time being, Soyuz spacecraft will be used to continue servicing the ISS.

The shuttle will be up there for another 10-12 days, will dock to the ISS and then come back home. Best of luck!

Anyway, I’m kind of sad. The shuttle was cool.

Last lift off, Enjoy the last ride.

How to get your thesis in

A friend of mine, Julia, has written a little guide to classic things required when writing the thesis and the setting up for the viva, which apply for EBI predocs enrolled with the University of Cambridge.

This was a piece on our internal wiki (which nobody ever reads because is a closed one and it’s rather impossible to find, but the problems with closed wikis is a topic for another post). So I asked her if it was ok to grab it and post it here, which, at least, is in the open of the internet sea, and people could maybe actually find it with google or any other way.

These information were correct up-to June 28, 2011. As the matter of fact, she is now a Doctor :). Bare in mind this applied for a PhD thesis in the Biological Science umbrella, and the last part is EBI specific. Therefore is not at all official, they are just tips and hooks to speed up the process. Check always the latest rules from the University.

With that said, here you have it.

P.S.: Template-wise check out the amazing classic thesis. You’ve got to tune it, just a bit.

Thesis submission and viva

Written by Julia Fischer on June 28, 2011

When the time has come and you would like to submit your thesis to the Board of Graduate Studies, there are one or two things you might want to know.

1. Find a template

Most people (at least in the natural sciences) will write their thesis in LaTeX. There are a various templates out there. Please add your template here if you have found a nice one.

2. Restrictions and rules for the thesis

If you are submitting to the department of Biology, you will have a word limit of 60,000 words, but you can always check the newest information here.

3. Abstract and examiners

It is a good idea to start thinking about your examiners a couple of months before you submit. You will have to email the degree committee (, saying that you will submit soon. They will then send you a form to fill. You have to submit this form with your thesis title and planned submission date back to them together with your thesis abstract (which shouldn’t change significantly from there on).

They will then contact your supervisor who has to suggest two examiners for your viva. You might want to mention this to your supervisor in a meeting before you have to submit the forms, so you can discuss possible choices. One examiner needs to be internal (i.e. University of Cambridge) and one external.

4. Initial submission

When you are ready to submit, you need two soft-bound copies of your thesis. If you are sure that there will be no corrections, you can submit a hard-bound copy directly, but if you need corrections, you will have to pay for the expensive hard-binding again. Here is a lot of information about all the forms and declarations you need on submission day.

5. Your viva

It is advisable to try and set your viva date for the end of the month if you are going for the bridging postdoc contract, because you will receive the postdoc stipend from the 1st of the month *after* your viva. That is, if your viva is on the 1st of the month you will lose the pay raise for a full month.

Poke your supervisor to email the graduate office in Heidelberg and HR at EBI directly after your viva to confirm that you have passed and theat he/she would like to employ you as a (bridging) postdoc, so they can prepare your postdoc contract.

Good luck!

6. Submission of corrections and hard-bound copies

You do need to submit a hard-bound copy to the Cambridge University Library, although you may have to hand the copy to the degree committee, if you are faster that Cambridge burocracy. EBI will usually pay for the hard-bound copy that they would like for their own library, but you will probably have to pay for the other copies yourself. All about submitting hard-bound copies can be found here.

7. Congratulations!

You’re done!