Mercurial > repos > xuebing > sharplab_seq_motif
comparison mytools/spatial_proximity.py @ 0:39217fa39ff2
Uploaded
author | xuebing |
---|---|
date | Tue, 13 Mar 2012 23:34:52 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:39217fa39ff2 |
---|---|
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) |