annotate tools/mytools/cdf-old-not-used/cdf2.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 python wrapper for cdf plot
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 import os,sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 filename1 = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 filename2 = sys.argv[2]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 output = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 c1 = sys.argv[4].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 c2 = sys.argv[5].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 label1,label2 = sys.argv[6].strip().split(',')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 title = sys.argv[8].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 log = sys.argv[7]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 rf = open('tmp.r','w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 rf.write("options(warn=-1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 rf.write("x1 <- read.table('"+filename1+"')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 rf.write("x2 <- read.table('"+filename2+"')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 rf.write("mycdf <- function(x1,x2) {\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 rf.write(" sx1 <- sort(x1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 rf.write(" sy1 <- c(1:length(sx1))/length(sx1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 rf.write(" sx2 <- sort(x2)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 rf.write(" sy2 <- c(1:length(sx2))/length(sx2)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 rf.write(" mi <- min(c(x1,x2))\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 rf.write(" ma <- max(c(x1,x2))\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 rf.write(" sx1 <- c(mi,sx1,ma)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 rf.write(" sx2 <- c(mi,sx2,ma)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 rf.write(" sy1 <- c(0,sy1,1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 rf.write(" sy2 <- c(0,sy2,1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 rf.write(" pv <- ks.test(x1,x2)$p.value\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 rf.write(" list(sx1,sy1,sx2,sy2,pv)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 rf.write("}\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 rf.write("list1 <- x1[,"+c1+"]\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 rf.write("list2 <- x2[,"+c2+"]\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 rf.write("list1[list1 > 1e10] <- 1e10\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 rf.write("list2[list2 > 1e10] <- 1e10\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 rf.write("list1[list1 < -1e10] <- -1e10\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 rf.write("list2[list2 < -1e10] <- -1e10\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 rf.write("max(list1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 rf.write("max(list2)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 rf.write("min(list1)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 rf.write("min(list2)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 if log == 'log':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 rf.write("list1 <- log2(list1) \n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 rf.write("list2 <- log2(list2) \n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 rf.write("res <- mycdf(list1,list2)\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 rf.write("pdf('"+output+"')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 rf.write("plot(res[[1]],res[[2]],type='l',lty=1,lwd=2,col='red',main=paste('"+title+"',format(res[[5]], digit=2,scientific = T),sep=' , p='),xlab='value',ylab='cumulative frequency')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 rf.write("lines(res[[3]],res[[4]],type='l',lty=2,lwd=2,col='blue')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 rf.write("legend('bottomright',c('"+label1+"','"+label2+"'),col=c('red','blue'), lty=1:2, lwd=2, bty='n')\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 rf.write("dev.off()\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 rf.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 os.system("R --vanilla < tmp.r")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 os.system('rm tmp.r')