-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathappendTissueSpecExpressionEntropy.py
More file actions
executable file
·89 lines (72 loc) · 1.57 KB
/
appendTissueSpecExpressionEntropy.py
File metadata and controls
executable file
·89 lines (72 loc) · 1.57 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
#!/usr/bin/env python
from math import log
from sys import *
from albertcommon import *
def entropy(values):
#transform values such that all values above 0
mvalues=min(values)
if mvalues<0:
for i in range(0,len(values)):
values[i]-=mvalues
totalwgt=float(sum(values))
if totalwgt==0:
return "NA"
Hg=0.0
for wgt in values:
try:
Ptg=wgt/totalwgt
if Ptg<0:
print >> stderr,"Ptg<0, should not happen. abort"
exit(1)
if Ptg==0:
continue #Ptg==0, don't contribute to entropy?
#print >> stderr,Ptg
Hg-=1*Ptg*log(Ptg,2)
except:
print >> stderr,"values=",values,"Ptg=%f wgt=%f totalwgt=%f Hg=%f" %(Ptg,wgt,totalwgt,Hg)
exit(1)
pass
return Hg
def toFloatList(fields,noise):
values=[]
for f in fields:
try:
values.append(float(f)+noise)
except:
pass
return values
noise=0.000000
if __name__=='__main__':
programName=argv[0]
args=argv[1:]
try:
matrix,valcols=args
except:
print >> stderr,programName,"matrixFile valcols > outputFileWithHgAppended"
explainColumns(stderr)
exit()
fs="\t"
startRow=2
headerRow=1
header,prestarts=getHeader(matrix,headerRow,startRow,fs)
valcols=getCol0ListFromCol1ListStringAdv(header,valcols)
lino=0
fil=open(matrix)
for lin in fil:
lino+=1
lin=lin.rstrip("\r\n")
fields=lin.split(fs)
if lino<startRow:
fields+=["Hg"]
else:
values=toFloatList(getSubvector(fields,valcols),noise)
if len(values)==0:
Hg="NA"
else:
try:
Hg=entropy(values)
except:
Hg="NA"
fields+=[str(Hg)]
print >> stdout,fs.join(fields)
fil.close()