annotate mytools/endbias.py @ 7:f0dc65e7f6c0

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:59:07 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
1 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
2 usage:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
3
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
4 python endbias.py utr5-coverage utr3-coverage outputfile
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
5 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
6 import sys,math
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
7
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
8 def getCoverage(filename):
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
9 f = open(filename)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
10 coverage = {}
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
11 for line in f:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
12 flds = line.strip().split('\t')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
13 score = float(flds[4])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
14 name = (flds[0].split('utr'))[0].strip('_')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
15 if coverage.has_key(name):
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
16 if score > coverage[name]:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
17 coverage[name] = score
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
18 else:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
19 coverage[name] = score
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
20 return coverage
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
21
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
22 def endBias(filename,utr5,utr3):
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
23 out = open(filename,'w')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
24 for txpt in utr5.keys():
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
25 if utr3.has_key(txpt):
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
26 out.write('\t'.join([txpt,str(utr5[txpt]),str(utr3[txpt]),str(math.log((1+utr5[txpt])/(1+utr3[txpt]),2))])+'\n')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
27 out.close()
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
28
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
29
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
30 utr5 = getCoverage(sys.argv[1])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
31 utr3 = getCoverage(sys.argv[2])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
32 endBias(sys.argv[3],utr5,utr3)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
33
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
34 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
35
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
36 utr5 = getCoverage('hmga2-utr5.coverage')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
37 utr3 = getCoverage('hmga2-utr3.coverage')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
38 logratio, cov5,cov3= endBias(utr5,utr3)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
39 2**pylab.median(logratio.values())
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
40
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
41 log2utr5 = pylab.log2(pylab.array(cov5)+1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
42 log2utr3 = pylab.log2(pylab.array(cov3)+1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
43
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
44 pylab.plot(log2utr5,log2utr3,'bo')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
45
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
46 pylab.show()
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
47
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
48 utr5 = getCoverage('control-utr5.coverage')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
49 utr3 = getCoverage('control-utr3.coverage')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
50 logratio, cov5,cov3= endBias(utr5,utr3)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
51 2**pylab.median(logratio.values())
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
52 '''