Simulating Biology

We write computer programs to simulate biological populations, allowing us to predict how real life organisms will act under specific circumstances. If you haven’t done it, writing coding might seem daunting, but it’s really just giving directions to a computer in a way it will understand. I’ll even show you how you can write code to simulate a real biological situation.

Let’s start with an asexual (all-female) population we’ll call $pop:

$pop=1000

Now we want to simulate reproduction. To give each female a chance to reproduce, we’ll create a loop that starts with the 1st female ($x=0), then keeps counting ($x++) until it goes through the whole population ($x<$pop):

for($x=0; $x<$pop; $x++)

Now we’ll give each female a 50% chance of reproducing. rand(1) will randomly choose a number between 0 and 1. If the number is greater than 0.5, the female will add an offspring to the next generation ($pop2); if it’s less than 0.5, it won’t:

if(rand(1)>0.5){++$pop2}

That’s it! Our whole program looks like this:

$pop=1000;

for($x=0; $x<$pop; $x++){

if(rand(1)>0.5){++$pop2}

}

print $pop2

When I ran it, I got 516 offspring in the next generation. That will change slightly each time we run it. Cool. Now what could we do to give each mother a 50% chance of having a 2nd offspring? (feel free to email me with the answer if you want to try this).

  • Turtles in the bottom row were incubated at 25°C, leaving them with poor coordination and long righting times. Turtles in the middle row were incubated at 30°C and right quickly. Because female turtles must leave the water to build nests every year, they require more agility than males. Sex determination has evolved to produce females at the warm temperatures that benefit them most (Freedberg et al. 2001, Freedberg et al. 2004).