- We will need a few imports:
import randomimport matplotlib.pyplot as plt%matplotlib inline
- Before we do any empirical analysis, let's try to understand what information we can extract from the case where the mother is AA and the father is AT. Let's answer the question, "If we have 20 offspring, what is the probability of all of them being heterozygous?":
num_sims = 100000num_ofs = 20num_hets_AA_AT = []for sim in range(num_sims): sim_hets = 0 for ofs in range(20): sim_hets += 1 if random.choice([0, 1]) == 1 else 0 num_hets_AA_AT.append(sim_hets) fig, ax = plt.subplots(1,1, figsize=(16,9))ax.hist(num_hets_AA_AT, bins=range(20))print(len([num_hets for num_hets in num_hets_AA_AT if num_hets==20]))
We get the following output: ...