-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure_generation_v2.Rmd
399 lines (295 loc) · 14.6 KB
/
figure_generation_v2.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
---
title: "Figure Generation v2"
author: "D. Ford Hannum"
date: "6/22/2020"
output:
html_document:
toc: true
toc_depth: 3
number_sections: false
theme: united
highlight: tango
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
library(Seurat)
library(ggplot2)
library(data.table)
```
# Introduction
The plan in this analysis is to generate images for figures 3 and 4 of the manuscript, with some preliminary images for a potential figure 5.
**Figure 3** will contain the general introduction to the scRNA-seq data, and we imagine it containing three images:
* UMAP projection: split into four panes for the four different conditions.
* Bar graph showing the distribution of cells within the whole bone marrow conditions
* Violin plots of cell labeling marker genes
**Figure 4**: will focus on the megakaryocytes (MKs)
* UMAP projection of combined sub-clustering of the MKs (maybe will also look at adding MEPs and Ery)
* Differential between control and Mpl MKs; could use violin plots or heatmap (which could be combined with pathway analysis)
* Potentially a trajectory analysis (so far no luck getting that to look right)
**Figure 5**: disease focus dive into the sc data. Looking at profibrotic factors, proliferation genes, Jak pathway, receptor lycan interaction, etc
```{r loading data}
wbm <- readRDS('./data/wbm_clustered_filtered_named.rds')
#DimPlot(wbm, reduction = 'umap', label = T, repel = T) + NoLegend()
```
```{r changing the levels of the data}
new_levels <- c('Granulocyte','Granulocyte','Granulocyte', 'B-cell','MK',
'Granulocyte', 'Granulocyte','Monocyte','Macrophage','Erythroid','B-cell',
'T-cell/NK', 'MEP')
names(new_levels) <- levels(wbm)
#new_levels
wbm <- RenameIdents(wbm, new_levels)
```
\newpage
# Figure 3
## a) UMAP projection of entire data
UMAP projection split into four panes for the four different conditions.
```{r figure 3a}
#head([email protected])
[email protected]$state <- factor([email protected]$state, levels = levels(as.factor([email protected]$state))[c(3,4,1,2)])
DimPlot(wbm, reduction = 'umap', split.by = 'state', ncol = 2) +
theme_bw() +
theme(axis.text = element_blank(), strip.text = element_blank())
```
It seems that adding an outer label will be easiest to do in Adobe Illustrator where I will combine all the figures. The left side is controls and right side Mpl; with whole bone marrow (wbm) on top and enriched wbm on the bottom
## b) Bar graph of distribution of cells
Focusing just on the wbm and comparing the origins of the distribution of cells.
```{r figure 3b, formatting data}
#head([email protected])
wbm$new_cluster_IDs <- [email protected]$cluster_IDs
levels([email protected]$new_cluster_IDs) <- new_levels
wbm_wbm <- [email protected][[email protected]$celltype == 'WBM',]
tbl <- as.data.frame(table(wbm_wbm$new_cluster_IDs, wbm_wbm$condition))
colnames(tbl) <- c('Cell Type','Condition','Freq')
#tbl
tbl$cond_count <- ifelse(tbl$Condition == 'control', sum(tbl[tbl$Condition == 'control',]$Freq),
sum(tbl[tbl$Condition == 'mut',]$Freq))
normalization_factor <- 2014/2328
tbl$Norm_count <- ifelse(tbl$Condition == 'control', tbl$Freq, round(tbl$Freq * normalization_factor,0))
cell_type_counts <- c()
cnt <- 1
for (i in levels(tbl$`Cell Type`)){
#print(i)
cell_type_counts[cnt] <- sum(tbl[tbl$`Cell Type` == i,]$Norm_count)
cnt <- cnt + 1
}
tbl$cell_type_counts <- rep(cell_type_counts,2)
tbl$percentage <- round(tbl$Norm_count / tbl$cell_type_counts,2)*100
tbl$Condition <- ifelse(tbl$Condition == 'control', 'Control', 'Mpl')
```
```{r figure 3b}
ggplot(data = tbl, aes(x = `Cell Type`, y = percentage, fill = Condition)) +
scale_fill_manual(values = c('blue','red')) +
geom_bar(stat = 'identity') +
theme_bw() +
ylab('Percentage of Cells') + xlab('Cell Type') +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
## c) Violin Plots for Marker Genes
```{r testing for marker genes, include = F}
# VlnPlot(wbm, c('Itga2b','Ank1','Ighd','Gata3','Ccr5','Pf4'), pt.size = 0)
# VlnPlot(wbm, c('Gp9','Elane','Mpo','Ctsg','Selp'), pt.size = 0)
# VlnPlot(wbm, c('Lbh','Nr4a1','Gpr141','Gata1'), pt.size = 0)
# VlnPlot(wbm, c('Cd14','Ptprc','Adgre1','Lyz2'), pt.size = 0)
```
Potential Key Marker Genes:
* MK,MEP: Itga2b
* Ery: Ank1
* B-cell: Ighd
* T-cell: Gata3
* Macrophage: Ccr5 (also T-cell)
```{r Figure 3c}
VlnPlot(wbm, c('Itga2b','Gp9','Ank1','Ighd','Gata3','Ccr5'), ncol = 3, pt.size = 0)
```
Need to clean up this image for the figure. Still thinking of ways to condense all the labels down to fewer.
# Figure 4
## 4a UMAP subclustering of MKs
Including both MKs and MEPs.
```{r re-analyzing just MKs and MEPs}
[email protected]$condition <- ifelse([email protected]$condition == 'control', 'Control', "Mpl")
mks <- subset(wbm, new_cluster_IDs %in% c('MK','MEP'))
#summary(as.factor(mks$state))
# Running all the same steps before to normalize, cluster, and dimension reduction
mks <- NormalizeData(mks, normalization.method = "LogNormalize", scale.factor = 10000)
all.genes <- rownames(mks)
mks <- ScaleData(mks, features = all.genes)
mks <- RunPCA(mks, features = VariableFeatures(mks), verbose = F)
# ElbowPlot(mks) # decided to go with the first 8 PCs
mks <- FindNeighbors(mks, dims = 1:8)
mks <- FindClusters(mks , resolution = .45, verbose = F)
mks <- RunUMAP(mks, dims = 1:8, verbose = F)
DimPlot(mks, reduction = 'umap', split.by = 'condition') +
theme(axis.text = element_blank())
DimPlot(mks, reduction = 'umap', split.by = 'new_cluster_IDs') +
theme(axis.text = element_blank())
```
## 4a supplement bar chart
Similar to figure 3b. Not necessarily needed but useful for me doing the analysis.
```{r 4a sup. table}
mk.tbl <- as.data.frame(table(mks$seurat_clusters, mks$condition))
colnames(mk.tbl) <- c('Cluster','Condition', 'Freq')
# normalization_factor <- sum(mk.tbl[mk.tbl$Condition == 'control',]$Freq)/
# sum(mk.tbl[mk.tbl$Condition == 'mut',]$Freq)
# The normalization factor should be calculated by the total cell depth
#summary(as.factor(wbm$condition))
normalization_factor <- 2620/3501
mk.tbl$Norm_freq <- ifelse(mk.tbl$Condition == 'Control', mk.tbl$Freq,
round(mk.tbl$Freq * normalization_factor,0))
cluster_counts <- c()
cnt <- 1
for (i in levels(mk.tbl$Cluster)){
cluster_counts[cnt] <- sum(mk.tbl[mk.tbl$Cluster == i,]$Norm_freq)
cnt <- cnt + 1
}
mk.tbl$cluster_counts <- rep(cluster_counts,2)
mk.tbl$Percentage <- round(mk.tbl$Norm_freq / mk.tbl$cluster_counts,2)*100
#mk.tbl$Condition <- ifelse(mk.tbl$Condition == 'control', 'Control', 'Mpl')
ggplot(data = mk.tbl, aes(x = Cluster, y = Percentage, fill = Condition)) +
scale_fill_manual(values = c('blue','red')) +
geom_bar(stat = 'identity') +
theme_bw() +
ylab('Percentage of Cells') + xlab('Cell Type') +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
**I think this could change how we do differenital expression for 4b. For now I kept 4b the same as we've done before, but I think some of the genes that are upregulated in the control are false, because they are just genes that are unique to clusters 2-4. Due to this, most MK Mpl cells would not express these genes. The focus may be to describe genes that distinguish 0, 1 and 5 which are unique to Mpl. Also Cluster 2 is the majority of the MEP cells, and we see the most balance between conditions there (also there are no DE genes in the MEP cluster)**
## 4b Differential Expression Heatmap
```{r MK & MEP differential expression}
mk.markers <- FindMarkers(wbm, ident.1 = 'Control', ident.2 = 'Mpl',
group.by = 'condition',
verbose = T, subset.ident = 'MK',
logfc.threshold = log(2), test.use = 'MAST')
# mep.markers <- FindMarkers(wbm, ident.1 = 'Control', ident.2 = 'Mpl',
# group.by = 'condition',
# verbose = T, subset.ident = 'MEP',
# logfc.threshold = log(2), test.use = 'MAST')
sig.mk.markers <- mk.markers[mk.markers$p_val_adj < 0.05,]
#sig.mep.markers <- mep.markers[mep.markers$p_val_adj < 0.05,]
# No DE MEP genes
sig.mk.markers <- sig.mk.markers[order(sig.mk.markers$avg_logFC, decreasing = T),]
sig.mk.genes <- rownames(sig.mk.markers)
# write.table(rownames(sig.mk.markers[sig.mk.markers$avg_logFC>0,]), './data/DE.genes.MK.higherINcontrols.tsv',
# quote = F, row.names = F, sep = '\t')
# write.table(rownames(sig.mk.markers[sig.mk.markers$avg_logFC<0,]), './data/DE.genes.MK.higherINmpl.tsv',
# quote = F, row.names = F, sep = '\t')
#write.table(sig.mk.genes, './data/DEgenes.MK.all.tsv',quote = F, row.names = F, sep = '\t')
# write.table(rownames(wbm), './data/all.genes.tsv', quote = F, row.names = F, sep = '\t')
```
```{r 4b de heatmap}
mk.cells <- WhichCells(wbm, ident = 'MK')
DoHeatmap(wbm, features = sig.mk.genes, group.by = 'condition',
cells = mk.cells, label = F) +
theme_minimal() +
xlab('MK Cells') + ylab('DE genes') +
scale_x_discrete(position = 'top') +
theme(text = element_text(size = 10, family = 'sans'),
axis.text = element_blank(),
axis.ticks = element_blank())
```
```{r mk_vln plots}
VlnPlot(mks, c('Mki67'), pt.size = 0, split.by = 'condition')
VlnPlot(wbm, 'Mki67', pt.size = 0, split.by = 'condition')
```
Above is an example of a gene that was differentially expressed between control and Mpl within the MK cluster, but when doing the subclustering we see that this is due to differences in populations (see below figure). This is why the first differential expression heatmap may not be the most valid way to interpret the data.
```{r another bar chart}
mk.tbl2 <- mk.tbl[,1:4]
mk.tbl2$condition_counts <- rep(c(sum(mk.tbl2[mk.tbl2$Condition == 'Control','Norm_freq']),
sum(mk.tbl2[mk.tbl2$Condition == 'Mpl', 'Norm_freq'])),
each = 6)
mk.tbl2$Percentage <- round(mk.tbl2$Norm_freq / mk.tbl2$condition_counts,2)*100
#mk.tbl2
mk.tbl2
ggplot(data = mk.tbl2, aes(x = Condition, y = Percentage, fill = Cluster)) +
geom_bar(stat = 'identity') +
theme_bw() +
ylab('Percentage of Cells') + xlab('Cell Type') +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
coord_flip()
```
## 4b Alternative
### DE Markers Genes for Clusters 0, 1, and 5
Going to look at markers that distinguish the MK subclusters 0, 1, and 5 from all other MK subclusters using MAST, a log(2) fold-change threshold, and only return true values (i.e. have a higher expression in given subcluster vs all)
```{r looking at mk subcluster specific markers}
submk.markers.0 <- FindMarkers(mks,
ident.1 = 0,
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
submk.markers.1 <- FindMarkers(mks,
ident.1 = 1,
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
submk.markers.5 <- FindMarkers(mks,
ident.1 = 5,
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
print("Subcluster 0 vs All")
submk.markers.0
#write.csv(submk.markers.0, './data/submk.markers.0.vs.all.csv', quote = F)
print("Subcluster 1 vs All")
submk.markers.1
#write.csv(submk.markers.1, './data/submk.markers.1.vs.all.csv', quote = F)
print("Subcluster 5 vs All")
submk.markers.5
#write.csv(submk.markers.5, './data/submk.markers.5.vs.all.csv', quote = F)
```
Running the same analysis but only comparing the given subcluster to subclusters 3 and 4, which are the normals MKs which are present in both control and Mpl.
```{r de marker genes version 2}
submk.markers.0.v2 <- FindMarkers(mks,
ident.1 = 0, ident.2 = c(3,4),
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
submk.markers.1.v2 <- FindMarkers(mks,
ident.1 = 1, ident.2 = c(3,4),
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
submk.markers.5.v2 <- FindMarkers(mks,
ident.1 = 5, ident.2 = c(3,4),
logfc.threshold = log(2),
only.pos = T,
test.use = "MAST")
print("Subcluster 0 vs 3 & 4")
submk.markers.0.v2
print("Subcluster 1 vs 3 & 4")
submk.markers.1.v2
print("Subcluster 5 vs 3 & 4")
submk.markers.5.v2
```
### DE marker genes within mixed clusters (2, 3, and 4)
Checking to see if there any DE genes between Control and Mpl within the clusters that have both conditions. My hypothesis is that we would see very few to no genes being differentially expressed.
```{r DEG in mixed clusters}
mk.markers.2 <- FindMarkers(mks, ident.1 = 'Control', ident.2 = 'Mpl',
group.by = 'condition',
verbose = T, subset.ident = 2,
logfc.threshold = log(2), test.use = 'MAST')
mk.markers.3 <- FindMarkers(mks, ident.1 = 'Control', ident.2 = 'Mpl',
group.by = 'condition',
verbose = T, subset.ident = 3,
logfc.threshold = log(2), test.use = 'MAST')
mk.markers.4 <- FindMarkers(mks, ident.1 = 'Control', ident.2 = 'Mpl',
group.by = 'condition',
verbose = T, subset.ident = 4,
logfc.threshold = log(2), test.use = 'MAST')
# summary(mk.markers.2$p_val_adj < 0.05)
# summary(mk.markers.3$p_val_adj < 0.05)
# summary(mk.markers.4$p_val_adj < 0.05)
mk.markers.3.sig <- mk.markers.3[mk.markers.3$p_val_adj < 0.05,]
mk.markers.4.sig <- mk.markers.4[mk.markers.4$p_val_adj < 0.05,]
```
**Values**
* pct.1: percentage of cells in control that express the gene
* pct.2: percentage of cells in Mpl that exress the gene
* avg_logFC: negative values indicate higher expression in group 2 (Mpl)
**Filters**
* minimum of a log2 fold-change (+- 0.69 in natural log)
* adjusted p-value less than 0.05
There were 6 DEGs within cluster 3:
```{r clst3 DEGs}
mk.markers.3.sig
```
There were 9 DEGEs within cluster 4:
```{r clst4 DEGs}
mk.markers.4.sig
```