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