-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.py
More file actions
77 lines (61 loc) · 2 KB
/
Copy pathsimulation.py
File metadata and controls
77 lines (61 loc) · 2 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
from openpyxl import*
import random
HomozygousDominantParent = ["D", "D"]
HomozygousRecessiveParent = ["d", "d"]
workbook = load_workbook(filename="Presentation.xlsx")
sheet = workbook.active
attempts = 30000
f1Children = []
#recreates the breeding process
def createOffsprings(Parent1, Parent2,isf1):
child = []
childAllele1 = Parent1[random.randrange(0,2)]
childAllele2 = Parent2[random.randrange(0,2)]
child.append(childAllele1)
child.append(childAllele2)
if isf1:
f1Children.append(child)
phenotype = CheckPhenotype(child)
return phenotype
#checks if there is any dominant alleles
def CheckPhenotype(Children):
for i in Children:
if i == "D":
return True
return False
row = 4
for i in range(attempts):
#reset all variables
f1Children = []
DominantsF1 = 0
RecessivesF1 = 0
DominantsF2 = 0
RecessivesF2 = 0
#F1
repetitions = range(random.randrange(60,90))
for i in repetitions:
f1 = True
offspringphenotype = createOffsprings(HomozygousDominantParent, HomozygousRecessiveParent, f1)
if offspringphenotype:
DominantsF1 += 1
else:
RecessivesF1 +=1
#F2
repetitions = range(random.randrange(100,200))
for i in repetitions:
f1 = False
f2parent1 = f1Children[random.randrange(0,len(f1Children)-1)]
f2parent2 = f1Children[random.randrange(0,len(f1Children)-1)]
offspringphenotype = createOffsprings(f2parent1, f2parent2, f1)
if offspringphenotype:
DominantsF2 += 1
else:
RecessivesF2 +=1
#Write on the Excel
sheet["C"+str(row)] = str(DominantsF1)
sheet["E"+str(row)] = str(RecessivesF1)
sheet["G"+str(row)] = str(DominantsF2)
sheet["I"+str(row)] = str(RecessivesF2)
print(DominantsF1, RecessivesF1, DominantsF2, RecessivesF2)
row +=1
workbook.save(filename="Presentation.xlsx")