-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGSEAcorr2.Rmd
More file actions
225 lines (189 loc) · 9.39 KB
/
GSEAcorr2.Rmd
File metadata and controls
225 lines (189 loc) · 9.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
---
title: "GSEA"
---
```{r setup, echo=F,message=F,warning=F}
library(scales)
library(colorspace)
source("~/Dropbox/GDB/line2user.R")
par(mar=c(3,3,2,1),mgp=2:0)
.PAR <- par(no.readonly=T)
knitr::opts_chunk$set(
echo=F,
message=F,
warning=F
)
```
# Mean signed FDR (downsampled)
Since number of samples being averaged was causing artifacts, downsampled to averaging 5 randomly selected samples from each sample set. Repeated enough times to cover the largest set once.
## Overall and within-set comparisons
Left: FDR-correction for all sample sets (ie. cell types / ligands) together, per downsample.
Right: FDR-correction per sample set, per downsample.
```{r overall, fig.height=9,fig.width=9,warning=FALSE}
allCuts <- seq(4,0,by=-0.01)
par(mfrow=c(2,2),mar=c(3,3,2,1),mgp=2:0)
for (GSEA in c("REACT","GOBP")) {
load(paste0("~/Dropbox/GDB_archive/CMapCorr_files/pfdrGSEA_",GSEA,"_DS.RData"))
temp_max <- allCuts[min(sapply(list(NQall_CT,NQall_LIG,NQall_LIGCT),
function(X) which(colMeans(X) > 0)[1] - 1))]
plot(NA,NA,xlim=c(0,temp_max),xaxt="n",ylim=c(0,1),main=GSEA,cex.lab=0.9,
xlab="Threshold of FDR-corrected P(mean signed GSEA FDR) by chance",
ylab="Mean proportion of FDR \u2264 x for sample set averages")
axis(side=1,labels=c(.0001,.001,.01,.05,.1,.5,1),
at=-log10(c(.0001,.001,.01,.05,.1,.5,1)))
temp <- apply(NQall_CT[sample(nrow(NQall_CT),nrow(NQall_LIGCT)),],1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[1]))
temp <- apply(NQall_LIG[sample(nrow(NQall_LIG),nrow(NQall_LIGCT)),],1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[2]))
temp <- apply(NQall_LIGCT,1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[3]))
lines(allCuts,colMeans(NQall_CT),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[1])
lines(allCuts,colMeans(NQall_LIG),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[2])
lines(allCuts,colMeans(NQall_LIGCT),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[3])
temp_c2l <- ks.test(colMeans(NQall_CT),colMeans(NQall_LIG))$p.value
temp_l2lc <- ks.test(colMeans(NQall_LIG),colMeans(NQall_LIGCT))$p.value
legend("topright",bty="n",lwd=c(1,NA,1,NA,1),
col=as.vector(sapply(qualitative_hcl(3,palette="dark3"),function(X) c(X,NA)))[1:5],
legend=c("Cell type",
paste("KS p =",signif(temp_c2l,2)),
"Ligand",
paste("KS p =",signif(temp_l2lc,2)),
"Lig / CT"))
plot(NA,NA,xlim=c(0,temp_max),xaxt="n",ylim=c(0,1),main=GSEA,cex.lab=0.9,
xlab="Threshold of FDR-corrected P(mean signed GSEA FDR) by chance",
ylab="Mean proportion of FDR \u2264 x for sample set averages")
axis(side=1,labels=c(.0001,.001,.01,.05,.1,.5,1),
at=-log10(c(.0001,.001,.01,.05,.1,.5,1)))
temp <- apply(NQper_CT[sample(nrow(NQper_CT),nrow(NQper_LIGCT)),],1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[1]))
temp <- apply(NQper_LIG[sample(nrow(NQper_LIG),nrow(NQper_LIGCT)),],1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[2]))
temp <- apply(NQper_LIGCT,1,function(X)
lines(allCuts,X,lwd=1,col=qualitative_hcl(3,palette="set2",alpha=0.5)[3]))
lines(allCuts,colMeans(NQper_CT),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[1])
lines(allCuts,colMeans(NQper_LIG),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[2])
lines(allCuts,colMeans(NQper_LIGCT),lwd=2,lty=3,col=qualitative_hcl(3,palette="dark3")[3])
temp_c2l <- ks.test(colMeans(NQper_CT),colMeans(NQper_LIG))$p.value
temp_l2lc <- ks.test(colMeans(NQper_LIG),colMeans(NQper_LIGCT))$p.value
legend("topright",bty="n",lwd=c(1,NA,1,NA,1),
col=as.vector(sapply(qualitative_hcl(3,palette="dark3"),function(X) c(X,NA)))[1:5],
legend=c("Cell type",
paste("KS p =",signif(temp_c2l,2)),
"Ligand",
paste("KS p =",signif(temp_l2lc,2)),
"Lig / CT"))
}
rm(list=grep("^temp",ls(),value=T))
```
Plotting averages only.
Left: all non-zero values.
Right: zoomed in.
```{r overall_avg, fig.height=9,fig.width=9,warning=FALSE}
allCuts <- seq(4,0,by=-0.01)
par(mfrow=c(2,2),mar=c(3,3,2,1),mgp=2:0)
for (GSEA in c("REACT","GOBP")) {
load(paste0("~/Dropbox/GDB_archive/CMapCorr_files/pfdrGSEA_",GSEA,"_DS.RData"))
temp_max <- allCuts[min(sapply(list(NQall_CT,NQall_LIG,NQall_LIGCT),
function(X) which(colMeans(X) > 0)[1]))]
plot(NA,NA,xlim=c(0,temp_max),xaxt="n",ylim=c(0,1),main=GSEA,cex.lab=0.9,
xlab="Threshold of FDR-corrected P(mean signed GSEA FDR) by chance",
ylab="Mean proportion of FDR \u2264 x for sample set averages")
axis(side=1,labels=c(.0001,.001,.01,.05,.1,.5,1),
at=-log10(c(.0001,.001,.01,.05,.1,.5,1)))
lines(allCuts,colMeans(NQall_CT),lwd=1,col=qualitative_hcl(3,palette="dark3")[1])
lines(allCuts,colMeans(NQall_LIG),lwd=1,col=qualitative_hcl(3,palette="dark3")[2])
lines(allCuts,colMeans(NQall_LIGCT),lwd=1,col=qualitative_hcl(3,palette="dark3")[3])
temp_c2l <- ks.test(colMeans(NQall_CT),colMeans(NQall_LIG))$p.value
temp_l2lc <- ks.test(colMeans(NQall_LIG),colMeans(NQall_LIGCT))$p.value
legend("topright",bty="n",lwd=c(1,NA,1,NA,1),
col=as.vector(sapply(qualitative_hcl(3,palette="dark3"),function(X) c(X,NA)))[1:5],
legend=c("Cell type",
paste("KS p =",signif(temp_c2l,2)),
"Ligand",
paste("KS p =",signif(temp_l2lc,2)),
"Lig / CT"))
temp_max <- -log10(0.5)
plot(NA,NA,xlim=c(0,temp_max),xaxt="n",ylim=c(0,1),main=GSEA,cex.lab=0.9,
xlab="Threshold of FDR-corrected P(mean signed GSEA FDR) by chance",
ylab="Mean proportion of FDR \u2264 x for sample set averages")
axis(side=1,labels=c(.0001,.001,.01,.05,.1,.5,1),
at=-log10(c(.0001,.001,.01,.05,.1,.5,1)))
lines(allCuts,colMeans(NQall_CT),lwd=1,col=qualitative_hcl(3,palette="dark3")[1])
lines(allCuts,colMeans(NQall_LIG),lwd=1,col=qualitative_hcl(3,palette="dark3")[2])
lines(allCuts,colMeans(NQall_LIGCT),lwd=1,col=qualitative_hcl(3,palette="dark3")[3])
}
```
## Cell line
```{r CT, fig.height=3,fig.width=9}
FDRcut <- 0.9
tempMAT <- apply(
sapply(seq_along(Qper_CT),function(X)
-log10(Qper_CT[[X]]) * sign(Mscore_CT[[X]]),
simplify="array"),
MARGIN=c(1,2),mean)
tempMAT <- tempMAT[apply(tempMAT,1,function(X) any(abs(X) >= -log10(FDRcut))),]
temp_lim <- max(abs(tempMAT))
temp_hSample <- hclust(dist(t(tempMAT)),method="ward.D2")
temp_hSet <- hclust(dist(tempMAT),method="ward.D2")
tempMAT <- tempMAT[temp_hSet$order,temp_hSample$order]
par(mar=c(2,6,0.5,0.5))
image(z=tempMAT,x=1:nrow(tempMAT),y=1:ncol(tempMAT),
col=diverging_hcl(1000,palette="Blue-Red3"),
breaks=seq(-temp_lim,temp_lim,length.out=1001),
xaxt="n",yaxt="n",xlab=NA,ylab=NA)
mtext(colnames(tempMAT),side=2,line=0.1,at=1:ncol(tempMAT),las=2,cex=0.7)
mtext(paste(GSEA,"gene set enrichment"),side=1)
mtext(paste0("|signed FDR| \u2264 ",FDRcut * 100,"%"),side=1,line=1)
rm(list=grep("^temp",ls(),value=T))
```
## Ligand
```{r LIG, fig.height=3,fig.width=9}
FDRcut <- 0.1
tempMAT <- apply(
sapply(seq_along(Qper_LIG),function(X)
-log10(Qper_LIG[[X]]) * sign(Mscore_LIG[[X]]),
simplify="array"),
MARGIN=c(1,2),mean)
tempMAT <- tempMAT[,apply(tempMAT,2,function(X) any(abs(X) >= -log10(FDRcut)))]
tempMAT <- tempMAT[apply(tempMAT,1,function(X) any(abs(X) >= -log10(FDRcut))),]
temp_lim <- max(abs(tempMAT))
temp_hSample <- hclust(dist(t(tempMAT)),method="ward.D2")
temp_hSet <- hclust(dist(tempMAT),method="ward.D2")
tempMAT <- tempMAT[temp_hSet$order,temp_hSample$order]
par(mar=c(2,4,0.5,0.5))
image(z=tempMAT,x=1:nrow(tempMAT),y=1:ncol(tempMAT),
col=diverging_hcl(1000,palette="Blue-Red3"),
breaks=seq(-temp_lim,temp_lim,length.out=1001),
xaxt="n",yaxt="n",xlab=NA,ylab=NA)
mtext(colnames(tempMAT),side=2,line=0.1,at=1:ncol(tempMAT),las=2,cex=0.7)
mtext(paste0("Ligands (",ncol(tempMAT),"/",length(Mscore_LIG),")"),side=2,line=3)
mtext(paste(GSEA,"gene set enrichment"),side=1)
mtext(paste0("|signed FDR| \u2264 ",FDRcut * 100,"%"),side=1,line=1)
rm(list=grep("^temp",ls(),value=T))
```
## Ligand per cell line
```{r LIGCT, fig.height=6,fig.width=9}
tempMAT <- apply(
sapply(seq_along(Qper_LIGCT),function(X)
-log10(Qper_LIGCT[[X]]) * sign(Mscore_LIGCT[[X]]),
simplify="array"),
MARGIN=c(1,2),mean)
tempMAT <- tempMAT[,apply(tempMAT,2,function(X) any(abs(X) >= -log10(FDRcut)))]
tempMAT <- tempMAT[apply(tempMAT,1,function(X) any(abs(X) >= -log10(FDRcut))),]
temp_lim <- max(abs(tempMAT))
temp_hSample <- hclust(dist(t(tempMAT)),method="ward.D2")
temp_hSet <- hclust(dist(tempMAT),method="ward.D2")
tempMAT <- tempMAT[temp_hSet$order,temp_hSample$order]
par(mar=c(2,1.5,0.5,0.5))
image(z=tempMAT,x=1:nrow(tempMAT),y=1:ncol(tempMAT),
col=diverging_hcl(1000,palette="Blue-Red3"),
breaks=seq(-temp_lim,temp_lim,length.out=1001),
xaxt="n",yaxt="n",xlab=NA,ylab=NA)
# mtext(colnames(tempMAT),side=2,line=0.1,at=1:ncol(tempMAT),las=2,cex=0.7)
mtext(paste0("Ligands per cell line (",
length(unique(sub("^.+_","",colnames(tempMAT)))),
"/295 unique ligands)"),
side=2,line=0.1)
mtext(paste(GSEA,"gene set enrichment"),side=1)
mtext(paste0("|signed FDR| \u2264 ",FDRcut * 100,"%"),side=1,line=1)
rm(list=grep("^temp",ls(),value=T))
```