Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 61 lines (48 sloc) 1.631 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
import ast
from collections import Counter
import pprint
import time
import random
import math

import matplotlib.pyplot as plt
import numpy as np

from simulate import *

def dark(r, d):
    """
r - amount of the gene pool with the recessive gene
d - amount of the gene pool with the dominant gene
returns the percentage of the population with the dominant trait
"""
    return d * 1.0 / (r + d) + d * r * 1.0 / ((r + d) ** 2)


def graph_expression():
    xs = range(0,101)
    ys = [100 * dark(100 - i, i) for i in xs]
    ax = plt.subplot(111)
    ax.plot(xs, ys, label='dominant gene', linewidth=3, c='#652f16')

    ys = [100 * (1 - dark(i, 100 - i)) for i in xs]
    ax = plt.subplot(111)
    ax.plot(xs, ys, label='recessive gene', linewidth=3, c='#2299ff')

    plt.ylabel('expected % of people with trait')
    plt.xlabel('% of gene pool')
    plt.legend(loc=2)

    plt.show()


def graph_pops():
    text = open(OUTPUT_FNAME).read()
    results = ast.literal_eval(text)
    xs = []
    ys = []
    for key, gene_pool in results.items():
        xs.append(key)
        ys.append(gene_pool.count(BROWN) * 1.0 / len(gene_pool))
    #pairs = sorted(results.items())
    ax = plt.subplot(111)
    #xs, ys = zip(*pairs)
    ax.plot(xs, np.array(xs) * 1.0 / max(xs), label='expected', linewidth=3, c='#777777', linestyle='dashed')
    ax.plot(xs, ys, label='simulated', linewidth=1, c='#2299ff')
    plt.ylabel('probability of the other gene going extinct')
    plt.xlabel('Initial % of gene pool')
    plt.legend(loc=2)
    plt.show()

if __name__ == "__main__":
    #graph_expression()
    graph_pops()
Something went wrong with that request. Please try again.