Repository navigation
Expand file tree
/
Copy pathUnitTest.py
More file actions
221 lines (187 loc) · 6.85 KB
/
Copy pathUnitTest.py
File metadata and controls
221 lines (187 loc) · 6.85 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Simulator script for testing SAI forward simulations with particular parameters
import SAIsim as sim
# Limited size for testing
size = 10
# given 10^-8 SAmut/base/gen and
mutRate = .1
# Approximated by
mutRateInv = .1
# Deviation of normally distributed offset of mutation effects from [x,1-x], with x = uniform[0,1)
mutEffectDiffSD = .2
# Reasonable minimum length given that 1 distance unit on the chromosome = 1 Morgan
minInvLen = .1
# Chromosome length in M, Drosophila arms are 50 cM
lenChrom = 1.0
# The expected # of crossovers per chromosome arm
# parameter = 1 gives 1 Morgan chromosome arm
recombRate = 1
# Must be <= pop size
encounterNum = 20
# SD for the normally distributed additive noise to male quality in the female choice
choiceNoiseSD = .5
# The probability per instance of heterozygosity that a gene undergoes conversion in a heterozygous gamete,
# which one is converted is selected at random, treated independently from number of crossover events
conversionRate = 0.5 # For easier testing
# Inversion record buffer represents how far from inversion edges to examine mutation effects
# CONSIDER making this a parameter of the record function (Doesn't really work as recording is simultaneous)
invRecBuffer = .1
# Testing Recombination
isFly = True
willConvert = False
willRecombine = True
mut1 = [0.05,.7,.2,0]
mut2 = [0.40,.8,.1,1]
inv1 = [0.02,0.98,0]
inv2 = [0.02,0.98,1]
inv3 = [0.04,0.10,3]
inv4 = [0.34,0.45,4]
# Inversion Dynamic Tests
# Expectation of all recombination cases observed
def testSameInvRec():
print('Testing recombination between the same inversion:')
testGenome = [[[[mut1],[inv1]],[[mut2],[inv1]]]]
print('Test Genome:')
print(testGenome)
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
# Expectation of all recombination cases observed, asthe ID isn't checked
def testSameInvDiffLabelRec():
print('Testing recombination between differently labeled inversions:')
testGenome = [[[[mut1],[inv1]],[[mut2],[inv2]]]]
print('Test Genome:')
print(testGenome)
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
# Run the tests
# testSameInvRec()
# testSameInvDiffLabelRec()
willConvert = True
# Conversion testing
# Expectation no conversion
def testConv1MSame():
print('Testing conversion between A/A Genotype:')
testGenome = [[[[mut1],[]],[[mut1],[]]]]
# testGenome = [[[[mut1],[inv1]],[[mut1],[inv2]]]]
print('Test Genome:')
print(testGenome)
print('Gametes:')
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
print()
# Expectation AB, A, B, - gametes
def testConv1MDiff():
print('Testing conversion between A/B Genotype:')
testGenome = [[[[mut1],[]],[[mut2],[]]]]
# testGenome = [[[[mut1],[inv1]],[[mut2],[inv2]]]]
print('Input Genome:')
print(testGenome)
print('Gametes:')
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
print()
# Expectation no conversion
def testConv2MSame():
print('Testing conversion between AB/AB Genotype:')
testGenome = [[[[mut1,mut2],[]],[[mut1,mut2],[]]]]
# testGenome = [[[[mut1,mut2],[inv1]],[[mut1,mut2],[inv2]]]]
print('Test Genome:')
print(testGenome)
print('Gametes:')
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
print()
# Expectation AB, A, B, - gametes
def testConv2MNull():
print('Testing conversion between AB/- Genotype:')
testGenome = [[[[mut1,mut2],[]],[[],[]]]]
# testGenome = [[[[mut1,mut2],[inv1]],[[mut1,mut2],[inv2]]]]
print('Test Genome:')
print(testGenome)
print('Gametes:')
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
print()
# Expectation AB, A, B, - gametes
def testConvNull2M():
print('Testing conversion between -/AB Genotype:')
testGenome = [[[[],[]],[[mut1,mut2],[]]]]
# testGenome = [[[[mut1,mut2],[inv1]],[[mut1,mut2],[inv2]]]]
print('Test Genome:')
print(testGenome)
print('Gametes:')
for i in range(10):
fly = sim.individual('F',mutEffectDiffSD,recombRate,conversionRate,minInvLen,\
lenChrom,isFly,willConvert,willRecombine,testGenome)
print(fly.genGamete())
print()
# Run tests
testConv1MSame()
testConv1MDiff()
testConv2MSame()
# conversionRate = 1
testConv2MNull()
testConvNull2M()
# # Scratch for testing mutation data change (due to shared reference)
# def testSharedData(self):
# mutCounts = [0]*self.__mutIDcount
# for indiv in self.males + self.females:
# for chrom in indiv.genome:
# for hom in chrom:
# for mut in hom[0]:
# mutCounts[mut[3]] += 1
# for i in range(self.__mutIDcount):
# if mutCounts[i] == 2*self.size:
# # self.record[1][i] = mut
# # mut[2] = 'test'
# print('Starting test for ID '+ str(i))
# # print(mut)
# # print(self.record[1][i])
# firstEncounter = True
# for indiv in self.males + self.females:
# for chrom in indiv.genome:
# for hom in chrom:
# for mut in hom[0]:
# if mut[3] == i:
# if firstEncounter:
# mut[2] = 'test'
# firstEncounter = False
# print(mut)
# return
# # For genGenomesSexes
# initMutList = [[0.5,0.95,0.1,0,40]]
# initInvList = [[0.01,0.06,0,60]]
# genomes = [[[[[],[]],[[],[]]]]]
# sexes = ['F']
# # For genGenoSexFromWholeGenHap
# mutList = [[0.5,0.95,0.1,0],[0.04,0.45,0.45,0]]
# invList = [[0.01,0.06,0]]
# mut0 = [0.5,0.95,0.1,0]
# mut1 = [0.04,0.45,0.45,1]
# inv0 = [0.01,0.06,0]
# hapList = [[[[[mut0,mut1],[inv0]]],6],[[[[mut0],[inv0]]],4]]
# numGens = 500
# # Now run the simulator session in length and recording intervals as desired using above parameters
# # (genomes,sexes,record) = sim.genGenomesSexes(size,initMutList,initInvList,genomes=genomes,sexes=sexes)
# (genomes,sexes,record) = sim.genGenoSexFromWholeGenHap(size,mutList,invList,hapList,genomes=genomes,sexes=sexes)
# pop = sim.SAIpop(size, mutRate, mutRateInv, mutEffectDiffSD, minInvLen, conversionRate, recombRate,\
# encounterNum, choiceNoiseSD, invRecBuffer, willMutate = False, willMutInv = False,\
# noMaleCost = True, genomes=genomes,sexes=sexes,record=record)
# # pop = sim.SAIpop(size, mutRate, mutRateInv, mutEffectDiffSD, minInvLen, conversionRate, recombRate,encounterNum, choiceNoiseSD, invRecBuffer)
# # pop.stepNGens(numGens)
# # pop.recordEveryNGens(10,200)
# pop.recordNGens(numGens)
# # pop.printGenomes()
# # pop.printRecord()
# pop.writeRecordTables('testOutput/Test1')