## Cellular automaton model of bacterial biosensors

So this fortnight at the doctoral training centre, we've been from "Hello World" to image processing in C and Perl. Yeah.

Anyway, before my brain explodes from over-knowledge-ness, I thought I'd blog about the program I made! It's a cellular automaton (like Conway's Game of Life) that essentially represents lots of bacteria immobilised on a silicon chip. I based it on this paper from 2004. In my simulation, the cells grow, divide and die based on how much food they are getting from the environment.

The bacteria contain a special gene from fireflies called luciferase, which allows them to bioluminesce. Halfway through the simulation, the cells are bathed in a solution that causes DNA damage. This activates the luciferase gene. The idea behind the original experiment was to use bacteria to sense when a molecule causes DNA damage, in order to screen for molecules that might cause cancer.

The simulation outputs a rudimentary display to the terminal. The glowing bacteria are represented by the letter "O" and the wild-type bacteria are shown by the "#" symbol.

If you want to read more about the biological background and the implementation, you can read my report, or try compiling and running my C code.

This was a really good opportunity to test out all the things I learned about C this week! In addition, the write-up I handed in was written in LaTeX, which I am completely new to. I've uploaded my Tex files (report.tex and code.tex) and the bibliography file (cellularautomata.bib, which was created by Mendeley) if you want to have a look at them - it turns out that the trick with LaTeX is just to have a template file to build on.

I found a useful bit of LaTeX code to stitch two PDFs together (which you can download as a file):

\documentclass[11pt,a4paper]{article}

\usepackage{pdfpages}
\begin{document}

\includepdf[pages={1-5}]{writeup.pdf}
\includepdf[pages={1-7}]{code.pdf}

\end{document}

Pretty cool, huh? I've put all the LaTeX bits together in a .tar.gz file here. To extract and compile, run these commands in sequence:

tar -xzvf tex-files.tar.gz
pdflatex writeup.tex
bibtex writeup.aux
pdflatex writeup.tex
pdflatex writeup.tex
pdflatex code.tex
pdflatex stitch.tex

## Modifying a FLAME model

As I mentioned in my previous post about my adventures in FLAME modelling, I started out with code from my lecturer. I started with three two-dimensional models, each of which contained a different type (genus) of bacteria (Vibrio, Sar11 and "Bacteria X"). Each bacteria agent had X and Y co-ordinates, an ID and a radius. The radius was different for each type of bacteria, and it defined the rules that applied to that bacteria. They moved around by Brownian motion, and if they hit a virus there was a certain probability that they would be killed. The phages moved around in a similar fashion.

My code can be downloaded from here. In this post, I'm going to take you through how I converted these three models into a single model, added a third dimension, and persuaded the viruses and bacteria to replicate. This is a tale of how it's possible to do some quite cool things to a program even if you don't fully understand how it works.

If you're particularly interested, you can download a PDF of the report I handed in here. It starts with a brief review of a mathematical bacteriophage model, then goes on to the FLAME model in the second half (page 2). I got a mark of 95% for it, so I'm showing it off to everyone ^_^

## Running FLAME models at the Linux command line

Update: I've written another post about how I edited the model.

Last week, I modified a FLAME model to make it 3D and added some other features (with help from my John). This animation is of the model running, with me wiggling it around a bit to show the 3D-ness, and then leaving it be. There are explosions!

I think it's pretty cool. It represents a community of bacteria being attacked by viruses. These viruses - known as "bacteriophages" - could be really useful for treating infections, because they can kill bacteria which are resistant to traditional antibiotics.

In order to work out what dosage to use, and when to apply it, we need to know more about how bacteria and viruses interact with each other. This is difficult to study in real life, since viruses are so tiny - but by using computer models, we can make better approximations of how they behave.

The animation shows three types of bacteria, represented by green, blue and pink spheres. The orange dots are viruses. When a bacterium is infected by one of the viruses, it bursts, releasing lots of new viruses. Each virus and bacterium is an "agent" inside the model, and they each follow a particular set of rules, and carry pieces of information. I was using a piece of software called "FLAME" for this.

FLAME uses C and XML to make rules for the agents in a model. I found the documentation a bit obtuse, so I thought I'd make a blog post about exactly what I did, in case it was useful to anyone.

Initially, you need to install a set of programs - gcc, xparser, libmboard, and the FLAME visualiser. The installation instructions on the website are quite straight-forward, so I'll start my tutorial by talking about running a model.

Running a model in FLAME using the Linux command line

You can download my model code from here. It contains 4 files.

• 0.xml describes the starting state of all the agents in the model
• phageAndBacteriaV6.c contains all of the functions that the agents use
• phageAndBacteriaV6.xml describes all the agents, and the messages they send each other
• visual-rules.xml dictates how the model will be visualised

You start by using the xparser program on the xml file. I saved all my files in /home/beth/models/ so that is the location that I will use in my command line work - you should substitute it for your working folder. So: open up a terminal. Next, navigate to the directory where you have installed xparser and run

./xparser /home/beth/models/phageAndBacteriaV6.xml

This will create a load of files in home/beth/models. Navigate to /home/beth/models and run

 make

This creates the model programs, most importantly one called main. You can then run the model, giving the number of iterations you want (in this case, 100) and the location of the 0.xml file (in this case, ./0.xml)

./main 100 ./0.xml

This creates a load of xml files, numbered 1 to 100. Each one contains information about every single agent in the model at a particular time step. Now, these don't look very exciting in themselves, but this is where the flame visualiser comes in.

Navigate to where you've installed the visualiser and run

./flame_visualiser

A window should pop up. Go to "File" > "Open" and find visual-rules.xml. If you click on "Open Visual Window", you should now see lots of lovely spheres. It's a fairly straight-forward program to use - you can drag the picture around, start and stop the animation, go back and forward through the iterations, and zoom. If you have a tiny screen, you can grab and move the window by holding down Alt when you click & drag.

I made my animation by opening "Image Settings" and then setting the iteration to 0 and clicking "Start Animation." This saves a series of numbered images. You can rotate the picture while you're recording if you fancy. Then I opened up The GIMP, clicked "File" > "Open As Layers" and selected all 100 images. Then I saved the image as a .gif, selecting "Save As Animation".

So that's how to run an existing model, and make a pretty picture. In my next post, I talk about how to edit one.

Edit: I forgot to add, the visual-rules.xml document was generated by the flame visualiser. You need to give each type of bacteria a radius and a colour using the visualiser, and an xml document will be generated.