Mercurial > repos > bornea > dotplot_runner
comparison Dotplot_Release/R_dotPlot.R @ 0:dfa3436beb67 draft
Uploaded
| author | bornea |
|---|---|
| date | Fri, 29 Jan 2016 09:56:02 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:dfa3436beb67 |
|---|---|
| 1 #!/usr/bin/env Rscript | |
| 2 | |
| 3 args <- commandArgs(trailingOnly = TRUE) | |
| 4 | |
| 5 library('latticeExtra') | |
| 6 library('colorRamps') | |
| 7 | |
| 8 data.file <- read.table("SC_data.txt", sep="\t", header=TRUE, row.names=1) ### import spectral count data | |
| 9 data.file2 <- read.table("FDR_data.txt", sep="\t", header=TRUE, row.names=1) ### import FDR count data | |
| 10 data.file3 <- read.table("clustered_matrix.txt", sep="\t", header=TRUE, row.names=1) ### import clustered matrix | |
| 11 data.file4 <- scan("singletons.txt", what="", sep="\n", strip.white=T) ### import singleton data | |
| 12 | |
| 13 #setting parameters | |
| 14 | |
| 15 Sfirst=as.numeric(args[1]) #first FDR cutoff | |
| 16 Ssecond=as.numeric(args[2]) #second FDR cutoff | |
| 17 maxp=as.integer(args[3]) #maximum value for a spectral count | |
| 18 | |
| 19 #calculate column and row lengths | |
| 20 | |
| 21 #determine bait and prey ordering | |
| 22 | |
| 23 bait_levels=names(data.file3) | |
| 24 prey_levels=c(rownames(data.file3),data.file4) | |
| 25 | |
| 26 x_ord=factor(row.names(data.file),levels=prey_levels) | |
| 27 y_ord=factor(names(data.file),levels=bait_levels) | |
| 28 | |
| 29 df<-data.frame(y=rep(y_ord,nrow(data.file)) | |
| 30 ,x=rep(x_ord, each=ncol(data.file)) | |
| 31 ,z1=as.vector(t(data.file)) # Circle color | |
| 32 ,z2=as.vector(t(data.file/apply(data.file,1,max))) # Circle size | |
| 33 ,z3=as.vector(t(data.file2)) # FDR | |
| 34 ) | |
| 35 | |
| 36 df$z1[df$z1>maxp] <- maxp #maximum value for spectral count | |
| 37 df$z2[df$z2==0] <- NA | |
| 38 df$z3[df$z3>Ssecond] <- 0.05*maxp | |
| 39 df$z3[df$z3<=Ssecond & df$z3>Sfirst] <- 0.5*maxp | |
| 40 df$z3[df$z3<=Sfirst] <- 1*maxp | |
| 41 df$z4 <- df$z1 | |
| 42 df$z4[df$z4==0] <- 0 | |
| 43 df$z4[df$z4>0] <- 2.5 | |
| 44 | |
| 45 # The labeling for the colorkey | |
| 46 | |
| 47 labelat = c(0, maxp) | |
| 48 labeltext = c(0, maxp) | |
| 49 | |
| 50 # color scheme to use | |
| 51 | |
| 52 nmb.colors<-maxp | |
| 53 z.colors<-grey(rev(seq(0,0.9,0.9/nmb.colors))) #grayscale color scale | |
| 54 | |
| 55 #plot | |
| 56 | |
| 57 pl <- levelplot(z1~x*y, data=df | |
| 58 ,col.regions =z.colors #terrain.colors(100) | |
| 59 ,scales = list(x = list(rot = 90), y=list(cex=0.8), tck=0) # rotates X,Y labels and changes scale | |
| 60 ,colorkey = FALSE | |
| 61 ,xlab="Prey", ylab="Bait" | |
| 62 ,panel=function(x,y,z,...,col.regions){ | |
| 63 print(x) | |
| 64 z.c<-df$z1[ (df$x %in% as.character(x)) & (df$y %in% y)] | |
| 65 z.2<-df$z2[ (df$x %in% as.character(x)) & (df$y %in% y)] | |
| 66 z.3<-df$z3 | |
| 67 z.4<-df$z4 | |
| 68 panel.xyplot(x,y | |
| 69 ,as.table=TRUE | |
| 70 ,pch=21 # point type to use (circles in this case) | |
| 71 ,cex=((z.2-min(z.2,na.rm=TRUE))/(max(z.2,na.rm=TRUE)-min(z.2,na.rm=TRUE)))*3 #circle size | |
| 72 ,fill=z.colors[floor((z.c-min(z.c,na.rm=TRUE))*nmb.colors/(max(z.c,na.rm=TRUE)-min(z.c,na.rm=TRUE)))+1] # circle colors | |
| 73 ,col=z.colors[1+z.3] # border colors | |
| 74 ,lex=z.4 #border thickness | |
| 75 ) | |
| 76 } | |
| 77 #,main="Fold change" # graph main title | |
| 78 ) | |
| 79 if(ncol(data.file) > 4) ht=3.5+(0.36*((ncol(data.file)-1)-4)) else ht=3.5 | |
| 80 if(nrow(data.file) > 20) wd=8.25+(0.29*(nrow(data.file)-20)) else wd=5+(0.28*(nrow(data.file)-10)) | |
| 81 pdf("dotplot.pdf", onefile = FALSE, paper = "special", height = ht, width = wd, pointsize = 2) | |
| 82 print(pl) | |
| 83 dev.off() |
