How to do it...

Take a look at the following steps:

  1. Let's start by initializing the variables and basic data structures, as follows:
from collections import OrderedDictnum_loci = 10pop_size = 100num_gens = 10init_ops = OrderedDict()pre_ops = OrderedDict()post_ops = OrderedDict()

Here, we specify that we want to simulate 10 loci, a population size of 100, and just 10 generations. We then prepare three ordered dictionaries. These will maintain our operators.

Note that we use OrderedDict(). Ordered dictionaries will return keys in the order that they were inserted. This is important because the order of operators is relevant, for example, if we print the result of a statistic—this will be dependent on it having been computed before.

  1. We will ...

Get Bioinformatics with Python Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.