-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell composition analysis.Rmd
108 lines (86 loc) · 3.13 KB
/
cell composition analysis.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
---
title: "Replicate_Consistency"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Cell composition
```{r}
# load conE and clusters
conE <- readRDS('/d0/home/jennydongwx/DRG_cochlea/res/Apr2021/conE.rds')
# cluster
conE_clusters <- conE$clusters$leiden$groups
```
```{r}
# remove unwanted clusters
conE_plot_clusters <- conE_clusters
levels(conE_plot_clusters) <- c(seq(1,11,1), rep(NA, 6))
conE_plot <- conE
conE_plot$clusters$leiden$groups <- conE_plot_clusters
```
## Fig. S4A
```{r}
tiff(filename = '/d0/home/jennydongwx/DRG_cochlea/res/Apr2021/final_figures/slide27_largerfont.tiff',
width = 250, height = 150, units = 'mm', res = 200)
par(pty="m", mar = rep(20,4))
plotClusterBarplots(conos.obj = conE_plot, show.entropy = FALSE, show.size = FALSE) +
theme( plot.title = element_text(size = 20, hjust = 0.5),
legend.title=element_text(size=18),
legend.text=element_text(size=15),
axis.text = element_text(size=15),
axis.title = element_text(size=18))
dev.off()
```
# Fig.S4B
```{r}
#function to get cluster composition
getClusterComp <- function(conos.obj, clustering = NULL, groups = NULL){
groups <- conos.obj$clusters[[1]]$groups
sample.factor <- conos.obj$getDatasetPerCell()
xt <- table(sample.factor[match(names(groups),names(sample.factor))],groups)
xt <- xt[rowSums(xt)>0, ]
xt <- xt[ ,colSums(xt)>0]
df <- reshape2::melt(xt)
colnames(df) <- c("sample","cluster","f")
#df$f <- df$f/colSums(xt)[as.character(df$cluster)]
return(df)
}
```
```{r}
# get cell composition per sample
conE_plot_distr <- getClusterComp(conE_plot)
```
normalize by cell count
## Fig. S4B
```{r}
comp_plots_list <- lapply(c('E14', 'E18', 'P14'), function(tp) {
sub_df <- conE_plot_distr %>% dplyr::filter(substr(sample,1,3) == tp)
tmp <- sub_df %>% group_by(sample) %>% summarise(norm_frac = f/ sum(f), cluster = cluster)
merged <- base::merge(sub_df, tmp, by = c('sample', 'cluster'))
merged %>% ggplot2::ggplot( ggplot2::aes(x=factor(cluster, levels=levels(conE_plot$clusters[[1]]$groups)),y=.data$norm_frac,fill=.data$sample)) +
ggplot2::geom_bar(stat='identity', position="dodge") + ggplot2::xlab('cluster') + ggplot2::ylab('normalized fraction') +
ggplot2::ggtitle(paste('normalized fraction for', tp)) +
ggplot2::scale_y_continuous(expand=c(0, 0)) +
ggplot2::scale_color_manual(labels = seq(1,3)) +
ggplot2::theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
plot.title = element_text(size = 20, hjust = 0.5),
legend.title=element_text(size=18),
legend.text=element_text(size=15),
axis.text = element_text(size=15),
axis.title = element_text(size=18),
)
})
ggarrange(comp_plots_list[[1]], comp_plots_list[[2]],comp_plots_list[[3]],
#labels = c("A", "B", "C"),
ncol = 2, nrow = 2)
```
```{r}
# plot each
for(i in seq(1,3)){
plt <- comp_plots_list[[i]]
fn <- paste0('slide28_largerfont', i,'.tiff')
ggsave(filename = fn, plot = plt, path = '/d0/home/jennydongwx/DRG_cochlea/res/Apr2021/final_figures', width = 250, height = 150, units = 'mm', device='tiff', dpi=150)
}
```