Mar 1, 2021 | science & tech

SLiM with Docker

a docker image for SLiM

Full disclosure: I get a little nervous when venturing into writing about biology or biology adjacent topics. This may be a little confusing considering I am currently a post-doc in a biology lab but here we are.

This isn't an entirely accurate representation of my situation. Contrary to the U.S. Border Patrol's belief, you don't actually have to be a biologist in order to be hired to work in a biology lab. In fact, you could be something like an anthropologist hired to do computer things, which is probably a more relevant depiction of my situation. In fact, being surrounded by biologists is a refreshing change of pace and there is even some overlap of interest such as anthropometrics!

A good portion of my current position involves running evolutionary simulations, which, prior to this version of myself, I had very little experience in doing. There may have been a time in undergrad when I was doing something similar, but if I'm being completely honest, I was new to the command line at the time and much of my mental pouvoir was spent typing ls on repeat trying to convince myself that I was hacking. What my actual task was is anyone's guess but I think I remember trying to simulate some sort of positive selection. Fast-forward a decade and few things have changed: I still key in ls just to feel cool and I'm back to running similations (if that is indeed what I was doing back then). Fortunately, between now and undergrad, I have learned a few more tricks, but first a very brief introduction of SLiM.


SLiM is a scriptable, simulation framework designed to be flexible enough to simulate complex, custom evolutionary phenomena. If playing Sims was/is your jam and don't mind getting your hands dirty with a scripting language, give SLiM a try. It may also be of interest to some computational, theoretical biologists out there. But in all seriousness, it appears to me that SLiM is today's gold standard with respect to running evolutionary simulations and what Dr. Ben Haller and the members of the Messer lab have created is pretty approachable, particularly if you are coming from the R community.

Seriously though, the dedication of Ben Haller to this project is phenomenal. SLiM is actually a framework built on top of the scripting language Eidos, which Haller also built. If you are familiar with the statistical programming language of `R`, Eidos has a small barrier of entry, however, statements are terminated with semicolons, which should make those C++ or Java developers feel like they are welcomed at this party.

The Docker Image

Anyone familiar with my development style can attest that Docker is a major component of my workflow. I am by no means an expert in the tool but I can really get behind containerized applications. In the past, I have run into a bit of pushback from fellow academics claiming that Docker is a bit overkill for research purposes. Perhaps in a future post I can unpack this, but for the here & now, I'm going to go ahead and simply say that I am a proponent of Dockerizing your research workflow.

Docker is an open-source tool to encapsulate your applications into "containers", which keep your dependencies, settings and tools consistent for that application. This means that your container will run your application the same way from host to host no matter what host's operating system is. Containers can also talk to one another, which means that different parts of your application can be partitioned up into microservices to make maintainence across the application lightweight.

Let's dive in! We can start by creating a txt file called Dockerfile.

# Dockerfile
FROM ubuntu:18.04
RUN apt-get update -y
RUN apt-get install -y \
wget make cmake gcc g++ unzip

We start here with our image's starting image (yup, you read that right). In this case I chose the Ubuntu for no other reason than it's the Linux distribution I am most familiar with. Without getting into too much of a Docker tutorial, all images start with a base image, the FROM line above. If the base image can't be found on the host operating system, then Docker will automatically check Docker Hub. When the image is found, it will pull it down and install it on the host. Now, images are meant to do one task and one task only. This keeps image builds small but it also means that they are scant on the software side, which is why we have to extend the capabilities of the base Ubuntu image by installing some pacakages. In keeping with tradition, only those packages that are needed to get SLiM installed and running are going to be added. Most of the installs apply specifically to building SLiM from source per the Building SLiM from sources on Linux section in the SLiM manual, however wget and unzip are related to obtaining and unziping the SLiM release.

RUN wget
RUN unzip \
&& mkdir /build
WORKDIR /build
RUN cmake /SLiM \
&& make slim

These next couple of steps actually involve building SLiM. We first start with wget, which is responsible for pulling the zip file down. After unzipping its contents, the image creates a top-level directory called build/ where the SLiM software will be installed. Next up is to navigate into /build and build SLiM from source using cmake and make. Now a copy of SLiM should be installed in this image and the final step is to create a symlink to the slim command.

RUN ln -s /build/slim /usr/bin/slim
CMD ["slim"]

Now you should be able to build your image and test that SLiM is running properly.

$ docker build -t slim .
$ docker run slim slim --testEidos

If everything goes smoothly, and it should because consistency is one of Docker's advantages, then you should see SUCCESS count: 5961 printed to your console. You can now take your .slim scripts and run them in a container of your image by mounting the file to the container. Now go and play god with containerized applications!

Oh, and here's a link to the complete image if you are interested.