-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
70 lines (58 loc) · 1.4 KB
/
functions.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
#
#import emAlgorithm as em
import emAlgorithm2 as em2
def uniqueData(data): # returns a list of only unique datapoints
ret = []
for i in data:
if i not in ret:
ret.append(i)
return ret
def printTreeInfo(tree):
print "="*20,"Tree Info:","="*20,
print tree
for node in tree.traverse():
print node.name, node.Pz, node.Px, node.Ez, node.Ex
def printTreeInfo2(tree,data):
print "="*20,"Tree Info:","="*20,
print tree
probsA = em2.probListA(tree,data)
probsB = em2.probListB(tree,data)
tot = 0
for node in tree.iter_descendants():
tmp = em2.arcWeigth(probsA,probsB,node.name,node.up.name,data,tree)
print node.name, node.Pz, node.Px, tmp
tot += tmp
print "Qvalue: ", tot
def sortData(data):
data.sort(reverse = True)
return data
def getOpposite(X):
tmp = list(X)
tmpD = {}
for mutation in tmp:
if mutation == "root":
tmpD[mutation] = X[mutation]
else:
tmpD[mutation] = not X[mutation]
#print X, tmp,tmpD
return tmpD
def binary(length,number):
string = bin(number)[2:].zfill(length)
temp = []
for i in string:
temp.append(int(i))
return temp
def getAllDataPoints(tree):
data = []
mutList = []
for node in tree.iter_descendants():
mutList.append(node.name)
all_combos = []
for i in range(0,2**len(mutList)):
tmp = {}
tmp2 = binary(len(mutList),i)
tmp["root"] = True
for k in range(len(tmp2)):
tmp[mutList[k]] = bool(tmp2[k])
data.append( tmp)
return data