annotate endbias.py @ 22:869c7664e584

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