-
Notifications
You must be signed in to change notification settings - Fork 6
/
comparison_between_datasets.Rmd
412 lines (368 loc) · 14.5 KB
/
comparison_between_datasets.Rmd
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
---
title: "Dataset comparisons"
author: "Dan Bunis"
date: "9/28/2020"
output:
html_document:
toc: true
theme: united
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dittoSeq)
library(DESeq2)
library(Seurat)
library(MAST)
library(eulerr)
```
# NOTE: This code requires outputs of other markdown code from this porject and should be run last.
Required data:
- Final output, bulkCD4.Rds, of the bulk naive CD4 T cell analysis (bulkRNAseq_CD4naiveTcells.Rmd).
- Final output, Tcells.Rds, of the single-cell naive T cell analyses (scRNAseq_naiveTcells.Rmd)
- Differential expression output of T cells, Microarray_APBvsFPBTcells_FDR0.05_FC1.5_LongAnn.csv, from microarray analysis (generated in the first half of microarray-and-qRTPCR_CD4naiveTcells-and-monocytes.Rmd)
# 0) Load datasets
```{r}
Tcells <- readRDS("Tcells.rds")
bulkCD4 <- readRDS("bulkCD4.rds")
bulkCD4_dds <- readRDS("bulkCD4_dds.rds")
```
# 1) Comparison of bulk and single-cell naive CD4 T cell differential expression calls
Equivalent differential expression cutoff:
- Absolute Fold Change >= 1.5
- FDR <= 0.05
- Non-ribosomal & non-mitochondrial (not analyzed in the bulk RNAseq datasset)
```{r, results = "hide"}
# Create function to remove ribosomal and mitochondrial genes
remove.ribo.mito <- function(genelist){
if (length(grep("^RPL|^RPS|^MT-",genelist))>0){
return(genelist[-grep("^RPL|^RPS|^MT-",genelist)])
} else {
genelist
}
}
# Set the clustering to be by T-celltype + age ("Tage" meta) so the Seurat FindMarkers function will use this.
Idents(Tcells) <- "Tage"
# Fetal vs Adult
sc4FvA <- FindMarkers(Tcells,
ident.1 = "4-fetal",
ident.2 = "4-adult",
test.use = "MAST")
sc4FvA_padjFC <- sc4FvA[abs(sc4FvA$avg_logFC)>=0.585 &
sc4FvA$p_val_adj<=0.05 &
!is.na(sc4FvA$p_val_adj),]
# Fetal vs UCB
sc4FvC <- FindMarkers(Tcells,
ident.1 = "4-fetal",
ident.2 = "4-cord",
test.use = "MAST")
sc4FvC_padjFC <- sc4FvC[abs(sc4FvC$avg_logFC)>=0.585 &
sc4FvC$p_val_adj<=0.05 &
!is.na(sc4FvC$p_val_adj),]
# UCB vs Adult
sc4CvA <- FindMarkers(Tcells,
ident.1 = "4-cord",
ident.2 = "4-adult",
test.use = "MAST")
sc4CvA_padjFC <- sc4CvA[abs(sc4CvA$avg_logFC)>=0.585 &
sc4CvA$p_val_adj<=0.05 &
!is.na(sc4CvA$p_val_adj),]
### Split up and down genes.
FETAL_sc4FvA <- remove.ribo.mito(rownames(sc4FvA_padjFC[sc4FvA_padjFC$avg_logFC>0,]))
ADULT_sc4FvA <- remove.ribo.mito(rownames(sc4FvA_padjFC[sc4FvA_padjFC$avg_logFC<0,]))
FETAL_sc4FvC <- remove.ribo.mito(rownames(sc4FvC_padjFC[sc4FvC_padjFC$avg_logFC>0,]))
UCB_sc4FvC <- remove.ribo.mito(rownames(sc4FvC_padjFC[sc4FvC_padjFC$avg_logFC<0,]))
UCB_sc4CvA <- remove.ribo.mito(rownames(sc4CvA_padjFC[sc4CvA_padjFC$avg_logFC>0,]))
ADULT_sc4CvA <- remove.ribo.mito(rownames(sc4CvA_padjFC[sc4CvA_padjFC$avg_logFC<0,]))
```
Re-calculate the bulk markers
```{r, results = "hide"}
#Extract comparisons from DESeq
FvA <- as.data.frame(results(bulkCD4_dds, contrast=c("Age","Fetal","Adult")))
FvC <- as.data.frame(results(bulkCD4_dds, contrast=c("Age","Fetal","Cord")))
CvA <- as.data.frame(results(bulkCD4_dds, contrast=c("Age","Cord","Adult")))
#Trim to DE cutoffs
FvA_padjFC <- FvA[(
(FvA$padj<=0.05) & (abs(FvA$log2FoldChange)>=0.585*log2(exp(1))) & (!is.na(FvA$padj))
),]
FvC_padjFC <- FvC[(
(FvC$padj<=0.05) & (abs(FvC$log2FoldChange)>=0.585*log2(exp(1))) & (!is.na(FvC$padj))
),]
CvA_padjFC <- CvA[(
(CvA$padj<=0.05) & (abs(CvA$log2FoldChange)>=0.585*log2(exp(1))) & (!is.na(CvA$padj))
),]
### Split up and down genes.
FETAL_FvA <- rownames(FvA_padjFC[FvA_padjFC$log2FoldChange>0,])
FETAL_FvC <- rownames(FvC_padjFC[FvC_padjFC$log2FoldChange>0,])
UCB_FvC <- rownames(FvC_padjFC[FvC_padjFC$log2FoldChange<0,])
UCB_CvA <- rownames(CvA_padjFC[CvA_padjFC$log2FoldChange>0,])
ADULT_FvA <- rownames(FvA_padjFC[FvA_padjFC$log2FoldChange<0,])
ADULT_CvA <- rownames(CvA_padjFC[CvA_padjFC$log2FoldChange<0,])
```
## Venns
```{r}
width = 1.5
height = 0.85
eulerr_options(fills = list(fill = dittoColors()[c(4,5)],
alpha = c(1,1)),
labels = list(fontsize = 9))
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_FetalvA.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(FETAL_FvA),
'scCD4s' = list(FETAL_sc4FvA))))
dev.off()
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_AdultvF.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(ADULT_FvA),
'scCD4s' = list(ADULT_sc4FvA))))
dev.off()
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_FetalvC.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(FETAL_FvC),
'scCD4s' = list(FETAL_sc4FvC))))
dev.off()
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_CordvF.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(UCB_FvC),
'scCD4s' = list(UCB_sc4FvC))))
dev.off()
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_CordvA.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(UCB_CvA),
'scCD4s' = list(UCB_sc4CvA))))
dev.off()
set.seed(1908)
pdf("Comparison-Figs/venn_CD4s_AdultvC.pdf", w=width, h=height)
plot(venn(c('bulkCD4s' = list(ADULT_CvA),
'scCD4s' = list(ADULT_sc4CvA))))
dev.off()
```
## Overlapping Genes Exploration
```{r}
allsc4 <- unique(c(rownames(sc4FvA_padjFC),
rownames(sc4FvC_padjFC),
rownames(sc4CvA_padjFC)))
allbulk4 <- unique(c(FETAL_FvA, FETAL_FvC,
UCB_FvC, UCB_CvA,
ADULT_FvA, ADULT_CvA))
# What are the unique-to-single-cell genes in the Fetal vs Adult comparison?
remove.ribo.mito(rownames(
sc4FvA_padjFC[!rownames(sc4FvA_padjFC) %in% c(FETAL_FvA, ADULT_FvA),]))
# What are the unique-to-single-cell genes in the Fetal vs UCB comparison?
remove.ribo.mito(rownames(
sc4FvC_padjFC[!rownames(sc4FvC_padjFC) %in% c(FETAL_FvC, UCB_FvC),]))
```
# 2) Compare expression of peripheral-only Microarray FvA genes in mixed tissue bulk RNAseq
This is a comparison of how the naive CD4 T cell gene signature obtained from comparison of fetal peripheral versus adult peripheral blood samples with microarray works for characterizing Fetal-splenic (vs UCB) vs Adult peripheral blood naive CD4 T cells in bulk RNA-seq.
```{r}
# Read in microarray signature
# The differential expression microaarray data is already cutoff to log2FC=1.5 and FDR <= 0.05.
microarray <- read.csv("Microarray_APBvsFPBTcells_FDR0.05_FC1.5_LongAnn.csv",
header = T, row.names = 1)
# Remove genes not analyzed further in this dataset.
microarray <- microarray[-grep("^XLOC|^LOC|^ENST|ORF|orf|A_19|A_24|A_33", rownames(microarray)),]
# Trim to only the genes in the bulk RNAseq dataset.
microarray_in <- microarray[isGene(rownames(microarray),bulkCD4),]
# Store directionality
enriched <- array("fetal-enriched", nrow(microarray_in))
enriched[microarray_in$logFC>0] <- "adult-enriched"
# Create a metadata for easily labeling the samples with their tissue identities.
age.names <- factor(meta("Samples", bulkCD4), labels = paste0(rep(c("APB-","FS-","UCB-"),each = 5), 1:5))
bulkCD4$age.names <- age.names
### Plot
# Create Heatmap
hm <- dittoHeatmap(
genes = rownames(microarray_in), object = bulkCD4, annot.by = "Age",
annotation_row = data.frame(
'MicroarrayAnnotation' = enriched,
row.names = rownames(microarray_in)),
annot.colors = c(dittoColors()[1:3], "red", "blue"),
cutree_row = 2, cutree_col = 3,
show_rownames = FALSE, cell.names.meta = "age.names",
treeheight_row = 15, treeheight_col = 15)
# Create fetal (microarray) gene summary plot
(pF <- dittoPlotVarsAcrossGroups(
rownames(microarray_in[microarray_in$logFC<0,]),
object = bulkCD4,
group.by = "Age",
x.reorder = 3:1, colors = 3:1,
x.labels = c("FS", "UCB", "APB"),
plots = c("vlnplot","boxplot"),
adjustment = "z-score",
main = NULL, jitter.size = 0.3,
sub = "Fetal-enriched\nmicroarray genes",
boxplot.color = "white",
boxplot.fill = FALSE,
y.breaks = -1:1,
xlab = NULL,
ylab = NULL,
legend.show = FALSE,
vlnplot.lineweight = 0.5,
theme = theme_bw()))
# Create adult (microarray) gene summary plot
(pA <- dittoPlotVarsAcrossGroups(
rownames(microarray_in[microarray_in$logFC>0,]),
object = bulkCD4,
group.by = "Age",
x.reorder = 3:1, colors = 3:1,
x.labels = c("FS", "UCB", "APB"),
plots = c("vlnplot","boxplot"),
adjustment = "z-score",
main = NULL, jitter.size = 0.3,
sub = "Adult-enriched\nmicroarray genes",
boxplot.color = "white",
boxplot.fill = FALSE,
y.breaks = -1:1,
xlab = NULL,
ylab = NULL,
legend.show = FALSE,
vlnplot.lineweight = 0.5,
theme = theme_bw()))
# Plot these altogether.
pdf("Comparison-Figs/RNAseqVsMicroarray_heatmap.pdf", w = 7, h = 6)
gridExtra::grid.arrange(grobs = list(hm[[4]],pF,pA),
ncol = 7,
nrow = 5,
layout_matrix =
rbind(c(1,1,1,1,1,2,2),
c(1,1,1,1,1,2,2),
c(1,1,1,1,1,3,3),
c(1,1,1,1,1,3,3),
c(1,1,1,1,1,NA,NA)))
dev.off()
```
# 3) Compare expression in bulk RNAseq samples to Treg signature from Ng, et al. 2019.
For this comparison, we need some supplemental data from Ng et. al., "Helios enhances the preferential differentiation of human fetal CD4+ naïve T cells into regulatory T cells", Science, 2019:
- Table S1: https://immunology.sciencemag.org/highwire/filestream/642275/field_highwire_adjunct_files/1/aav5947_Table_S1.xlsx
The table contains two tabs, but we need data from both, so I copied the second tab into the first, remove the extra cell of data holding legend information, then exported as a csv. That csv is what gets loaded in in the first line of code below.
```{r}
Treg_sig <- read.csv("Ng2019_Table_S1_TregSignature_bothTabs.csv",
stringsAsFactors = F, header = T)[,c(1,8)]
# Extract Treg up genes captured in this dataset
Treg_UP <- Treg_sig$Gene_symbol[Treg_sig$Heatmap.Cluster %in% c("Cluster 1","Cluster 2")]
Treg_UP_in <- Treg_UP[isGene(Treg_UP, bulkCD4)]
# Extract Treg down genes captured in this dataset
Treg_DOWN <- Treg_sig$Gene_symbol[Treg_sig$Heatmap.Cluster %in% c("Cluster 3","Cluster 4")]
Treg_DOWN_in <- Treg_DOWN[isGene(Treg_DOWN, bulkCD4)]
#Make age annotation metadata
bulkCD4$Age.names <- paste(gsub("Cord", "UCB",meta("Age", bulkCD4)),1:5, sep = "-")
#Make Treg gene annotations:
genes_annot <- data.frame(TregExpression = c(rep("Up", length(Treg_UP_in)),
rep("Down", length(Treg_DOWN_in))),
row.names = c(Treg_UP_in, Treg_DOWN_in),
stringsAsFactors = FALSE)
# Select specific Treg genes to highlight:
highlights <- c("IL2RA", "FOXP3", "CTLA4", "IKZF2", "IKZF4")
# highlights_in <- isGene(highlights, bulkCD4, TRUE) # ALl are inside
# Collect average z-score expression levels of each gene in all ages, then separate by gene for adding these to the summary plots
all_exp_df <- data.frame(
z.exp =
c(sapply(highlights, function(X) {
mean(gene(X, bulkCD4, adjustment = "z-score")[meta("Age",bulkCD4)=="Fetal"])
}),
sapply(highlights, function(X) {
mean(gene(X, bulkCD4, adjustment = "z-score")[meta("Age",bulkCD4)=="Cord"])
}),
sapply(highlights, function(X) {
mean(gene(X, bulkCD4, adjustment = "z-score")[meta("Age",bulkCD4)=="Adult"])
})),
gene = rep(highlights,3),
grouping = rep(c("F","UCB","A"), each = 5))
cord_exp_df <- all_exp_df[all_exp_df$grouping == "UCB",]
# Make plots
hm <- dittoHeatmap(rownames(genes_annot),
object = bulkCD4,
annot.by = "Age",
cell.names.meta = "Age.names",
main = "Treg Signature Genes",
annotation_row = genes_annot,
cutree_row = 2, treeheight_row = 15,
cutree_col = 3, treeheight_col = 15,
highlight.genes = highlights,
show_rownames = FALSE,
annot.colors = c(dittoColors()[1:3],"blue","red"))
(pUP <- dittoPlotVarsAcrossGroups(
c(Treg_UP_in),
object = bulkCD4,
group.by = "Age",
x.reorder = 3:1, colors = 3:1,
x.labels = c("F", "UCB", "A"),
plots = c("vlnplot","boxplot"),
adjustment = "z-score",
main = NULL, jitter.size = 0.3,
sub = "Treg-upregulated",
boxplot.color = "white",
boxplot.fill = FALSE,
y.breaks = -1:1,
theme = theme_bw(),
x.labels.rotate = FALSE,
ylab = NULL, xlab = NULL,
legend.show = FALSE,
vlnplot.lineweight = 0.5) +
# Add gene annotations
geom_point(
data = cord_exp_df,
aes(x = grouping, y = z.exp),
fill = "black",
shape = 15,
inherit.aes = FALSE) +
ggrepel::geom_text_repel(
data = cord_exp_df,
aes(x = grouping, y = z.exp, label = gene),
fill = "white",
direction = "x",
inherit.aes = FALSE)# +
# geom_path(
# data = all_exp_df,
# aes(x = grouping, y = z.exp, group = gene),
# inherit.aes = FALSE)
)
(pDN <- dittoPlotVarsAcrossGroups(
c(Treg_DOWN_in),
object = bulkCD4,
group.by = "Age",
x.reorder = 3:1, colors = 3:1,
x.labels = c("F", "UCB", "A"),
plots = c("vlnplot","boxplot"),
adjustment = "z-score",
main = NULL, jitter.size = 0.3,
sub = "Treg-downregulated",
boxplot.color = "white",
boxplot.fill = FALSE,
y.breaks = -1:1,
theme = theme_bw(),
x.labels.rotate = FALSE,
ylab = NULL, xlab = NULL,
legend.show = FALSE,
vlnplot.lineweight = 0.5))
pdf("Comparison-Figs/bulkCD4s_TregSignature_heatmap.pdf", w = 8, h = 4.5)
gridExtra::grid.arrange(grobs = list(hm[[4]],pUP,pDN),
ncol = 7,
nrow = 4,
layout_matrix =
rbind(c(1,1,1,1,1,1,2,2),
c(1,1,1,1,1,1,2,2),
c(1,1,1,1,1,1,3,3),
c(1,1,1,1,1,1,3,3)))
dev.off()
```
```{r}
# Statistics
df_TregUP <- dittoPlotVarsAcrossGroups(
c(Treg_UP_in),
object = bulkCD4,
group.by = "Age",
adjustment = "z-score",
data.out = TRUE)[[2]]
df_TregDOWN <- dittoPlotVarsAcrossGroups(
c(Treg_DOWN_in),
object = bulkCD4,
group.by = "Age",
adjustment = "z-score",
data.out = TRUE)[[2]]
# Up
wilcox.test(df_TregUP$var.data[df_TregUP$grouping=="Cord"], df_TregUP$var.data[df_TregUP$grouping=="Adult"])
wilcox.test(df_TregUP$var.data[df_TregUP$grouping=="Cord"], df_TregUP$var.data[df_TregUP$grouping=="Fetal"])
# Down
wilcox.test(df_TregDOWN$var.data[df_TregDOWN$grouping=="Cord"], df_TregDOWN$var.data[df_TregDOWN$grouping=="Adult"])
wilcox.test(df_TregDOWN$var.data[df_TregDOWN$grouping=="Cord"], df_TregDOWN$var.data[df_TregDOWN$grouping=="Fetal"])
```