-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFigure4D_pct_expressed.Rmd
164 lines (120 loc) · 5.58 KB
/
Figure4D_pct_expressed.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
---
title: "Script to calculate heatmap of percent expressed cells."
author: "Neerja Katiyar"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: workflowr::wflow_html
editor_options:
chunk_output_type: console
---
### Prepare the environment
```{r setup, include=FALSE}
require(knitr)
knitr::opts_chunk$set(echo = TRUE)
opts_knit$set(root.dir = "/Users/katiyn/Dropbox (JAX)/MouseAging_clean/Mice_aging_NK_resubmission/code/") #set root dir!
```
```{r libraries, include=TRUE, echo=TRUE}
library(ggpubr)
library(pheatmap)
library(tidyr)
library(Seurat)
library(RColorBrewer)
```
```{r read_tabula_muris_data, include=TRUE, echo=TRUE}
spleen.subset <- readRDS("./data/spleen_seurat_subset_rename_ident_Oct24.rds")
cell.types <- unique(Idents(spleen.subset))
spleen.subset$cluster_name <- Idents(spleen.subset)
cell.types <- unique(Idents(spleen.subset))
```
### Generate heatmap for percent of cells expressing Fosb.
```{r heatmap_Fosb, include=TRUE, echo=TRUE}
df_combined <- data.frame()
for (i in cell.types) {
print(i)
data_celltype <- subset([email protected], cluster_name == i)
spleen.subset_celltype <- subset(spleen.subset, ident = i)
spleen_subset_celltype_young <- subset(spleen.subset_celltype, age == "3m")
spleen_subset_celltype_old <- subset(spleen.subset_celltype, age == "18m")
spleen_subset_celltype_young_gene <- subset(spleen_subset_celltype_young, Fosb > 0)
spleen_subset_celltype_old_gene <- subset(spleen_subset_celltype_old, Fosb > 0)
spleen_subset_celltype_young_gene_pct <- ncol(spleen_subset_celltype_young_gene)/ncol(spleen_subset_celltype_young)
spleen_subset_celltype_old_gene_pct <- ncol(spleen_subset_celltype_old_gene)/ncol(spleen_subset_celltype_old)
age_table <- data.frame(Young = spleen_subset_celltype_young_gene_pct, Aged = spleen_subset_celltype_old_gene_pct)
rownames(age_table) = i
df_combined <- rbind(df_combined, age_table)
}
print(df_combined)
df_mat <- as.matrix(df_combined)
pheatmap.val <- df_mat
breaksList = seq(0, max(pheatmap.val*100), by = .001)
gene = "Fosb"
print(gene)
pdf(paste0("./output/Pheatmap_new_cell_type_vs_age_", gene, ".pdf"), width = 4)
pheatmap::pheatmap(pheatmap.val * 100, cluster_cols = FALSE, cluster_rows = FALSE,
color = colorRampPalette((brewer.pal(n = 9, name = "Blues")))(length(breaksList)),
breaks = breaksList, border_color = "white", main = gene, display_numbers = T,
fontsize_number = 9,
number_color = "white", legend = F)
dev.off()
```
### Generate heatmap for percent of cells expressing Fos.
```{r heatmap_Fos, include=TRUE, echo=TRUE}
df_combined <- data.frame()
for (i in cell.types) {
data_celltype <- subset([email protected], cluster_name == i)
spleen.subset_celltype <- subset(spleen.subset, ident = i)
spleen_subset_celltype_young <- subset(spleen.subset_celltype, age == "3m")
spleen_subset_celltype_old <- subset(spleen.subset_celltype, age == "18m")
spleen_subset_celltype_young_gene <- subset(spleen_subset_celltype_young, Fos > 0)
spleen_subset_celltype_old_gene <- subset(spleen_subset_celltype_old, Fos > 0)
spleen_subset_celltype_young_gene_pct <- ncol(spleen_subset_celltype_young_gene)/ncol(spleen_subset_celltype_young)
spleen_subset_celltype_old_gene_pct <- ncol(spleen_subset_celltype_old_gene)/ncol(spleen_subset_celltype_old)
age_table <- data.frame(Young = spleen_subset_celltype_young_gene_pct, Aged = spleen_subset_celltype_old_gene_pct)
rownames(age_table) = i
print(age_table)
df_combined <- rbind(df_combined, age_table)
}
print(df_combined)
df_mat <- as.matrix(df_combined)
pheatmap.val <- df_mat
breaksList = seq(0, max(pheatmap.val*100), by = .001)
gene = "Fos"
print(gene)
pdf(paste0("./output/Pheatmap_new_cell_type_vs_age_", gene, ".pdf"), width = 4)
pheatmap::pheatmap(pheatmap.val * 100, cluster_cols = FALSE, cluster_rows = FALSE,
color = colorRampPalette((brewer.pal(n = 9, name = "Blues")))(length(breaksList)),
breaks = breaksList, border_color = "white", main = gene, display_numbers = T,
fontsize_number = 9,
number_color = "white", legend = F)
dev.off()
```
### Generate heatmap for percent of cells expressing Jun.
```{r heatmap_Jun, include=TRUE, echo=TRUE}
df_combined <- data.frame()
for (i in cell.types) {
data_celltype <- subset([email protected], cluster_name == i)
spleen.subset_celltype <- subset(spleen.subset, ident = i)
spleen_subset_celltype_young <- subset(spleen.subset_celltype, age == "3m")
spleen_subset_celltype_old <- subset(spleen.subset_celltype, age == "18m")
spleen_subset_celltype_young_gene <- subset(spleen_subset_celltype_young, Jun > 0)
spleen_subset_celltype_old_gene <- subset(spleen_subset_celltype_old, Jun > 0)
spleen_subset_celltype_young_gene_pct <- ncol(spleen_subset_celltype_young_gene)/ncol(spleen_subset_celltype_young)
spleen_subset_celltype_old_gene_pct <- ncol(spleen_subset_celltype_old_gene)/ncol(spleen_subset_celltype_old)
age_table <- data.frame(Young = spleen_subset_celltype_young_gene_pct, Aged = spleen_subset_celltype_old_gene_pct)
rownames(age_table) = i
print(age_table)
df_combined <- rbind(df_combined, age_table)
}
print(df_combined)
df_mat <- as.matrix(df_combined)
pheatmap.val <- df_mat
breaksList = seq(0, max(pheatmap.val*100), by = .001)
gene = "Jun"
print(gene)
pdf(paste0("./output/Pheatmap_new_cell_type_vs_age_", gene, ".pdf"), width = 4)
pheatmap::pheatmap(pheatmap.val * 100, cluster_cols = FALSE, cluster_rows = FALSE,
color = colorRampPalette((brewer.pal(n = 9, name = "Blues")))(length(breaksList)),
breaks = breaksList, border_color = "white", main = gene, display_numbers = T,
fontsize_number = 9,
number_color = "white", legend = F)
dev.off()
```