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
/
translocation_meiosis.py
executable file
·202 lines (177 loc) · 7.01 KB
/
translocation_meiosis.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python
import os
import sys
import random
debug = False
types = {
1: 'adjacent-1',
2: 'adjacent-2',
3: 'alternate',
}
#Mbp
chromosome_lengths = {
1: (125,124),
2: (93,149),
3: (91,107),
4: (50,140),
5: (48,133),
6: (61,110),
7: (60,99),
8: (46,101),
9: (49,92),
10: (40,95),
11: (54,81),
12: (36,98),
13: (18,97),
14: (17,90),
15: (19,84),
16: (37,54),
17: (24,57),
18: (17,61),
19: (27,33),
20: (28,36),
21: (13,35),
22: (15,37),
}
centromere_length = 20
color_scales = {
'red': ['coral', 'lightsalmon', 'crimson'],
'blue': ['deepskyblue', 'lightskyblue', 'royalblue'],
}
def drawChromosome(chromosome1, color='red'):
table = ''
table += '<table style="border-collapse: collapse; border: 0px solid white; height: 30px">'
distance = chromosome_lengths[chromosome1]
table += '<colgroup width="{0}"></colgroup>'.format(distance[0]*2.4 - 16)
table += '<colgroup width="{0}"></colgroup>'.format(32)
table += '<colgroup width="{0}"></colgroup>'.format(distance[1]*2.4 - 16)
table += '<tr>'
table += '<td bgcolor="{1}" style="border: 2px solid black;" align="center"><span style="font-size: small"></span></td>'.format(chromosome1, color_scales[color][2])
table += '<td bgcolor="{1}" style="border: 4px solid black;" align="center">{0}</td>'.format(chromosome1, color_scales[color][1])
table += '<td bgcolor="{1}" style="border: 2px solid black;" align="center"><span style="font-size: large"></span></td>'.format(chromosome1, color_scales[color][2])
table += '</tr>'
table += '</table>'
return table
def drawTranslocatedChromosome(chromosome1, chromosome2, color1='red', color2='blue'):
table = ''
table += '<table style="border-collapse: collapse; border: 0px solid white; height: 30px">'
distance1 = chromosome_lengths[chromosome1]
distance2 = chromosome_lengths[chromosome2]
table += '<colgroup width="{0}"></colgroup>'.format(distance1[0]*2.4 - 16)
table += '<colgroup width="{0}"></colgroup>'.format(32)
table += '<colgroup width="{0}"></colgroup>'.format(distance1[1]*1.2 - 8)
table += '<colgroup width="{0}"></colgroup>'.format(distance2[1]*1.2 - 8)
table += '<tr>'
table += '<td bgcolor="{1}" style="border: 2px solid black;" align="center"><span style="font-size: large"></span></td>'.format(chromosome1, color_scales[color1][2])
table += '<td bgcolor="{1}" style="border: 4px solid black;" align="center">{0}</td>'.format(chromosome1, color_scales[color1][1])
table += '<td bgcolor="{1}" style="border: 2px solid black; border-right: 1px dashed black" align="center"><span style="font-size: large"></span></td>'.format(chromosome2, color_scales[color1][2])
table += '<td bgcolor="{1}" style="border: 2px solid black; border-left: 1px dashed black" align="center"><span style="font-size: large"></span></td>'.format(chromosome2, color_scales[color2][2])
table += '</tr>'
table += '</table>'
return table
def questionText(type, chromosome1, chromosome2):
question = '<p>{0},{1}: {2}</p>'.format(chromosome1, chromosome2, types[type])
question += '<p>A phenotypically normal prospective couple seeks genetic counseling '
question += 'because the man knows that he has a balanced translocation of a portion of his '
question += 'chromosome {0} that has been exchanged with a portion of his chromosome {1}.</p>'.format(chromosome1, chromosome2)
question += '<p>Which two (2) of the following sets of gametes was formed by <strong>{0}</strong> segregation in this individual? Check two boxes.</p>'.format(types[type])
return question
def merge_tables(table_list):
table = ''
table += '<table style="border-collapse: collapse; border: 0px solid white;">'
for chromo_table in table_list:
table += '<tr>'
table += ' <td align="left">{0}</td>'.format(chromo_table)
table += '</tr>'
table += '</table>'
return table
def blackboardFormat(type, chromosome1, chromosome2):
question_string = questionText(type, chromosome1, chromosome2)
table1 = ''
#A. rob(14; 21)
#B. rob(14; 21), +14
#C. rob(14; 21), +21
#D. -14
#E. -21
table1 = drawChromosome(chromosome1, 'red')
table2 = drawChromosome(chromosome2, 'blue')
table12 = drawTranslocatedChromosome(chromosome1, chromosome2, 'red', 'blue')
table21 = drawTranslocatedChromosome(chromosome2, chromosome1, 'blue', 'red')
table_merge = merge_tables([table1, table2, table12, table21])
#print(table1+table2+table12+table21)
question_string += '<p>all of the chromosomes from a somatic cell is shown below</p>'
question_string += table_merge
choices = []
smtab = '<table style="border-collapse: collapse; border: 1px solid silver;">'
trtd = '<tr><td style="border: 0px solid white;">'
alternate1 = smtab + trtd + 't({0}; {1}), t({1}; {0})</td></tr>'.format(chromosome1, chromosome2)
alternate1 += trtd + table12 + '</td></tr>'
alternate1 += trtd + table21 + '</td></tr>'
alternate1 += '</table><p></p><p></p>'
choices.append(alternate1)
alternate2 = smtab + trtd + '{0}, {1}</td></tr>'.format(chromosome1, chromosome2)
alternate2 += trtd + table1 + '</td></tr>'
alternate2 += trtd + table2 + '</td></tr>'
alternate2 += '</table><p></p><p></p>'
choices.append(alternate2)
adjacent1a = smtab + trtd + 't({0}; {1}), +{1}</td></tr>'.format(chromosome1, chromosome2)
adjacent1a += trtd + table12 + '</td></tr>'
adjacent1a += trtd + table2 + '</td></tr>'
adjacent1a += '</table><p></p><p></p>'
choices.append(adjacent1a)
adjacent1b = smtab + trtd + 't({1}; {0}), +{0}</td></tr>'.format(chromosome1, chromosome2)
adjacent1b += trtd + table21 + '</td></tr>'
adjacent1b += trtd + table1 + '</td></tr>'
adjacent1b += '</table><p></p><p></p>'
choices.append(adjacent1b)
adjacent2a = smtab + trtd + 't({0}; {1}), +{0}</td></tr>'.format(chromosome1, chromosome2)
adjacent2a += trtd + table12 + '</td></tr>'
adjacent2a += trtd + table1 + '</td></tr>'
adjacent2a += '</table><p></p><p></p>'
choices.append(adjacent2a)
adjacent2b = smtab + trtd + 't({1}; {0}), +{1}</td></tr>'.format(chromosome1, chromosome2)
adjacent2b += trtd + table21 + '</td></tr>'
adjacent2b += trtd + table2 + '</td></tr>'
adjacent2b += '</table><p></p><p></p>'
choices.append(adjacent2b)
answers = []
if type == 1:
answers.append(adjacent1a)
answers.append(adjacent1b)
elif type == 2:
answers.append(adjacent2a)
answers.append(adjacent2b)
elif type == 3:
answers.append(alternate1)
answers.append(alternate2)
else:
sys.exit(1)
blackboard = "MA\t"
blackboard += question_string
#print(question)
random.shuffle(choices)
for c in choices:
blackboard += "\t" + c
if c in answers:
blackboard += '\tCorrect'
else:
blackboard += '\tIncorrect'
print(question_string)
return blackboard
if __name__ == "__main__":
filename = "bbq-translocation_meiosis.txt"
f = open(filename, "w")
chromosomes = range(1,23) #[13, 14, 15, 21, 22]
num_problems = 90
count = 0
while count < num_problems:
type = random.randint(1,3)
chromosome1 = random.randint(1,22)
chromosome2 = random.randint(1,22)
if chromosome1 >= chromosome2:
continue
final_question = blackboardFormat(type, chromosome1, chromosome2)
print(chromosome1, chromosome2)
f.write(final_question+'\n')
count += 1
f.close()