-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix2.py
More file actions
84 lines (69 loc) · 2.55 KB
/
fix2.py
File metadata and controls
84 lines (69 loc) · 2.55 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from Individual_based_sim import gametes, random, icount, count, pairing
# for example 1000, 30%, 50%, 20%
# allele_feq will be caculated by the perctages of the population set in ipopco
# allele_feq of the [1,1] allele
def ipopulationcontrol(popnum, per00, per10, per11):
pop = {}
allele_feq = (popnum * (per11 / 100) + popnum * (per10 / 200)) / popnum
for i in range(0, popnum):
pop[i] = [0, 0]
if i >= (popnum * (per00 / 100)):
pop[i] = [1, 0]
if i >= (popnum * (per00 / 100) + popnum * (per10 / 100)):
pop[i] = [1, 1]
return pop, allele_feq
def Fixing(initalpop, num, mutation_rate, max_gen, fixation, sel_coe):
count_n = 1
# fitness1 for (0,0), fitness2 for (0,1) and (1,0), fitness3 for (1,1)
fitness1 = 1.0 - (2 * sel_coe)
fitness2 = 1.0 - sel_coe
fitness3 = 1.0
# reproduction is how many potential gametes per gene
repoduction = 100.0
pop = initalpop
# while loop keeps track of generations and changs the population from the
# intinal population to the next geration after the first generation
plt.ion() # Note this correction
fig = plt.figure()
plt.axis([0, max_gen, 0, 1])
x = list()
y = list()
while True:
nextgerneration = gametes(
pop, fitness1, fitness2, fitness3, repoduction)
genechosen, genechosen_change = random(
nextgerneration, num, mutation_rate)
newgeneration = (pairing(genechosen_change, num))
count_n = count_n + 1
pop = newgeneration
# to check count the amount of 1's and 0's
count0, count1 = icount(newgeneration)
allele_feq = (count1 / (count0 + count1))
# print(count1)
print(allele_feq)
x.append(count_n)
y.append(allele_feq)
plt.title('Allele Frequency Vs. Time')
plt.xlabel('Time (generations)')
plt.ylabel('Allele Frequency')
plt.scatter(count_n, allele_feq, c="blue")
plt.show()
plt.pause(0.0001)
if allele_feq == 1:
break
if allele_feq == 0:
break
return count_n
# sel_coe is selection coefencent
population_size = 1000
sel_coe = -.2
mutationrate = 100
initalpop, allele_feq = ipopulationcontrol(population_size, 25, 50, 25)
print(count(initalpop))
print(allele_feq)
# multiple_generations(ipop, number of individuals, mutation, maxgen)
year = Fixing(initalpop, population_size, mutationrate, 1000, allele_feq,
sel_coe)
print(year)