annotate Dotplot_Release/R_dotPlot.R @ 4:a0b4bcf67972 draft

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