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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.