annotate spatial_proximity.py @ 12:2f4ea569f048

Uploaded
author xuebing
date Sat, 10 Mar 2012 08:10:44 -0500
parents b7f1d9f8f3bc
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 import os,sys
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
3
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
4 file1 = sys.argv[1]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
5 file2 = sys.argv[2]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
6 genome = sys.argv[3]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
7 outplot = sys.argv[4]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
8 outlog = sys.argv[5]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
9 outbed = sys.argv[6]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
10
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
11 strandness = ''
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
12 if len(sys.argv) > 7:
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
13 strandness = sys.argv[7]
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
14
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
15 # real distance
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
16 cmd = 'closestBed -a '+file1+' -b '+file2 + ' '+strandness + ' -d -t first > '+outbed
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
17 os.system(cmd)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
18 # shuffle
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
19 cmd = 'shuffleBed -chrom -g '+genome+' -i '+file1+'> shuffled.bed'
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
20 os.system(cmd)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
21 # shuffled distance
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
22 cmd = 'closestBed -a shuffled.bed -b '+file2 + ' '+strandness + ' -d -t first > shuffled.dist'
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
23 os.system(cmd)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
24
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
25
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
26 # test in R
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
27 r = open('tmp.r','w')
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
28 r.write("options(warn=-1)\n")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
29 r.write("source('/Users/xuebing/galaxy-dist/tools/mytools/cdf.r')\n")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
30 r.write("x = read.table('"+outbed+"',sep='\t')\n")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
31 r.write("y = read.table('shuffled.dist',sep='\t')\n")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
32 r.write("pdf('"+outplot+"')\n")
b7f1d9f8f3bc 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")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
34 r.write("dev.off()\n")
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
35 r.close()
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
36 os.system("R --vanilla < tmp.r >"+outlog)