annotate endbias.py @ 11:b7f1d9f8f3bc

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