This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epistasis_test_cross.py
executable file
·96 lines (79 loc) · 2.25 KB
/
epistasis_test_cross.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
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
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import os
import copy
import math
import random
N = 0
epistasis_ratios = {
'15:1': '3:1',
'13:3': '3:1',
'12:4': '2:2 or 1:1',
'12:3:1': '2:1:1',
'10:6': '2:2 or 1:1',
'10:3:3': '2:1:1',
'9:7': '1:3',
'9:6:1': '1:2:1 or 1:1:2',
'9:4:3': '1:2:1 or 1:1:2',
}
one_colon_choices = [
'4:1', '3:2', '3:1', '2:3', '2:2 or 1:1', '2:1', '1:4', '1:3', '1:2',
]
two_colon_choices = [
'3:1:1', '2:2:1', '2:1:2', '2:1:1', '1:3:1', '1:2:2', '1:2:1 or 1:1:2', '1:1:3', '1:1:1',
]
def write_question(question, choices):
global N
N += 1
outfile = 'bbq-' + os.path.splitext(os.path.basename(__file__))[0] + '-questions.txt'
print('writing to file: '+outfile)
f = open(outfile, 'a')
print('{0}. {1}'.format(N, question))
letters = 'ABCDEF'
f.write('MC\t{0}\t'.format(question))
for i,choice in enumerate(choices):
f.write(choice+'\t')
if choice == answer:
prefix = 'x'
f.write('Correct\t')
else:
prefix = ' '
f.write('Incorrect\t')
print('- [{0}] {1}. {2}'.format(prefix, letters[i], choice))
print('')
f.write('\n')
f.close()
if __name__ == '__main__':
keys = list(epistasis_ratios.keys())
num_repeats = 11
try:
os.remove('bbq-epistasis_test_cross.txt')
except FileNotFoundError:
pass
#random.shuffle(keys)
for ratio in keys:
number = '{0}. '.format(N)
question = ''
question += 'In a specific cross, F<sub>2</sub> progeny exhibit a modified dihybrid ratio of <b>{0}</b> (instead of 9:3:3:1 ). '.format(ratio)
question += 'What phenotypic ratio would be expected from a test-cross with an individual from the F<sub>1</sub> progeny? '
answer = epistasis_ratios[ratio]
colon_count = answer.split(' ')[0].count(':')
if colon_count == 2:
choices = copy.copy(two_colon_choices)
elif colon_count == 1:
choices = copy.copy(one_colon_choices)
print(choices)
print(answer)
choices.remove(answer)
possibilities = math.comb(len(choices), 5)
#print("There are {0} possibilities".format(possibilities))
### BREAK
original_choices = choices
for i in range(num_repeats):
choices = copy.copy(original_choices)
random.shuffle(choices)
random.shuffle(choices)
choices = choices[0:5]
choices.append(answer)
random.shuffle(choices)
random.shuffle(choices)
write_question(question, choices)