annotate tools/mytools/endbias.py @ 1:cdcb0ce84a1b

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