Mercurial > repos > xuebing > sharplabtool
comparison mytools/spatial_proximity.py @ 9:87eb5c5ddfe9
Uploaded
author | xuebing |
---|---|
date | Fri, 09 Mar 2012 20:01:43 -0500 |
parents | f0dc65e7f6c0 |
children |
comparison
equal
deleted
inserted
replaced
8:361ec1c0479d | 9:87eb5c5ddfe9 |
---|---|
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) |