-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPRB.py
53 lines (37 loc) · 1.29 KB
/
IPRB.py
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
from sys import argv
from sys import exit
def main():
# Ensures correct command line input
if len(argv) != 4:
exit("Please use proper command line arguments.")
# Stores user input
dataset = []
for i in range(1, 4, 1):
dataset.append(int(argv[i]))
total = sum(dataset) # Total alleles
# Stores frequency of genetic combination, with full being all dominant
freq = {
"full": combinations(total - dataset[0], total),
"most": combinations(0, dataset[1]),
"half": dataset[1] * dataset[2],
"none": combinations(0, dataset[2])
}
# Probability of each key in freq
weight = [1, 0.75, 0.5, 0]
# Calculates total combinations
combos = combinations(0, total)
# Weights the frequencies in freq to determine probability
result = 0
for i, value in enumerate(freq):
result += freq[value] * weight[i]
# Averages and prints result by dividing the amount of combinations
result /= combos
print(result)
def combinations(beginning, end):
customsum = 0
# Iterates over given range, adding each iteration to the last
for i in range(beginning, end, 1):
customsum += i
return customsum
if __name__ == "__main__":
main()