annotate baseline/comparePDFs.r @ 81:b6f9a640e098 draft

Uploaded
author davidvanzessen
date Fri, 19 Feb 2021 15:10:54 +0000
parents
children 729738462297
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
1 options("warn"=-1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
2
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
3 #from http://selection.med.yale.edu/baseline/Archive/Baseline%20Version%201.3/Baseline_Functions_Version1.3.r
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
4 # Compute p-value of two distributions
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
5 compareTwoDistsFaster <-function(sigma_S=seq(-20,20,length.out=4001), N=10000, dens1=runif(4001,0,1), dens2=runif(4001,0,1)){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
6 #print(c(length(dens1),length(dens2)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
7 if(length(dens1)>1 & length(dens2)>1 ){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
8 dens1<-dens1/sum(dens1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
9 dens2<-dens2/sum(dens2)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
10 cum2 <- cumsum(dens2)-dens2/2
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
11 tmp<- sum(sapply(1:length(dens1),function(i)return(dens1[i]*cum2[i])))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
12 #print(tmp)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
13 if(tmp>0.5)tmp<-tmp-1
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
14 return( tmp )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
15 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
16 else {
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
17 return(NA)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
18 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
19 #return (sum(sapply(1:N,function(i)(sample(sigma_S,1,prob=dens1)>sample(sigma_S,1,prob=dens2))))/N)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
20 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
21
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
22
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
23 require("grid")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
24 arg <- commandArgs(TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
25 #arg <- c("300143","4","5")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
26 arg[!arg=="clonal"]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
27 input <- arg[1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
28 output <- arg[2]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
29 rowIDs <- as.numeric( sapply(arg[3:(max(3,length(arg)))],function(x){ gsub("chkbx","",x) } ) )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
30
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
31 numbSeqs = length(rowIDs)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
32
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
33 if ( is.na(rowIDs[1]) | numbSeqs>10 ) {
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
34 stop( paste("Error: Please select between one and 10 seqeunces to compare.") )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
35 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
36
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
37 #load( paste("output/",sessionID,".RData",sep="") )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
38 load( input )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
39 #input
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
40
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
41 xMarks = seq(-20,20,length.out=4001)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
42
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
43 plot_grid_s<-function(pdf1,pdf2,Sample=100,cex=1,xlim=NULL,xMarks = seq(-20,20,length.out=4001)){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
44 yMax = max(c(abs(as.numeric(unlist(listPDFs[pdf1]))),abs(as.numeric(unlist(listPDFs[pdf2]))),0),na.rm=T) * 1.1
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
45
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
46 if(length(xlim==2)){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
47 xMin=xlim[1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
48 xMax=xlim[2]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
49 } else {
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
50 xMin_CDR = xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
51 xMin_FWR = xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
52 xMax_CDR = xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001][length(xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
53 xMax_FWR = xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001][length(xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
54
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
55 xMin_CDR2 = xMarks[listPDFs[pdf2][[1]][["CDR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
56 xMin_FWR2 = xMarks[listPDFs[pdf2][[1]][["FWR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
57 xMax_CDR2 = xMarks[listPDFs[pdf2][[1]][["CDR"]]>0.001][length(xMarks[listPDFs[pdf2][[1]][["CDR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
58 xMax_FWR2 = xMarks[listPDFs[pdf2][[1]][["FWR"]]>0.001][length(xMarks[listPDFs[pdf2][[1]][["FWR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
59
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
60 xMin=min(c(xMin_CDR,xMin_FWR,xMin_CDR2,xMin_FWR2,0),na.rm=TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
61 xMax=max(c(xMax_CDR,xMax_FWR,xMax_CDR2,xMax_FWR2,0),na.rm=TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
62 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
63
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
64 sigma<-approx(xMarks,xout=seq(xMin,xMax,length.out=Sample))$x
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
65 grid.rect(gp = gpar(col=gray(0.6),fill="white",cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
66 x <- sigma
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
67 pushViewport(viewport(x=0.175,y=0.175,width=0.825,height=0.825,just=c("left","bottom"),default.units="npc"))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
68 #pushViewport(plotViewport(c(1.8, 1.8, 0.25, 0.25)*cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
69 pushViewport(dataViewport(x, c(yMax,-yMax),gp = gpar(cex=cex),extension=c(0.05)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
70 grid.polygon(c(0,0,1,1),c(0,0.5,0.5,0),gp=gpar(col=grey(0.95),fill=grey(0.95)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
71 grid.polygon(c(0,0,1,1),c(1,0.5,0.5,1),gp=gpar(col=grey(0.9),fill=grey(0.9)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
72 grid.rect()
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
73 grid.xaxis(gp = gpar(cex=cex/1.1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
74 yticks = pretty(c(-yMax,yMax),8)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
75 yticks = yticks[yticks>(-yMax) & yticks<(yMax)]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
76 grid.yaxis(at=yticks,label=abs(yticks),gp = gpar(cex=cex/1.1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
77 if(length(listPDFs[pdf1][[1]][["CDR"]])>1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
78 ycdr<-approx(xMarks,listPDFs[pdf1][[1]][["CDR"]],xout=seq(xMin,xMax,length.out=Sample),yleft=0,yright=0)$y
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
79 grid.lines(unit(x,"native"), unit(ycdr,"native"),gp=gpar(col=2,lwd=2))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
80 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
81 if(length(listPDFs[pdf1][[1]][["FWR"]])>1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
82 yfwr<-approx(xMarks,listPDFs[pdf1][[1]][["FWR"]],xout=seq(xMin,xMax,length.out=Sample),yleft=0,yright=0)$y
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
83 grid.lines(unit(x,"native"), unit(-yfwr,"native"),gp=gpar(col=4,lwd=2))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
84 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
85
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
86 if(length(listPDFs[pdf2][[1]][["CDR"]])>1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
87 ycdr2<-approx(xMarks,listPDFs[pdf2][[1]][["CDR"]],xout=seq(xMin,xMax,length.out=Sample),yleft=0,yright=0)$y
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
88 grid.lines(unit(x,"native"), unit(ycdr2,"native"),gp=gpar(col=2,lwd=2,lty=2))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
89 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
90 if(length(listPDFs[pdf2][[1]][["FWR"]])>1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
91 yfwr2<-approx(xMarks,listPDFs[pdf2][[1]][["FWR"]],xout=seq(xMin,xMax,length.out=Sample),yleft=0,yright=0)$y
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
92 grid.lines(unit(x,"native"), unit(-yfwr2,"native"),gp=gpar(col=4,lwd=2,lty=2))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
93 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
94
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
95 grid.lines(unit(c(0,1),"npc"), unit(c(0.5,0.5),"npc"),gp=gpar(col=1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
96 grid.lines(unit(c(0,0),"native"), unit(c(0,1),"npc"),gp=gpar(col=1,lwd=1,lty=3))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
97
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
98 grid.text("All", x = unit(-2.5, "lines"), rot = 90,gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
99 grid.text( expression(paste("Selection Strength (", Sigma, ")", sep="")) , y = unit(-2.5, "lines"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
100
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
101 if(pdf1==pdf2 & length(listPDFs[pdf2][[1]][["FWR"]])>1 & length(listPDFs[pdf2][[1]][["CDR"]])>1 ){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
102 pCDRFWR = compareTwoDistsFaster(sigma_S=xMarks, N=10000, dens1=listPDFs[[pdf1]][["CDR"]], dens2=listPDFs[[pdf1]][["FWR"]])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
103 pval = formatC(as.numeric(pCDRFWR),digits=3)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
104 grid.text( substitute(expression(paste(P[CDR/FWR], "=", x, sep="")),list(x=pval))[[2]] , x = unit(0.02, "npc"),y = unit(0.98, "npc"),just=c("left", "top"),gp = gpar(cex=cex*1.2))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
105 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
106 grid.text(paste("CDR"), x = unit(0.98, "npc"),y = unit(0.98, "npc"),just=c("right", "top"),gp = gpar(cex=cex*1.5))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
107 grid.text(paste("FWR"), x = unit(0.98, "npc"),y = unit(0.02, "npc"),just=c("right", "bottom"),gp = gpar(cex=cex*1.5))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
108 popViewport(2)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
109 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
110 #plot_grid_s(1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
111
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
112
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
113 p2col<-function(p=0.01){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
114 breaks=c(-.51,-0.1,-.05,-0.01,-0.005,0,0.005,0.01,0.05,0.1,0.51)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
115 i<-findInterval(p,breaks)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
116 cols = c( rgb(0.8,1,0.8), rgb(0.6,1,0.6), rgb(0.4,1,0.4), rgb(0.2,1,0.2) , rgb(0,1,0),
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
117 rgb(1,0,0), rgb(1,.2,.2), rgb(1,.4,.4), rgb(1,.6,.6) , rgb(1,.8,.8) )
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
118 return(cols[i])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
119 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
120
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
121
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
122 plot_pvals<-function(pdf1,pdf2,cex=1,upper=TRUE){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
123 if(upper){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
124 pCDR1FWR2 = compareTwoDistsFaster(sigma_S=xMarks, N=10000, dens1=listPDFs[[pdf1]][["CDR"]], dens2=listPDFs[[pdf2]][["FWR"]])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
125 pFWR1FWR2 = compareTwoDistsFaster(sigma_S=xMarks, N=10000, dens1=listPDFs[[pdf1]][["FWR"]], dens2=listPDFs[[pdf2]][["FWR"]])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
126 pFWR1CDR2 = compareTwoDistsFaster(sigma_S=xMarks, N=10000, dens2=listPDFs[[pdf2]][["CDR"]], dens1=listPDFs[[pdf1]][["FWR"]])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
127 pCDR1CDR2 = compareTwoDistsFaster(sigma_S=xMarks, N=10000, dens2=listPDFs[[pdf2]][["CDR"]], dens1=listPDFs[[pdf1]][["CDR"]])
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
128 grid.polygon(c(0.5,0.5,1,1),c(0,0.5,0.5,0),gp=gpar(col=p2col(pFWR1FWR2),fill=p2col(pFWR1FWR2)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
129 grid.polygon(c(0.5,0.5,1,1),c(1,0.5,0.5,1),gp=gpar(col=p2col(pCDR1FWR2),fill=p2col(pCDR1FWR2)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
130 grid.polygon(c(0.5,0.5,0,0),c(1,0.5,0.5,1),gp=gpar(col=p2col(pCDR1CDR2),fill=p2col(pCDR1CDR2)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
131 grid.polygon(c(0.5,0.5,0,0),c(0,0.5,0.5,0),gp=gpar(col=p2col(pFWR1CDR2),fill=p2col(pFWR1CDR2)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
132
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
133 grid.lines(c(0,1),0.5,gp=gpar(lty=2,col=gray(0.925)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
134 grid.lines(0.5,c(0,1),gp=gpar(lty=2,col=gray(0.925)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
135
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
136 grid.text(formatC(as.numeric(pFWR1FWR2),digits=3), x = unit(0.75, "npc"),y = unit(0.25, "npc"),just=c("center", "center"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
137 grid.text(formatC(as.numeric(pCDR1FWR2),digits=3), x = unit(0.75, "npc"),y = unit(0.75, "npc"),just=c("center", "center"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
138 grid.text(formatC(as.numeric(pCDR1CDR2),digits=3), x = unit(0.25, "npc"),y = unit(0.75, "npc"),just=c("center", "center"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
139 grid.text(formatC(as.numeric(pFWR1CDR2),digits=3), x = unit(0.25, "npc"),y = unit(0.25, "npc"),just=c("center", "center"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
140
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
141
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
142 # grid.text(paste("P = ",formatC(pCDRFWR,digits=3)), x = unit(0.5, "npc"),y = unit(0.98, "npc"),just=c("center", "top"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
143 # grid.text(paste("P = ",formatC(pFWRFWR,digits=3)), x = unit(0.5, "npc"),y = unit(0.02, "npc"),just=c("center", "bottom"),gp = gpar(cex=cex))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
144 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
145 else{
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
146 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
147 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
148
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
149
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
150 ##################################################################################
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
151 ################## The whole OCD's matrix ########################################
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
152 ##################################################################################
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
153
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
154 #pdf(width=4*numbSeqs+1/3,height=4*numbSeqs+1/3)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
155 pdf( output ,width=4*numbSeqs+1/3,height=4*numbSeqs+1/3)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
156
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
157 pushViewport(viewport(x=0.02,y=0.02,just = c("left", "bottom"),w =0.96,height=0.96,layout = grid.layout(numbSeqs+1,numbSeqs+1,widths=unit.c(unit(rep(1,numbSeqs),"null"),unit(4,"lines")),heights=unit.c(unit(4,"lines"),unit(rep(1,numbSeqs),"null")))))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
158
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
159 for( seqOne in 1:numbSeqs+1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
160 pushViewport(viewport(layout.pos.col = seqOne-1, layout.pos.row = 1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
161 if(seqOne>2){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
162 grid.polygon(c(0,0,0.5,0.5),c(0,0.5,0.5,0),gp=gpar(col=grey(0.5),fill=grey(0.9)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
163 grid.polygon(c(1,1,0.5,0.5),c(0,0.5,0.5,0),gp=gpar(col=grey(0.5),fill=grey(0.95)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
164 grid.polygon(c(0,0,1,1),c(1,0.5,0.5,1),gp=gpar(col=grey(0.5)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
165
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
166 grid.text(y=.25,x=0.75,"FWR",gp = gpar(cex=1.5),just="center")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
167 grid.text(y=.25,x=0.25,"CDR",gp = gpar(cex=1.5),just="center")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
168 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
169 grid.rect(gp = gpar(col=grey(0.9)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
170 grid.text(y=.75,substr(paste(names(listPDFs)[rowIDs[seqOne-1]]),1,16),gp = gpar(cex=2),just="center")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
171 popViewport(1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
172 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
173
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
174 for( seqOne in 1:numbSeqs+1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
175 pushViewport(viewport(layout.pos.row = seqOne, layout.pos.col = numbSeqs+1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
176 if(seqOne<=numbSeqs){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
177 grid.polygon(c(0,0.5,0.5,0),c(0,0,0.5,0.5),gp=gpar(col=grey(0.5),fill=grey(0.95)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
178 grid.polygon(c(0,0.5,0.5,0),c(1,1,0.5,0.5),gp=gpar(col=grey(0.5),fill=grey(0.9)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
179 grid.polygon(c(1,0.5,0.5,1),c(0,0,1,1),gp=gpar(col=grey(0.5)),default.units="npc")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
180 grid.text(x=.25,y=0.75,"CDR",gp = gpar(cex=1.5),just="center",rot=270)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
181 grid.text(x=.25,y=0.25,"FWR",gp = gpar(cex=1.5),just="center",rot=270)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
182 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
183 grid.rect(gp = gpar(col=grey(0.9)))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
184 grid.text(x=0.75,substr(paste(names(listPDFs)[rowIDs[seqOne-1]]),1,16),gp = gpar(cex=2),rot=270,just="center")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
185 popViewport(1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
186 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
187
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
188 for( seqOne in 1:numbSeqs+1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
189 for(seqTwo in 1:numbSeqs+1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
190 pushViewport(viewport(layout.pos.col = seqTwo-1, layout.pos.row = seqOne))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
191 if(seqTwo>seqOne){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
192 plot_pvals(rowIDs[seqOne-1],rowIDs[seqTwo-1],cex=2)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
193 grid.rect()
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
194 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
195 popViewport(1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
196 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
197 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
198
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
199
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
200 xMin=0
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
201 xMax=0.01
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
202 for(pdf1 in rowIDs){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
203 xMin_CDR = xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
204 xMin_FWR = xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001][1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
205 xMax_CDR = xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001][length(xMarks[listPDFs[pdf1][[1]][["CDR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
206 xMax_FWR = xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001][length(xMarks[listPDFs[pdf1][[1]][["FWR"]]>0.001])]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
207 xMin=min(c(xMin_CDR,xMin_FWR,xMin),na.rm=TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
208 xMax=max(c(xMax_CDR,xMax_FWR,xMax),na.rm=TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
209 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
210
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
211
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
212
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
213 for(i in 1:numbSeqs+1){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
214 for(j in (i-1):numbSeqs){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
215 pushViewport(viewport(layout.pos.col = i-1, layout.pos.row = j+1))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
216 grid.rect()
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
217 plot_grid_s(rowIDs[i-1],rowIDs[j],cex=1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
218 popViewport(1)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
219 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
220 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
221
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
222 dev.off()
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
223
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
224 cat("Success", paste(rowIDs,collapse="_"),sep=":")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
225