-
Notifications
You must be signed in to change notification settings - Fork 3
/
transformGenomicMatrix.py
49 lines (39 loc) · 1.24 KB
/
transformGenomicMatrix.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
import string, sys, os
import math
def parseUnit(unit): # working progress
if string.find(unit,"log") != -1:
logBase = string.strip(string.split(unit,'(')[0])[3:]
theta = string.strip(string.split(string.split(unit,'(')[1], ')')[0])
theta = string.strip(string.split(theta, '+')[1])
if logBase != '' and theta != '':
return [int(logBase), float(theta)]
else:
return None
def setLowNA_log2TMPplus (value):
#for unit = log2(tmp+0.001) turn all value < -6 to NA
try:
if float(value) < -6:
return ' '
else:
return value
except:
return ' '
def process (infile, outfile, action):
fout=open(outfile,'w')
#header
fin=open(infile,'rU')
fout.write(fin.readline())
while 1:
line = fin.readline()
if line == '':
break
data = string.split(line[:-1], '\t')
values = map(lambda x: action(x), data[1:])
fout.write(data[0] + '\t' + string.join(map(lambda x: str(x), values), '\t') +'\n')
fout.close()
if len(sys.argv[:])!= 3:
print "python transformGenomicMatrix fin fout"
sys.exit()
infile = sys.argv[1]
outfile= sys.argv[2]
process(infile, outfile, setLowNA_log2TMPplus)