annotate spatial_proximity.py @ 2:e68d35c7d3eb default tip

Uploaded
author xuebing
date Sat, 31 Mar 2012 14:09:14 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
1
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
2 import os,sys
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
3
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
4 file1 = sys.argv[1]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
5 file2 = sys.argv[2]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
6 genome = sys.argv[3]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
7 outplot = sys.argv[4]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
8 outlog = sys.argv[5]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
9 outbed = sys.argv[6]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
10
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
11 strandness = ''
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
12 if len(sys.argv) > 7:
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
13 strandness = sys.argv[7]
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
14
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
15 # real distance
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
16 cmd = 'closestBed -a '+file1+' -b '+file2 + ' '+strandness + ' -d -t first > '+outbed
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
17 os.system(cmd)
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
18 # shuffle
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
19 cmd = 'shuffleBed -chrom -g '+genome+' -i '+file1+'> shuffled.bed'
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
20 os.system(cmd)
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
21 # shuffled distance
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
22 cmd = 'closestBed -a shuffled.bed -b '+file2 + ' '+strandness + ' -d -t first > shuffled.dist'
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
23 os.system(cmd)
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
24
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
25
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
26 # test in R
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
27 r = open('tmp.r','w')
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
28 r.write("options(warn=-1)\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
29 r.write("source('/Users/xuebing/galaxy-dist/tools/mytools/cdf.r')\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
30 r.write("x = read.table('"+outbed+"',sep='\t')\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
31 r.write("y = read.table('shuffled.dist',sep='\t')\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
32 r.write("pdf('"+outplot+"')\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
33 r.write("mycdf(list(log10(1+x[,ncol(x)]),log10(1+y[,ncol(y)])),'spatial distance',c('real','shuffled'),'topleft','log10 distance','')\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
34 r.write("dev.off()\n")
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
35 r.close()
e68d35c7d3eb Uploaded
xuebing
parents:
diff changeset
36 os.system("R --vanilla < tmp.r >"+outlog)