-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
442 lines (395 loc) · 17.5 KB
/
test.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
import eteTree as et
import functions as fu
from abberations import abberations as abbrs
"""
import likelyhood as lh
import likelyhood2 as lh2
import likelyhood3 as lh3
"""
import likelyhood4 as lh4
import math as math
import emAlgorithm as em
import numpy as np
import functions as fu
import copy as copy
def testDataPoint(tree,X):
#print X, lh.likelyhoodOfX(tree1,X), lh.likelyhoodOfX2(tree1,X), lh.likelyhoodOfX3(tree1,X)
for node in tree.iter_descendants():
tmp = lh.likelyhoodOfXandZ(tree,X,node.name,1)/lh.likelyhoodOfX2(tree,X) + lh.likelyhoodOfXandZ(tree,X,node.name,0)/lh.likelyhoodOfX2(tree,X)
if (tmp != 1):
print lh.likelyhoodOfXandZ(tree,X,node.name,1)/lh.likelyhoodOfX(tree,X) + lh.likelyhoodOfXandZ(tree,X,node.name,0)/lh.likelyhoodOfX(tree,X)
print lh.likelyhoodOfXandZ(tree,X,node.name,1)/lh.likelyhoodOfX2(tree,X) + lh.likelyhoodOfXandZ(tree,X,node.name,0)/lh.likelyhoodOfX2(tree,X)
print node.name,"= 1,",lh.likelyhoodOfXandZ(tree,X,node.name,1)
print node.name, "= 0,", lh.likelyhoodOfXandZ(tree,X,node.name,0)
print node
raw_input("continue")
else:
continue
def testTrees2():
print "="*20, " TEST 2 ","="*20
mutations1 = list(abbrs)
tree1 = et.generate(3,mutations1,False, False) # small one-lvl tree
tree1 = et.setRandomTreeNodes(tree1,Px = 0.8, test = True)
data1 = et.createDataHash(tree1, 1000)
data1 = fu.uniqueData(data1)
fu.printTreeInfo(tree1)
print len(data1)
raw_input("continue\n")
fu.sortData(data1)
for X in data1:
testDataPoint(tree1,X)
def test3():
print "="*20, " TEST 3 ","="*20
mutations = list(abbrs)
tree = et.generate(2,mutations,False, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree,Px = 0.8, test = True)
data = et.createDataHash(tree, 1000)
data = fu.uniqueData(data)
data = fu.sortData(data)
fu.printTreeInfo(tree)
for X in data:
print X, lh.likelyhoodOfX(tree,X)
print X, lh.likelyhoodOfX2(tree,X)
def testTrees():
print "="*20, " TEST 1 ","="*20
mutations1 = list(abbrs)
tree1 = et.generate(3,mutations1,False, True) # small one-lvl tree
tree1 = et.setRandomTreeNodes(tree1,Px = 0.8, test = True)
data1 = et.createDataHash(tree1, 100)
data1 = fu.uniqueData(data1)
fu.printTreeInfo(tree1)
fu.sortData(data1)
print "P[",data1[0],"|T]", lh.likelyhoodOfX(tree1,data1[0]), 0.9*0.8*0.9*0.8
print "P[",data1[1],"|T]", lh.likelyhoodOfX(tree1,data1[1]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data1[2],"|T]", lh.likelyhoodOfX(tree1,data1[2]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data1[3],"|T]", lh.likelyhoodOfX(tree1,data1[3]), (0.1+0.9*0.2)*(0.1+0.9*0.2)
print "P[",data1[0],"|T]", lh2.calcProbForX(tree1,data1[0]), 0.9*0.8*0.9*0.8
print "P[",data1[1],"|T]", lh2.calcProbForX(tree1,data1[1]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data1[2],"|T]", lh2.calcProbForX(tree1,data1[2]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data1[3],"|T]", lh2.calcProbForX(tree1,data1[3]), (0.1+0.9*0.2)*(0.1+0.9*0.2)
print "="*20," TEST 1.2 ","="*20
mutations2 = list(abbrs)
tree2 = et.generate(3,mutations1, True, False) # small one-lvl tree
tree2 = et.setRandomTreeNodes(tree2,Px= 0.8, test = True)
data2 = et.createDataHash(tree2, 100)
data2 = fu.uniqueData(data2)
fu.printTreeInfo(tree2)
fu.sortData(data2)
print "P[",data2[0],"|T]", lh.likelyhoodOfX(tree2,data2[0]), 0.9*0.8*0.9*0.8
print "P[",data2[1],"|T]", lh.likelyhoodOfX(tree2,data2[1]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data2[2],"|T]", lh.likelyhoodOfX(tree2,data2[2]), 0.9*0.2*(0.9*0.8)
print "P[",data2[3],"|T]", lh.likelyhoodOfX(tree2,data2[3]), 0.1+(0.9*0.2*(0.1+0.9*0.2))#(0.1+0.9*0.1)*(0.1+0.9*0.1)
print "P[",data2[0],"|T]", lh2.calcProbForX(tree2,data2[0]), 0.9*0.8*0.9*0.8
print "P[",data2[1],"|T]", lh2.calcProbForX(tree2,data2[1]), 0.9*0.8*(0.1+0.9*0.2)
print "P[",data2[2],"|T]", lh2.calcProbForX(tree2,data2[2]), 0.9*0.2*(0.9*0.8)
print "P[",data2[3],"|T]", lh2.calcProbForX(tree2,data2[3]), 0.1+(0.9*0.2*(0.1+0.9*0.2))#(0.1+0.9*0.1)*(0.1+0.9*0.1)
print "="*20," TEST 1.3 ","="*20
mutations3 = list(abbrs)
tree3 = et.generate(2,mutations3, True, False) # small one-lvl tree
tree3 = et.setRandomTreeNodes(tree3,Px= 0.8, test = True)
data3 = et.createDataHash(tree3, 100)
data3 = fu.uniqueData(data3)
fu.printTreeInfo(tree3)
print data3
print "P[",data3[0],"|T]", lh.likelyhoodOfX(tree3,data3[0]), 0.9*0.8
print "P[",data3[1],"|T]", lh.likelyhoodOfX(tree3,data3[1]), (0.1+0.9*0.2)
print "P[ Z(M85) = 0,",data3[0],"|T]", lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",0), 0.05
print "P[ Z(M85) = 1,",data3[0],"|T]", lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",1), 0.9*0.8
print "P[ Z(M85) = 0,",data3[1],"|T]", lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",0), 0.1
print "P[ Z(M85) = 1,",data3[1],"|T]", lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",1), 0.18
print 1, "=", lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",0)/lh.likelyhoodOfX(tree3,data3[0]),"+", lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",1)/lh.likelyhoodOfX(tree3,data3[0]), lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",1)/lh.likelyhoodOfX(tree3,data3[0]) + lh.likelyhoodOfXandZ(tree3,data3[0],"[M85]",0)/lh.likelyhoodOfX(tree3,data3[0])
print 1, "=", lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",0)/lh.likelyhoodOfX(tree3,data3[1]),"+", lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",1)/lh.likelyhoodOfX(tree3,data3[1]), lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",1)/lh.likelyhoodOfX(tree3,data3[1]) + lh.likelyhoodOfXandZ(tree3,data3[1],"[M85]",0)/lh.likelyhoodOfX(tree3,data3[1])
print "P[",data3[0],"|T]", lh2.calcProbForX(tree3,data3[0]), 0.9*0.8
print "P[",data3[1],"|T]", lh2.calcProbForX(tree3,data3[1]), (0.1+0.9*0.2)
print "P[ Z(M85) = 0,",data3[0],"|T]", lh2.calcProbForXandZ(tree3,data3[0],"[M85]",0), 0.05
print "P[ Z(M85) = 1,",data3[0],"|T]", lh2.calcProbForXandZ(tree3,data3[0],"[M85]",1), 0.9*0.8
print "P[ Z(M85) = 0,",data3[1],"|T]", lh2.calcProbForXandZ(tree3,data3[1],"[M85]",0), 0.1
print "P[ Z(M85) = 1,",data3[1],"|T]", lh2.calcProbForXandZ(tree3,data3[1],"[M85]",1), 0.18
fu.printTreeInfo(tree3)
print tree3, data3[0]
print "SLASK: ", lh2.calcProbForX(tree3,data3[0])
print 1, "=", lh2.calcProbForXandZ(tree3,data3[0],"[M85]",0)/lh2.calcProbForX(tree3,data3[0]),"+", lh2.calcProbForXandZ(tree3,data3[0],"[M85]",1)/lh2.calcProbForX(tree3,data3[0]), lh2.calcProbForXandZ(tree3,data3[0],"[M85]",1)/lh2.calcProbForX(tree3,data3[0]) + lh2.calcProbForXandZ(tree3,data3[0],"[M85]",0)/lh2.calcProbForX(tree3,data3[0])
print 1, "=", lh2.calcProbForXandZ(tree3,data3[1],"[M85]",0)/lh2.calcProbForX(tree3,data3[1]),"+", lh2.calcProbForXandZ(tree3,data3[1],"[M85]",1)/lh2.calcProbForX(tree3,data3[1]), lh2.calcProbForXandZ(tree3,data3[1],"[M85]",1)/lh2.calcProbForX(tree3,data3[1]) + lh2.calcProbForXandZ(tree3,data3[1],"[M85]",0)/lh2.calcProbForX(tree3,data3[1])
#print data2[1], lh.likelyhoodOfX(tree2,data2[1]), 0.9*0.8*(0.1+0.9*0.2)
#print data2[2], lh.likelyhoodOfX(tree2,data2[2]), 0.9*0.2*(0.9*0.8)
#print data2[3], lh.likelyhoodOfX(tree2,data2[3]), 0.1+(0.9*0.2*(0.1+0.9*0.2))#(0.1+0.9*0.1)*(0.1+0.9*0.1)
def test4():
print "="*20, " TEST 4 ","="*20
mutations = list(abbrs)
tree = et.generate(30,mutations,False, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree)
data = et.createDataHash(tree, 2000)
data = fu.uniqueData(data)
fu.printTreeInfo(tree)
fu.sortData(data)
for X in data:
print lh.likelyhoodOfX2(tree,X) - lh.likelyhoodOfX3(tree,X),
return None
def test5():
print "\n","="*20, " TEST 5 , One Child trees","="*20
tCounter = 0
fCounter = 0
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,True, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree,test=True)
data = et.createDataHash(tree, 2000)
data = fu.uniqueData(data)
fu.printTreeInfo(tree)
fu.sortData(data)
for X in data:
tmp = lh2.calcProbForX(tree,X)
for node in tree.iter_descendants():
tCounter+=1
if (abs(((lh2.calcProbForXandZ(tree,X,node.name,1)/tmp) + (lh2.calcProbForXandZ(tree,X,node.name,0)/tmp)) - 1.0) > 0.001):
fCounter+=1
print treeSize,tree, "\n",X,node.name
print "P[X|T] = ", tmp
print 1, " = ",(lh2.calcProbForXandZ(tree,X,node.name,1)/tmp) + (lh2.calcProbForXandZ(tree,X,node.name,0)/tmp)
print lh2.calcProbForXandZ(tree,X,node.name,1)
print lh2.calcProbForXandZ(tree,X,node.name,0)
raw_input("continue")
#if (1 != ((lh2.calcProbwithZ(tree,X,node.name,1)/tmp) + (lh2.calcProbwithZ(tree,X,node.name,0)/tmp))):
print " TEST 5 TreeSize: ",treeSize, tCounter-fCounter, " out of ", tCounter, "were Successful"
tCounter = 0
fCounter = 0
return None
def test6():
print "\n","="*20, " TEST 6, One Level Trees ","="*20
tCounter = 0
fCounter = 0
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False, True) # small one-lvl tree
tree = et.setRandomTreeNodes(tree)
data = et.createDataHash(tree, 2000)
data = fu.uniqueData(data)
#fu.printTreeInfo(tree)
fu.sortData(data)
for X in data:
tmp = lh2.calcProbForX(tree,X)
for node in tree.iter_descendants():
tCounter +=1
if (abs(((lh2.calcProbForXandZ(tree,X,node.name,1)/tmp) + (lh2.calcProbForXandZ(tree,X,node.name,0)/tmp)) - 1.0) > 0.001):
fCounter +=1
#print treeSize,tree, "\n",X,node.name
#print "P[X|T] = ", tmp
#print 1, " = ",(lh2.calcProbForXandZ(tree,X,node.name,1)/tmp) + (lh2.calcProbForXandZ(tree,X,node.name,0)/tmp)
#print lh2.calcProbForXandZ(tree,X,node.name,1)
#print lh2.calcProbForXandZ(tree,X,node.name,0)
#raw_input("continue")
#if (1 != ((lh2.calcProbwithZ(tree,X,node.name,1)/tmp) + (lh2.calcProbwithZ(tree,X,node.name,0)/tmp))):
print " TEST 6 TreeSize: ",treeSize, tCounter-fCounter, " out of ", tCounter, "were Successful"
tCounter = 0
fCounter = 0
return None
def test8():
print "="*20, "Test 8.1, One level trees", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False,True)
tree = et.setRandomTreeNodes(tree, test = False)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = []
for X in data:
tmp.append( lh2.calcProbForX(tree,X))
#if sum(tmp) != 1:
#fu.printTreeInfo(tree)
#print tmp
#raw_input("continue")
print " TEST 8.1 TreeSize: ",treeSize, len(data), sum(tmp)
#print data
print "="*20, "Test 8.2", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,True,False)
tree = et.setRandomTreeNodes(tree,test = True, Px = 0.95, Pz = 0.5)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = []
for X in data:
tmp.append( lh2.calcProbForX(tree,X))
if sum(tmp) != 1:
fu.printTreeInfo(tree)
print tmp, sum(tmp), data
raw_input("continue")
print " TEST 8.2 TreeSize: ",treeSize, len(data), sum(tmp)
#print data
print "="*20, "Test 8.3", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False,False)
tree = et.setRandomTreeNodes(tree)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = 0
for X in data:
tmp += lh2.calcProbForX(tree,X)
print " TEST 8.3 TreeSize: ",treeSize, len(data), tmp
#print data
def test9():
print "="*20, "Test 9.1, One level trees", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False,True)
tree = et.setRandomTreeNodes(tree, test = False)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = []
for X in data:
tmp.append( lh4.calcProb_X(tree,X))
if (abs(sum(tmp) - 1) > 0.0000001):
fu.printTreeInfo(tree)
print tmp, sum(tmp), data
raw_input("continue")
print " TEST 9.1 TreeSize: ",treeSize, len(data), sum(tmp)
#print data
print "="*20, "Test 9.2", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,True,False)
tree = et.setRandomTreeNodes(tree,test = True, Px = 0.95, Pz = 0.5)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = []
for X in data:
tmp.append( lh4.calcProb_X(tree,X))
if (abs(sum(tmp) - 1) > 0.0000001):
fu.printTreeInfo(tree)
print tmp, sum(tmp), data
raw_input("continue")
print " TEST 9.2 TreeSize: ",treeSize, len(data), sum(tmp)
#print data
print "="*20, "Test 9.3", "="*20
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False,False)
tree = et.setRandomTreeNodes(tree)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
tmp = 0
for X in data:
tmp += lh4.calcProb_X(tree,X)
print " TEST 9.3 TreeSize: ",treeSize, len(data), tmp
#print data
def test10():
print "\n","="*20, " TEST 10, ","="*20
tCounter = 0
fCounter = 0
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
fu.sortData(data)
for X in data:
tmp = lh4.calcProb_X(tree,X)
for node in tree.iter_descendants():
tCounter +=1
if (abs(((lh4.calcProb_X_Z(tree,X,node.name,1)/tmp) + (lh4.calcProb_X_Z(tree,X,node.name,0)/tmp)) - 1.0) > 0.00001):
fCounter +=1
#print treeSize,tree, "\n",X,node.name
#print "P[X|T] = ", tmp
#print 1, " = ",(lh2.calcProbForXandZ(tree,X,node.name,1)/tmp) + (lh2.calcProbForXandZ(tree,X,node.name,0)/tmp)
#print lh2.calcProbForXandZ(tree,X,node.name,1)
#print lh2.calcProbForXandZ(tree,X,node.name,0)
#raw_input("continue")
#if (1 != ((lh2.calcProbwithZ(tree,X,node.name,1)/tmp) + (lh2.calcProbwithZ(tree,X,node.name,0)/tmp))):
print " TEST 10 TreeSize: ",treeSize, tCounter-fCounter, " out of ", tCounter, "were Successful, len(data): ", len(data)
tCounter = 0
fCounter = 0
return None
def test11():
print "\n","="*20, " TEST 11, ","="*20
tCounter = 0
fCounter = 0
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree, Pz = 0.6, Px = 0.95, test = True)
tree = et.setRandomTreeNodes(tree)
data = fu.getAllDataPoints(tree)
#fu.printTreeInfo(tree)
fu.sortData(data)
allPoints = []
for X in data:
tmp = lh4.calcProb_X(tree,X)
for node in tree.iter_descendants():
tCounter +=1
if not node.is_root():
for a in range(0,2):
p_x_Zp = (lh4.calcProb_X_Z(tree,X,node.up.name,a))
p_X_Z0_Zp = lh4.calcProb_X_Z_Zp(tree,X,node.name,0,node.up.name,a)
p_X_Z1_Zp = lh4.calcProb_X_Z_Zp(tree,X,node.name,1,node.up.name,a)
#fu.printTreeInfo(tree)
#print X,"\n", node.up.name," = ", a, node.name
#print p_x_Zp, p_X_Z0_Zp, p_X_Z1_Zp,
#raw_input("Continue1")
if (abs(p_X_Z1_Zp+p_X_Z0_Zp-p_x_Zp) > 0.0000000001):
fu.printTreeInfo(tree)
print X,"\n", node.up.name," = ", a, node.name
print p_x_Zp, p_X_Z0_Zp, p_X_Z1_Zp,
raw_input("Continue2")
print " TEST 11 TreeSize: ",treeSize, tCounter-fCounter, " out of ", tCounter, "were Successful, len(data): ", len(data)
tCounter = 0
fCounter = 0
return None
def test12():
print "Example 1, small 3 level tree"
for treeSize in range(2,10):
mutations = list(abbrs)
tree = et.generate(treeSize,mutations,False, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree, Pz = 0.6, Px = 0.95, test = True)
data = fu.getAllDataPoints(tree)
fu.printTreeInfo(tree)
for X in data:
p_X = lh4.calcProb_X(tree,X)
print "\nP[",X,"|T] = ", p_X
for node in tree.iter_descendants():
p_X_Zp1 = lh4.calcProb_X_Z(tree,X,node.up.name,1)
p_X_Zp0 = lh4.calcProb_X_Z(tree,X,node.up.name,0)
print "p(", node.name,") = ",node.up.name
print "P[z(",node.up.name,") = 1, X, | T] = ",p_X_Zp1
print "P[z(",node.up.name,") = 0, X, | T] = ",p_X_Zp0
if not node.is_root():
p_X_Z1_Zp0 = lh4.calcProb_X_Z_Zp(tree,X,node.name,1, node.up.name, 0)
p_X_Z1_Zp1 = lh4.calcProb_X_Z_Zp(tree,X,node.name,1, node.up.name, 1)
p_X_Z0_Zp0 = lh4.calcProb_X_Z_Zp(tree,X,node.name,0, node.up.name, 0)
p_X_Z0_Zp1 = lh4.calcProb_X_Z_Zp(tree,X,node.name,0, node.up.name, 1)
print "P[z(",node.name,") = 1, z(",node.up.name,")= 1, X, | T] = ", p_X_Z1_Zp1
print "P[z(",node.name,") = 0, z(",node.up.name,")= 1, X, | T] = ", p_X_Z0_Zp1
print "P[z(",node.name,") = 1, z(",node.up.name,")= 0, X, | T] = ", p_X_Z1_Zp0
print "P[z(",node.name,") = 0, z(",node.up.name,")= 0, X, | T] = ", p_X_Z0_Zp0
print "P[z(",node.up.name,")) = 1, X, | T] = ", p_X_Zp1
print "P[z(",node.up.name,")) = 0, X, | T] = ", p_X_Zp0
tmp = p_X_Z1_Zp0 + p_X_Z0_Zp0 - p_X_Zp0
tmp2 = 100000 + tmp
if not ( tmp2 == 100000):
raw_input("MAJOR ERROR")
#,(p_X_Z0_Zp1 + p_X_Z1_Zp1) - p_X_Zp1, p_X_Zp1, p_X_Z1_Zp0, p_X_Z1_Zp1
#print " 0 = ",(p_X_Z0_Zp0 + p_X_Z1_Zp0) - p_X_Zp0, p_X_Zp0, p_X_Z0_Zp0, p_X_Z0_Zp1
def test13():
print "Example 2, small 2 level tree"
print """
P[!X|T] = 0.59
P[X|T] = 0.41
"""
mutations = list(abbrs)
tree = et.generate(2,mutations,True, False) # small one-lvl tree
tree = et.setRandomTreeNodes(tree, Pz = 0.6, Px = 0.95, test = True)
data = fu.getAllDataPoints(tree)
fu.printTreeInfo(tree)
for X in data:
p_X = lh4.calcProb_X(tree,X)
print X, p_X
for node in tree.iter_descendants():
print node.name
print "Z(",node.name,") =", 1,lh4.calcProb_X_Z(tree,X,node.name,1), "= 0.57"
print "Z(",node.name,") =", 0,lh4.calcProb_X_Z(tree,X,node.name,0), "= 0.02"
if node.is_leaf():
print lh4.calcProb_X_Z_Zp(tree,X,node.name,0, node.up.name, 0)
print lh4.calcProb_X_Z_Zp(tree,X,node.name,0, node.up.name, 1)
print lh4.calcProb_X_Z_Zp(tree,X,node.name,1, node.up.name, 0)
print lh4.calcProb_X_Z_Zp(tree,X,node.name,1, node.up.name, 1)